i'm attempting write controller specs sub controller, in case admin::userscontroller
it has basic set of crud actions.
my users_controller_spec.rb
describe admin::carrierscontroller before(:each) sign_in factorygirl.create(:admin) end "should have current_user" subject.current_user.should_not be_nil end describe "get 'index'" "assigns users @users" user = create(:user) :index assigns(:users).should eq [user] end "renders index view" :index expect(response).to render_template :index end end end
now problem i'm running against index action. controller work , simple @users = user.all
whats complicating things user table sti so
class user < activerecord::base end class client < user end class seller < user end
my factories
factorygirl.define factory :user name { faker::company.name } sequence(:email) {|n| "test#{n}@test.com"} password "password" password_confirmation {|instance| instance.password } type "seller" factory :admin type "admin" end factory :seller type "seller" end factory :client type "client" end end end
obviously eq method not working becuase rspec has problems matching class names in assigns(:users) expectation. exact error is:
1) admin::userscontroller 'index' assigns users @users failure/error: assigns(:users).should eq user expected #<activerecord::relation [#<client id: 1282, name: "marks-kozey", type: "client"...]> eq #<user id: 1282, name: "marks-kozey", type: "client"...
is problem factories? or testing incorrectly. first time testing sti appreciative.
try passing class symbol child factory, e.g.:
factory :client, class:client type "client" end
the factory-generated object should of type client
instead of user
.
Comments
Post a Comment