aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2011-11-03 21:14:51 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2011-11-03 21:17:15 -0700
commit533a9f84b035756eedf9fdccf0c494dc9701ba72 (patch)
tree5454ceae355dc24e742f93f6fe81a905b3da15d9 /activerecord/test/cases/associations
parentb5f908a7ad515215f164e306f82c3e6c506182cb (diff)
downloadrails-533a9f84b035756eedf9fdccf0c494dc9701ba72.tar.gz
rails-533a9f84b035756eedf9fdccf0c494dc9701ba72.tar.bz2
rails-533a9f84b035756eedf9fdccf0c494dc9701ba72.zip
Merge pull request #3507 from jmazzi/issue-3503
Preserve SELECT columns on the COUNT for finder_sql when possible
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index cddd2a6f8c..a60af7c046 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -41,6 +41,21 @@ class HasManyAssociationsTestForCountWithCountSql < ActiveRecord::TestCase
end
end
+class HasManyAssociationsTestForCountDistinctWithFinderSql < ActiveRecord::TestCase
+ class Invoice < ActiveRecord::Base
+ has_many :custom_line_items, :class_name => 'LineItem', :finder_sql => "SELECT DISTINCT line_items.amount from line_items"
+ end
+
+ def test_should_count_distinct_results
+ invoice = Invoice.new
+ invoice.custom_line_items << LineItem.new(:amount => 0)
+ invoice.custom_line_items << LineItem.new(:amount => 0)
+ invoice.save!
+
+ assert_equal 1, invoice.custom_line_items.count
+ end
+end
+
class HasManyAssociationsTest < ActiveRecord::TestCase