Permalink
Browse files

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

…in 2.3
  • Loading branch information...
1 parent 1b4e6ca commit babde2e5bcb2ad3ba090b158e718961e5d08febc @willbryant committed Oct 11, 2011
@@ -83,8 +83,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.
@@ -61,9 +61,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
@@ -371,6 +371,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

0 comments on commit babde2e

Please sign in to comment.