diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-04-27 11:52:34 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-04-27 11:52:34 +0100 |
commit | 61555a0df11f535d46a0a631fbb0d0773613d08e (patch) | |
tree | da90ba3ee340a27d89e2bfdc0571092697883181 /activerecord | |
parent | df6f971e3aedf8bb1ec318de95d7ce849e2c9c9e (diff) | |
download | rails-61555a0df11f535d46a0a631fbb0d0773613d08e.tar.gz rails-61555a0df11f535d46a0a631fbb0d0773613d08e.tar.bz2 rails-61555a0df11f535d46a0a631fbb0d0773613d08e.zip |
allow AssociationProxy#scoped to take options so that API is the same as Base#scoped
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_proxy.rb | 8 | ||||
-rw-r--r-- | activerecord/test/cases/associations_test.rb | 4 |
2 files changed, 10 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index 44cbf473a1..ad029d1101 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -61,11 +61,15 @@ module ActiveRecord @association end - def scoped + def scoped(options = nil) association = @association - association.scoped.extending do + scope = association.scoped + + scope.extending! do define_method(:proxy_association) { association } end + scope.merge!(options) if options + scope end def respond_to?(name, include_private = false) diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb index 4d3751bba5..6412ec0599 100644 --- a/activerecord/test/cases/associations_test.rb +++ b/activerecord/test/cases/associations_test.rb @@ -214,6 +214,10 @@ class AssociationProxyTest < ActiveRecord::TestCase david = developers(:david) assert_equal david.association(:projects), david.projects.proxy_association end + + def test_scoped_allows_conditions + assert developers(:david).projects.scoped(where: 'foo').where_values.include?('foo') + end end class OverridingAssociationsTest < ActiveRecord::TestCase |