Skip to content
Snippets Groups Projects
Commit 7d3b4cdb authored by Ryan Bates's avatar Ryan Bates
Browse files

Adding clear_aliased_actions to Ability which removes previously defined actions including defaults

parent f99d5060
No related branches found
No related tags found
No related merge requests found
* 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
......
...@@ -160,12 +160,18 @@ module CanCan ...@@ -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],
......
...@@ -49,9 +49,7 @@ describe CanCan::Ability do ...@@ -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 ...@@ -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 it "should clear aliased actions" do
@ability.can?(:destroy, 123).should == :modify_called @ability.alias_action :update, :to => :modify
@ability.clear_aliased_actions
@ability.aliased_actions[:modify].should be_nil
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment