我试图实现Rolify宝石却不能增加夹具与它的范围。 的(模型)测试的最后一行,因为目前国内主持人的作用似乎给下面未能@user
为组织一个全球性的,而不是只。 下面的灯具不使用resource_id
和resource_type
,这是中提到的创业板文档的灯具,但我不知道如何使用它们。 我应该如何设置主持人角色只有组织中的一个范围?
roles.yml
moderator:
id: 1
resource: one (Organization)
users.yml里
one:
email: example@example.com
roles: moderator, organizations(:one) # I was hoping this would set the scope of the role to organization one but it isn't (seems to set the role globally).
test.rb
def setup
@moderator_role = roles(:moderator)
@organization1 = organizations(:one)
@organization2 = organizations(:two)
@user = users(:one)
end
test "should be moderator if fixtures correct" do
assert_equal @user.has_role?('moderator'), true
assert_equal @user.has_role?(:moderator, @organization1), true
assert_equal @user.has_role?(:moderator, @organization2), false # This line fails
end
更新:我也尝试下面的代码。 不过还是测试失败。
roles.yml
moderator:
name: :moderator
resource: one (Organization)
users.yml里
one:
organization: one
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 be moderator if fixtures correct" do
assert_equal @user.has_role?('moderator'), true # This line fails
assert_equal @user.has_role?(:moderator, @organization1), true # This line also fails
assert_equal @user.has_role?(:moderator, @organization2), false
end