From a10243a5691e29f801b6777d443de33ffb18a345 Mon Sep 17 00:00:00 2001 From: Florent Piteau Date: Fri, 1 Apr 2011 21:25:19 +0200 Subject: [PATCH] When using an existing scope, it should be merged properly to the class. May fix ryanb/cancan#328 :) --- lib/cancan/model_adapters/active_record_adapter.rb | 2 +- spec/cancan/model_adapters/active_record_adapter_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cancan/model_adapters/active_record_adapter.rb b/lib/cancan/model_adapters/active_record_adapter.rb index 4110847..a98cae2 100644 --- a/lib/cancan/model_adapters/active_record_adapter.rb +++ b/lib/cancan/model_adapters/active_record_adapter.rb @@ -87,7 +87,7 @@ module CanCan def database_records if override_scope - override_scope + @model_class.scoped.merge(override_scope) elsif @model_class.respond_to?(:where) && @model_class.respond_to?(:joins) @model_class.where(conditions).joins(joins) else diff --git a/spec/cancan/model_adapters/active_record_adapter_spec.rb b/spec/cancan/model_adapters/active_record_adapter_spec.rb index c409d74..fc8c8a4 100644 --- a/spec/cancan/model_adapters/active_record_adapter_spec.rb +++ b/spec/cancan/model_adapters/active_record_adapter_spec.rb @@ -125,7 +125,7 @@ if ENV["MODEL_ADAPTER"].nil? || ENV["MODEL_ADAPTER"] == "active_record" Article.accessible_by(@ability).should == [article1] end - it "should only fetch associated records for nested controllers" do + it "should fetch only associated records when using with a scope for conditions" do @ability.can :read, Article, Article.where(:secret => true) category1 = Category.create!(:visible => false) category2 = Category.create!(:visible => true)