ruby on rails - Fixtures with polymorphic association not working -
i'm trying implement rolify gem have trouble adding fixtures scope it. last line of (model) test below fails because moderator role seems given @user
globally instead of organization one. fixtures below aren't using resource_id
, resource_type
, mentioned in gem documentation fixtures, i'm not sure how use them. how should set scope moderator role organization one?
roles.yml
moderator: id: 1 resource: 1 (organization)
users.yml
one: email: example@example.com roles: moderator, organizations(:one) # hoping set scope of role organization 1 isn't (seems set role globally).
test.rb
def setup @moderator_role = roles(:moderator) @organization1 = organizations(:one) @organization2 = organizations(:two) @user = users(:one) end test "should moderator if fixtures correct" assert_equal @user.has_role?('moderator'), true assert_equal @user.has_role?(:moderator, @organization1), true assert_equal @user.has_role?(:moderator, @organization2), false # line fails end
update: tried code below. still test fails.
roles.yml
moderator: name: :moderator resource: 1 (organization)
users.yml
one: organization: 1 roles: moderator, organizations(:one)
organizations.yml
one: name: "company a"
test.rb
def setup @moderator_role = roles(:moderator) @organization1 = organizations(:one) @organization2 = organizations(:two) @user = users(:one) end test "should moderator if fixtures correct" assert_equal @user.has_role?('moderator'), true # line fails assert_equal @user.has_role?(:moderator, @organization1), true # line fails assert_equal @user.has_role?(:moderator, @organization2), false end
i found out code in update, test pass if run users controller test or integration test, instead of model test. guess running wrong type of test.
Comments
Post a Comment