moving can definition into ability instance instead of class, this removes ugly instance_exec command
This commit is contained in:
@@ -8,7 +8,7 @@ describe CanCan::Ability do
|
||||
end
|
||||
|
||||
it "should be able to :read anything" do
|
||||
@ability_class.can :read, :all
|
||||
@ability.can :read, :all
|
||||
@ability.can?(:read, String).should be_true
|
||||
@ability.can?(:read, 123).should be_true
|
||||
end
|
||||
@@ -18,8 +18,8 @@ describe CanCan::Ability do
|
||||
end
|
||||
|
||||
it "should return what block returns on a can call" do
|
||||
@ability_class.can :read, :all
|
||||
@ability_class.can :read, Symbol do |sym|
|
||||
@ability.can :read, :all
|
||||
@ability.can :read, Symbol do |sym|
|
||||
sym
|
||||
end
|
||||
@ability.can?(:read, Symbol).should be_nil
|
||||
@@ -27,21 +27,21 @@ describe CanCan::Ability do
|
||||
end
|
||||
|
||||
it "should pass class with object if :all objects are accepted" do
|
||||
@ability_class.can :preview, :all do |object_class, object|
|
||||
@ability.can :preview, :all do |object_class, object|
|
||||
[object_class, object]
|
||||
end
|
||||
@ability.can?(:preview, 123).should == [Fixnum, 123]
|
||||
end
|
||||
|
||||
it "should pass class with no object if :all objects are accepted and class is passed directly" do
|
||||
@ability_class.can :preview, :all do |object_class, object|
|
||||
@ability.can :preview, :all do |object_class, object|
|
||||
[object_class, object]
|
||||
end
|
||||
@ability.can?(:preview, Hash).should == [Hash, nil]
|
||||
end
|
||||
|
||||
it "should pass action and object for global manage actions" do
|
||||
@ability_class.can :manage, Array do |action, object|
|
||||
@ability.can :manage, Array do |action, object|
|
||||
[action, object]
|
||||
end
|
||||
@ability.can?(:stuff, [1, 2]).should == [:stuff, [1, 2]]
|
||||
@@ -49,8 +49,8 @@ describe CanCan::Ability do
|
||||
end
|
||||
|
||||
it "should alias update or destroy actions to modify action" do
|
||||
@ability_class.alias_action :update, :destroy, :to => :modify
|
||||
@ability_class.can :modify, :all do |object_class, object|
|
||||
@ability.alias_action :update, :destroy, :to => :modify
|
||||
@ability.can :modify, :all do |object_class, object|
|
||||
:modify_called
|
||||
end
|
||||
@ability.can?(:update, 123).should == :modify_called
|
||||
@@ -58,7 +58,7 @@ describe CanCan::Ability do
|
||||
end
|
||||
|
||||
it "should return block result for action, object_class, and object for any action" do
|
||||
@ability_class.can :manage, :all do |action, object_class, object|
|
||||
@ability.can :manage, :all do |action, object_class, object|
|
||||
[action, object_class, object]
|
||||
end
|
||||
@ability.can?(:foo, 123).should == [:foo, Fixnum, 123]
|
||||
@@ -66,22 +66,19 @@ describe CanCan::Ability do
|
||||
end
|
||||
|
||||
it "should automatically alias index and show into read calls" do
|
||||
@ability_class.can :read, :all
|
||||
@ability.can :read, :all
|
||||
@ability.can?(:index, 123).should be_true
|
||||
@ability.can?(:show, 123).should be_true
|
||||
end
|
||||
|
||||
it "should automatically alias new and edit into create and update respectively" do
|
||||
@ability_class.can(:create, :all) { :create_called }
|
||||
@ability_class.can(:update, :all) { :update_called }
|
||||
@ability.can(:create, :all) { :create_called }
|
||||
@ability.can(:update, :all) { :update_called }
|
||||
@ability.can?(:new, 123).should == :create_called
|
||||
@ability.can?(:edit, 123).should == :update_called
|
||||
end
|
||||
|
||||
it "should be able to access given user" do
|
||||
@ability_class.can(:preview, :all) { user }
|
||||
ability = @ability_class.for_user(:some_user)
|
||||
ability.user.should == :some_user
|
||||
ability.can?(:preview, 123).should == :some_user
|
||||
it "should respond to prepare" do
|
||||
@ability.should respond_to(:prepare)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,7 +21,6 @@ describe CanCan::ControllerAdditions do
|
||||
it "should have a current_ability method which generates an ability for the current user" do
|
||||
stub(@controller).current_user { :current_user }
|
||||
@controller.current_ability.should be_kind_of(Ability)
|
||||
@controller.current_ability.user.should == :current_user
|
||||
end
|
||||
|
||||
it "should provide a can? method which goes through the current ability" do
|
||||
|
||||
Reference in New Issue
Block a user