如何测试带有参数的创建动作的康康舞能力?
我的能力是这样的:
def initialize(user)
partner_id ||= user.partner.id
can :create, Employee, :partner_id => partner_id
这是在之前的块中:
before(:each) do
@employee = Factory :employee, role: "manager"
@partner = @employee.partner
@some_other_partner = Factory :partner
@subject = EmployeeAbility.new( @employee )
end
我的积极规范是这样的(这个通过了):
it { @subject.should be_able_to(:create, Employee, partner_id: @partner.id ) }
我的消极规范是这样的(这个失败了):
it { @subject.should_not be_able_to(:create, Employee, partner_id: @some_other_partner.id ) }
我应该如何以我可以测试的方式声明该能力创建的员工属于特定合作伙伴而不属于其他合作伙伴?
My ability is this one:
def initialize(user)
partner_id ||= user.partner.id
can :create, Employee, :partner_id => partner_id
This is in the before block:
before(:each) do
@employee = Factory :employee, role: "manager"
@partner = @employee.partner
@some_other_partner = Factory :partner
@subject = EmployeeAbility.new( @employee )
end
My positive spec is this (This one passes):
it { @subject.should be_able_to(:create, Employee, partner_id: @partner.id ) }
My negative spec would be this (This one fails):
it { @subject.should_not be_able_to(:create, Employee, partner_id: @some_other_partner.id ) }
How should I declare the ability in such a way that I can test that the created employee belongs to a particular partner and not to some other partner?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用类的实例而不是类本身来检查能力:
You can check an ability using an instance of a class rather than the class itself: