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?
You can check an ability using an instance of a class rather than the class itself: