adding manage action which applies to everything

This commit is contained in:
Ryan Bates
2009-11-16 14:42:41 -08:00
parent 0cfb8c7c41
commit 6c89c32059
2 changed files with 30 additions and 13 deletions

View File

@@ -9,9 +9,19 @@ class Ability
can :preview, :all do |object_class, object|
[object_class, object]
end
can :manage, Array do |action, object|
[action, object]
end
end
describe CanCan::Ability do
class AdminAbility
include CanCan::Ability
can :manage, :all do |action, object_class, object|
[action, object_class, object]
end
end
describe Ability do
before(:each) do
@ability = Ability.new
end
@@ -37,4 +47,17 @@ describe CanCan::Ability do
it "should pass class with no object if :all objects are accepted and class is passed directly" do
@ability.can?(:preview, Hash).should == [Hash, nil]
end
it "should pass action and object for global manage actions" do
@ability.can?(:stuff, [1, 2]).should == [:stuff, [1, 2]]
@ability.can?(:stuff, Array).should == [:stuff, nil]
end
end
describe AdminAbility do
it "should return block result for action, object_class, and object for any action" do
@ability = AdminAbility.new
@ability.can?(:foo, 123).should == [:foo, Fixnum, 123]
@ability.can?(:bar, Fixnum).should == [:bar, Fixnum, nil]
end
end