Permalink
Browse files

Adding clear_aliased_actions to Ability which removes previously defi…

…ned actions including defaults
  • Loading branch information...
1 parent f99d506 commit 7d3b4cdbc2bf978118a31fc203b2f502cd453781 @ryanb committed Dec 31, 2009
Showing with 18 additions and 10 deletions.
  1. +2 −0 CHANGELOG.rdoc
  2. +8 −2 lib/cancan/ability.rb
  3. +8 −8 spec/cancan/ability_spec.rb
View
@@ -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
View
@@ -160,12 +160,18 @@ def alias_action(*args)
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],
@@ -49,9 +49,7 @@
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 @@
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

0 comments on commit 7d3b4cd

Please sign in to comment.