Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adding clear_aliased_actions to Ability which removes previously defi…

…ned actions including defaults
  • Loading branch information...
commit 7d3b4cdbc2bf978118a31fc203b2f502cd453781 1 parent f99d506
Ryan Bates authored December 30, 2009
2  CHANGELOG.rdoc
Source Rendered
... ...
@@ -1,3 +1,5 @@
  1
+* Adding clear_aliased_actions to Ability which removes previously defined actions including defaults - see issue #20
  2
+
1 3
 * Append aliased actions (don't overwrite them) - see issue #20
2 4
 
3 5
 * Adding custom message argument to unauthorized! method (thanks tjwallace) - see issue #18
10  lib/cancan/ability.rb
@@ -160,12 +160,18 @@ def alias_action(*args)
160 160
       aliased_actions[target] += args
161 161
     end
162 162
     
163  
-    private
164  
-    
  163
+    # Returns a hash of aliased actions. The key is the target and the value is an array of actions aliasing the key.
165 164
     def aliased_actions
166 165
       @aliased_actions ||= default_alias_actions
167 166
     end
168 167
     
  168
+    # Removes previously aliased actions including the defaults.
  169
+    def clear_aliased_actions
  170
+      @aliased_actions = {}
  171
+    end
  172
+    
  173
+    private
  174
+    
169 175
     def default_alias_actions
170 176
       {
171 177
         :read => [:index, :show],
16  spec/cancan/ability_spec.rb
@@ -49,9 +49,7 @@
49 49
   
50 50
   it "should alias update or destroy actions to modify action" do
51 51
     @ability.alias_action :update, :destroy, :to => :modify
52  
-    @ability.can :modify, :all do |object_class, object|
53  
-      :modify_called
54  
-    end
  52
+    @ability.can(:modify, :all) { :modify_called }
55 53
     @ability.can?(:update, 123).should == :modify_called
56 54
     @ability.can?(:destroy, 123).should == :modify_called
57 55
   end
@@ -126,10 +124,12 @@
126 124
   it "should append aliased actions" do
127 125
     @ability.alias_action :update, :to => :modify
128 126
     @ability.alias_action :destroy, :to => :modify
129  
-    @ability.can :modify, :all do |object_class, object|
130  
-      :modify_called
131  
-    end
132  
-    @ability.can?(:update, 123).should == :modify_called
133  
-    @ability.can?(:destroy, 123).should == :modify_called
  127
+    @ability.aliased_actions[:modify].should == [:update, :destroy]
  128
+  end
  129
+  
  130
+  it "should clear aliased actions" do
  131
+    @ability.alias_action :update, :to => :modify
  132
+    @ability.clear_aliased_actions
  133
+    @ability.aliased_actions[:modify].should be_nil
134 134
   end
135 135
 end

0 notes on commit 7d3b4cd

Please sign in to comment.
Something went wrong with that request. Please try again.