diff options
-rw-r--r-- | activerecord/lib/active_record/scoping/named.rb | 17 | ||||
-rw-r--r-- | activerecord/test/cases/base_test.rb | 5 |
2 files changed, 13 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/scoping/named.rb b/activerecord/lib/active_record/scoping/named.rb index b43e08157a..5943baf93b 100644 --- a/activerecord/lib/active_record/scoping/named.rb +++ b/activerecord/lib/active_record/scoping/named.rb @@ -29,17 +29,16 @@ module ActiveRecord # You can define a \scope that applies to all finders using # ActiveRecord::Base.default_scope. def scoped(options = nil) - if options - scoped.apply_finder_options(options) + if current_scope + scope = current_scope.clone else - if current_scope - current_scope.clone - else - scope = relation - scope.default_scoped = true - scope - end + scope = relation + scope.default_scoped = true + scope end + + scope.merge!(options) if options + scope end ## diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index ef22936e18..024225b813 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -2087,4 +2087,9 @@ class BasicsTest < ActiveRecord::TestCase assert_equal record, klass.public_send(meth, :foo, :bar) end end + + test "scoped can take a values hash" do + klass = Class.new(ActiveRecord::Base) + assert_equal ['foo'], klass.scoped(select: 'foo').select_values + end end |