Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

has_many associations should accept arguments to scoped, as they did …

…in 2.3
  • Loading branch information...
commit 6f87d6337e684772ce71e0aa71e0b8cd87967dea 1 parent df932c4
@willbryant authored
View
5 activerecord/lib/active_record/associations/association.rb
@@ -84,8 +84,9 @@ def target=(target)
loaded!
end
- def scoped
- target_scope.merge(association_scope)
+ def scoped(*args)
+ r = target_scope.merge(association_scope)
+ args.empty? ? r : r.scoped(*args)
end
# The scope for this association.
View
4 activerecord/lib/active_record/associations/collection_proxy.rb
@@ -68,9 +68,9 @@ def proxy_association
@association
end
- def scoped
+ def scoped(*args)
association = @association
- association.scoped.extending do
+ association.scoped(*args).extending do
define_method(:proxy_association) { association }
end
end
View
13 activerecord/test/cases/associations/has_many_associations_test.rb
@@ -360,6 +360,19 @@ def test_counting_using_finder_sql
assert_equal 2, Firm.find(4).clients_using_sql.count
end
+ def test_scoped_without_arguments
+ clients = Firm.first.clients.all
+ assert !clients.empty?
+ assert_equal clients, Firm.first.clients.scoped.all
+ end
+
+ def test_scoped_with_arguments
+ clients = Firm.first.clients.all
+ assert !clients.empty?
+ assert_equal clients, Firm.first.clients.scoped(:conditions => "id IS NOT NULL").all
+ assert Firm.first.clients.scoped(:conditions => "id IS NULL").all.empty?
+ end
+
def test_belongs_to_sanity
c = Client.new
assert_nil c.firm
Please sign in to comment.
Something went wrong with that request. Please try again.