diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 0843027..af4c6a9 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -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 * Adding custom message argument to unauthorized! method (thanks tjwallace) - see issue #18 diff --git a/lib/cancan/ability.rb b/lib/cancan/ability.rb index 1fab685..702075e 100644 --- a/lib/cancan/ability.rb +++ b/lib/cancan/ability.rb @@ -160,12 +160,18 @@ module CanCan aliased_actions[target] += args 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 @aliased_actions ||= default_alias_actions end + # Removes previously aliased actions including the defaults. + def clear_aliased_actions + @aliased_actions = {} + end + + private + def default_alias_actions { :read => [:index, :show], diff --git a/spec/cancan/ability_spec.rb b/spec/cancan/ability_spec.rb index e6178a1..20bc1a9 100644 --- a/spec/cancan/ability_spec.rb +++ b/spec/cancan/ability_spec.rb @@ -49,9 +49,7 @@ describe CanCan::Ability do it "should alias update or destroy actions to modify action" do @ability.alias_action :update, :destroy, :to => :modify - @ability.can :modify, :all do |object_class, object| - :modify_called - end + @ability.can(:modify, :all) { :modify_called } @ability.can?(:update, 123).should == :modify_called @ability.can?(:destroy, 123).should == :modify_called end @@ -126,10 +124,12 @@ describe CanCan::Ability do it "should append aliased actions" do @ability.alias_action :update, :to => :modify @ability.alias_action :destroy, :to => :modify - @ability.can :modify, :all do |object_class, object| - :modify_called - end - @ability.can?(:update, 123).should == :modify_called - @ability.can?(:destroy, 123).should == :modify_called + @ability.aliased_actions[:modify].should == [:update, :destroy] + end + + 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