From 1ac8099f7a3e2ce7e6b9b37715785ff7c652953b Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Fri, 25 Mar 2011 14:24:43 -0700 Subject: [PATCH 1/3] 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 From 89e40987d8215516b97df31a551b2562d4e01493 Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Fri, 25 Mar 2011 14:26:33 -0700 Subject: [PATCH 2/3] make sure ActiveRecord::Relation is defined before checking conditions against it so Rails 2 is supported again - closes #312 --- lib/cancan/model_adapters/active_record_adapter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cancan/model_adapters/active_record_adapter.rb b/lib/cancan/model_adapters/active_record_adapter.rb index 22fb669..4110847 100644 --- a/lib/cancan/model_adapters/active_record_adapter.rb +++ b/lib/cancan/model_adapters/active_record_adapter.rb @@ -99,7 +99,7 @@ module CanCan def override_scope conditions = @rules.map(&:conditions).compact - if conditions.any? { |c| c.kind_of?(ActiveRecord::Relation) } + if defined?(ActiveRecord::Relation) && conditions.any? { |c| c.kind_of?(ActiveRecord::Relation) } if conditions.size == 1 conditions.first else From fb8e9bde5744dd383042837e3815435d493e1c26 Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Fri, 25 Mar 2011 14:28:26 -0700 Subject: [PATCH 3/3] releasing 1.6.3 --- CHANGELOG.rdoc | 7 +++++++ cancan.gemspec | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index d581528..c3ec7ac 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,3 +1,10 @@ +1.6.3 (March 25, 2011) + +* Make sure ActiveRecord::Relation is defined before checking conditions against it so Rails 2 is supported again - see issue #312 + +* Return subject passed to authorize! - see issue #314 + + 1.6.2 (March 18, 2011) * Fixed instance loading when :singleton option is used - see issue #310 diff --git a/cancan.gemspec b/cancan.gemspec index 4c1c670..1f732ab 100644 --- a/cancan.gemspec +++ b/cancan.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "cancan" - s.version = "1.6.2" + s.version = "1.6.3" s.author = "Ryan Bates" s.email = "ryan@railscasts.com" s.homepage = "http://github.com/ryanb/cancan"