diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 6be73e5..0843027 100644 --- a/CHANGELOG.rdoc +++ b/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 diff --git a/lib/cancan/ability.rb b/lib/cancan/ability.rb index 4783e7b..1fab685 100644 --- a/lib/cancan/ability.rb +++ b/lib/cancan/ability.rb @@ -156,7 +156,8 @@ module CanCan # 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 diff --git a/spec/cancan/ability_spec.rb b/spec/cancan/ability_spec.rb index 3377e97..e6178a1 100644 --- a/spec/cancan/ability_spec.rb +++ b/spec/cancan/ability_spec.rb @@ -2,9 +2,8 @@ require File.dirname(__FILE__) + '/../spec_helper' 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 @@ describe CanCan::Ability do @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