Adding clear_aliased_actions to Ability which removes previously defined actions including defaults

This commit is contained in:
Ryan Bates 2009-12-30 18:01:40 -08:00
parent f99d506050
commit 7d3b4cdbc2
3 changed files with 18 additions and 10 deletions

View File

@ -1,3 +1,5 @@
* Adding clear_aliased_actions to Ability which removes previously defined actions including defaults - see issue #20
* Append aliased actions (don't overwrite them) - see issue #20 * Append aliased actions (don't overwrite them) - see issue #20
* Adding custom message argument to unauthorized! method (thanks tjwallace) - see issue #18 * Adding custom message argument to unauthorized! method (thanks tjwallace) - see issue #18

View File

@ -160,12 +160,18 @@ module CanCan
aliased_actions[target] += args aliased_actions[target] += args
end end
private # Returns a hash of aliased actions. The key is the target and the value is an array of actions aliasing the key.
def aliased_actions def aliased_actions
@aliased_actions ||= default_alias_actions @aliased_actions ||= default_alias_actions
end end
# Removes previously aliased actions including the defaults.
def clear_aliased_actions
@aliased_actions = {}
end
private
def default_alias_actions def default_alias_actions
{ {
:read => [:index, :show], :read => [:index, :show],

View File

@ -49,9 +49,7 @@ describe CanCan::Ability do
it "should alias update or destroy actions to modify action" do it "should alias update or destroy actions to modify action" do
@ability.alias_action :update, :destroy, :to => :modify @ability.alias_action :update, :destroy, :to => :modify
@ability.can :modify, :all do |object_class, object| @ability.can(:modify, :all) { :modify_called }
:modify_called
end
@ability.can?(:update, 123).should == :modify_called @ability.can?(:update, 123).should == :modify_called
@ability.can?(:destroy, 123).should == :modify_called @ability.can?(:destroy, 123).should == :modify_called
end end
@ -126,10 +124,12 @@ describe CanCan::Ability do
it "should append aliased actions" do it "should append aliased actions" do
@ability.alias_action :update, :to => :modify @ability.alias_action :update, :to => :modify
@ability.alias_action :destroy, :to => :modify @ability.alias_action :destroy, :to => :modify
@ability.can :modify, :all do |object_class, object| @ability.aliased_actions[:modify].should == [:update, :destroy]
:modify_called
end end
@ability.can?(:update, 123).should == :modify_called
@ability.can?(:destroy, 123).should == :modify_called it "should clear aliased actions" do
@ability.alias_action :update, :to => :modify
@ability.clear_aliased_actions
@ability.aliased_actions[:modify].should be_nil
end end
end end