From 1ac8099f7a3e2ce7e6b9b37715785ff7c652953b Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Fri, 25 Mar 2011 14:24:43 -0700 Subject: [PATCH] return subject passed to authorize! - closes #314 --- lib/cancan/ability.rb | 1 + spec/cancan/ability_spec.rb | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/cancan/ability.rb b/lib/cancan/ability.rb index 6dfa175..5f86877 100644 --- a/lib/cancan/ability.rb +++ b/lib/cancan/ability.rb @@ -201,6 +201,7 @@ module CanCan message ||= unauthorized_message(action, subject) raise AccessDenied.new(message, action, subject) end + subject end def unauthorized_message(action, subject) diff --git a/spec/cancan/ability_spec.rb b/spec/cancan/ability_spec.rb index 84e2216..c71f9fa 100644 --- a/spec/cancan/ability_spec.rb +++ b/spec/cancan/ability_spec.rb @@ -317,9 +317,11 @@ describe CanCan::Ability do end end - it "should not raise access denied exception if ability is authorized to perform an action" do + it "should not raise access denied exception if ability is authorized to perform an action and return subject" do @ability.can :read, :foo - lambda { @ability.authorize!(:read, :foo) }.should_not raise_error + lambda { + @ability.authorize!(:read, :foo).should == :foo + }.should_not raise_error end it "should know when block is used in conditions" do