aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorNeeraj Singh <neerajdotname@gmail.com>2010-07-01 21:41:41 -0400
committerJosé Valim <jose.valim@gmail.com>2010-07-13 22:03:35 +0200
commitedb5401039ee15c37b201244c5dbf660bed51fb4 (patch)
tree785330f325da5180afdde007b3769db87a29bc30 /activerecord/test
parentf4fbc2c1f943ff11776b2c7c34df6bcbe655a4e5 (diff)
downloadrails-edb5401039ee15c37b201244c5dbf660bed51fb4.tar.gz
rails-edb5401039ee15c37b201244c5dbf660bed51fb4.tar.bz2
rails-edb5401039ee15c37b201244c5dbf660bed51fb4.zip
count method should not take options if it is operated on has_many association which has finder_sql or counter_sql
[#2395 state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb26
1 files changed, 26 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 f1440804d2..6218cdd344 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -11,6 +11,32 @@ require 'models/comment'
require 'models/person'
require 'models/reader'
require 'models/tagging'
+require 'models/invoice'
+require 'models/line_item'
+
+class HasManyAssociationsTestForCountWithFinderSql < ActiveRecord::TestCase
+ class Invoice < ActiveRecord::Base
+ has_many :custom_line_items, :class_name => 'LineItem', :finder_sql => "SELECT line_items.* from line_items"
+ end
+ def test_should_fail
+ assert_raise(ArgumentError) do
+ Invoice.create.custom_line_items.count(:conditions => {:amount => 0})
+ end
+ end
+end
+
+class HasManyAssociationsTestForCountWithCountSql < ActiveRecord::TestCase
+ class Invoice < ActiveRecord::Base
+ has_many :custom_line_items, :class_name => 'LineItem', :counter_sql => "SELECT COUNT(*) line_items.* from line_items"
+ end
+ def test_should_fail
+ assert_raise(ArgumentError) do
+ Invoice.create.custom_line_items.count(:conditions => {:amount => 0})
+ end
+ end
+end
+
+
class HasManyAssociationsTest < ActiveRecord::TestCase
fixtures :accounts, :categories, :companies, :developers, :projects,