Append aliased actions (don't overwrite them) - closes #20
This commit is contained in:
parent
ef22de689b
commit
f99d506050
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user