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

This commit is contained in:
Ryan Bates 2009-12-30 17:49:49 -08:00
parent ef22de689b
commit f99d506050
3 changed files with 16 additions and 4 deletions

View File

@ -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 * Adding custom message argument to unauthorized! method (thanks tjwallace) - see issue #18

View File

@ -156,7 +156,8 @@ module CanCan
# This way one can use params[:action] in the controller to determine the permission. # This way one can use params[:action] in the controller to determine the permission.
def alias_action(*args) def alias_action(*args)
target = args.pop[:to] target = args.pop[:to]
aliased_actions[target] = args aliased_actions[target] ||= []
aliased_actions[target] += args
end end
private private

View File

@ -2,9 +2,8 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe CanCan::Ability do describe CanCan::Ability do
before(:each) do before(:each) do
@ability_class = Class.new @ability = Object.new
@ability_class.send(:include, CanCan::Ability) @ability.extend(CanCan::Ability)
@ability = @ability_class.new
end end
it "should be able to :read anything" do 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, 3).should be_true
@ability.can?(:read, 123).should be_false @ability.can?(:read, 123).should be_false
end 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 end