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 a9d656852929ba80f04f09970564ef0a46fa46ee 1 parent 87bbf48
@willbryant authored
View
4 activerecord/lib/active_record/associations/association_collection.rb
@@ -35,8 +35,8 @@ def select(select = nil)
end
end
- def scoped
- with_scope(construct_scope) { @reflection.klass.scoped }
+ def scoped(*args)
+ with_scope(construct_scope) { @reflection.klass.scoped(*args) }
end
def find(*args)
View
13 activerecord/test/cases/associations/has_many_associations_test.rb
@@ -252,6 +252,19 @@ def test_counting_using_finder_sql
end
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.