Skip to content
Browse files

Append aliased actions (don't overwrite them) - closes #20

  • Loading branch information...
1 parent ef22de6 commit f99d50605060c34b3c9c7fa359fc7cf80504a991 @ryanb committed Dec 30, 2009
Showing with 16 additions and 4 deletions.
  1. +2 −0 CHANGELOG.rdoc
  2. +2 −1 lib/cancan/ability.rb
  3. +12 −3 spec/cancan/ability_spec.rb
View
2 CHANGELOG.rdoc
@@ -1,3 +1,5 @@
+* Append aliased actions (don't overwrite them) - see issue #20
+
* Adding custom message argument to unauthorized! method (thanks tjwallace) - see issue #18
View
3 lib/cancan/ability.rb
@@ -156,7 +156,8 @@ def cannot(action, noun, &block)
# This way one can use params[:action] in the controller to determine the permission.
def alias_action(*args)
target = args.pop[:to]
- aliased_actions[target] = args
+ aliased_actions[target] ||= []
+ aliased_actions[target] += args
end
private
View
15 spec/cancan/ability_spec.rb
@@ -2,9 +2,8 @@
describe CanCan::Ability do
before(:each) do
- @ability_class = Class.new
- @ability_class.send(:include, CanCan::Ability)
- @ability = @ability_class.new
+ @ability = Object.new
+ @ability.extend(CanCan::Ability)
end
it "should be able to :read anything" do
@@ -123,4 +122,14 @@
@ability.can?(:read, 3).should be_true
@ability.can?(:read, 123).should be_false
end
+
+ 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
+ end
end

0 comments on commit f99d506

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