ruby on rails - Using role_model and Factory_Girl (for spec testing), how do I properly setup a user as an admin? -


i'm running feature specs on rails , reason can't admin setup using role_model.

here's code:

app/models/user.rb

   class user < activerecord::base       include rolemodel        attr_accessible :email, :username, :roles, :password, :password_confirmation        has_secure_password       validates :email, :username, :password, :password_confirmation, presence: true       validates :email, :username, uniqueness: true        roles :admin, :moderator, :developer     end 

app/controllers/sessions_controller.rb

class sessionscontroller < applicationcontroller ...     def create         user = user.find_by_email(params[:email])         if user && user.authenticate(params[:password])             session[:user_id] = user.id             if user.is? :admin                 redirect_to admin_url, notice: "admin logged in!"             else                  redirect_to user_url(user), notice: "logged in!"             end         else             flash.now.alert = "email or password invalid!"             render "new"         end     end  ... end 

app/spec/factories/users.rb

require 'faker' require 'role_model'  factorygirl.define      factory :user         username { faker::internet.user_name }         email { faker::internet.email }         password "password"         password_confirmation "password"          factory :invalid_user             username nil         end          factory :admin             roles = [:admin]         end     end end 

app/spec/features/admin_spec.rb

require "spec_helper"  feature "admin dashboard"     scenario "accesses dashboard"         admin = create(:admin)          visit root_path         fill_in "email", with: admin.email         fill_in "password", with: admin.password         click_button "login"          current_path.should eq admin_path         within 'h1'             page.should have_content "hello, world!"         end          page.should have_content @app_name         page.should have_content "games"     end end 

for reason test keeps failing @ "current_path.should eq admin_path" admin user should logged in. can tell me what's going on setup?

turns out had remove "=" in admin factory.


Comments