diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-10-03 17:28:24 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-10-04 13:34:38 -0300 |
commit | 98967293cfef14a70281b47c4a07b5318f94d668 (patch) | |
tree | b16eed0d3b545ad6deaec6e80be4eed6b25f92ce /activerecord/test | |
parent | 95369a5921a87988fbcb1b1d66a68255f3cf8924 (diff) | |
download | rails-98967293cfef14a70281b47c4a07b5318f94d668.tar.gz rails-98967293cfef14a70281b47c4a07b5318f94d668.tar.bz2 rails-98967293cfef14a70281b47c4a07b5318f94d668.zip |
Merge pull request #6978 from frodsan/count_nosql_unsaved_parent
Count returns 0 without querying if parent is not saved
Diffstat (limited to 'activerecord/test')
3 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb index bacab8d2f2..cad4cc9bf9 100644 --- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb @@ -812,6 +812,12 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase assert_equal 1, developer.projects.count end + def test_counting_should_not_fire_sql_if_parent_is_unsaved + assert_no_queries do + assert_equal 0, Developer.new.projects.count + end + end + unless current_adapter?(:PostgreSQLAdapter) def test_count_with_finder_sql assert_equal 3, projects(:active_record).developers_with_finder_sql.count diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 30cfcc53d2..ed4475770b 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -301,6 +301,12 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal firm.limited_clients.length, firm.limited_clients.count end + def test_counting_should_not_fire_sql_if_parent_is_unsaved + assert_no_queries do + assert_equal 0, Person.new.readers.count + end + end + def test_finding assert_equal 2, Firm.find(:first, :order => "id").clients.length end diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index e4710eb61b..ffd7f4efa2 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -782,6 +782,12 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase assert_equal 1, authors(:mary).categories.general.count end + def test_counting_should_not_fire_sql_if_parent_is_unsaved + assert_no_queries do + assert_equal 0, Person.new.posts.count + end + end + def test_has_many_through_belongs_to_should_update_when_the_through_foreign_key_changes post = posts(:eager_other) |