diff options
Diffstat (limited to 'activerecord/test/cases/associations/has_many_associations_test.rb')
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 60 |
1 files changed, 12 insertions, 48 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 9869657961..545bc77fed 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -468,10 +468,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase company = companies(:first_firm) new_clients = [] - # Load schema information so we don't query below if running just this test. - Client.define_attribute_methods - - assert_no_queries do + assert_queries(0) do new_clients << company.clients_of_firm.build(name: "Another Client") new_clients << company.clients_of_firm.build(name: "Another Client II") new_clients << company.clients_of_firm.build(name: "Another Client III") @@ -492,10 +489,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase company = companies(:first_firm) new_clients = [] - # Load schema information so we don't query below if running just this test. - Client.define_attribute_methods - - assert_no_queries do + assert_queries(0) do new_clients << company.clients_of_firm.build(name: "Another Client") new_clients << company.clients_of_firm.build(name: "Another Client II") new_clients << company.clients_of_firm.build(name: "Another Client III") @@ -1015,11 +1009,8 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end def test_transactions_when_adding_to_new_record - # Load schema information so we don't query below if running just this test. - Client.define_attribute_methods - firm = Firm.new - assert_no_queries do + assert_queries(0) do firm.clients_of_firm.concat(Client.new("name" => "Natural Company")) end end @@ -1034,10 +1025,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase def test_new_aliased_to_build company = companies(:first_firm) - # Load schema information so we don't query below if running just this test. - Client.define_attribute_methods - - new_client = assert_no_queries { company.clients_of_firm.new("name" => "Another Client") } + new_client = assert_queries(0) { company.clients_of_firm.new("name" => "Another Client") } assert_not_predicate company.clients_of_firm, :loaded? assert_equal "Another Client", new_client.name @@ -1048,10 +1036,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase def test_build company = companies(:first_firm) - # Load schema information so we don't query below if running just this test. - Client.define_attribute_methods - - new_client = assert_no_queries { company.clients_of_firm.build("name" => "Another Client") } + new_client = assert_queries(0) { company.clients_of_firm.build("name" => "Another Client") } assert_not_predicate company.clients_of_firm, :loaded? assert_equal "Another Client", new_client.name @@ -1109,10 +1094,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase def test_build_many company = companies(:first_firm) - # Load schema information so we don't query below if running just this test. - Client.define_attribute_methods - - new_clients = assert_no_queries { company.clients_of_firm.build([{ "name" => "Another Client" }, { "name" => "Another Client II" }]) } + new_clients = assert_queries(0) { company.clients_of_firm.build([{ "name" => "Another Client" }, { "name" => "Another Client II" }]) } assert_equal 2, new_clients.size end @@ -1127,10 +1109,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal 1, first_topic.replies.length - # Load schema information so we don't query below if running just this test. - Reply.define_attribute_methods - - assert_no_queries do + assert_queries(0) do first_topic.replies.build(title: "Not saved", content: "Superstars") assert_equal 2, first_topic.replies.size end @@ -1141,10 +1120,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase def test_build_via_block company = companies(:first_firm) - # Load schema information so we don't query below if running just this test. - Client.define_attribute_methods - - new_client = assert_no_queries { company.clients_of_firm.build { |client| client.name = "Another Client" } } + new_client = assert_queries(0) { company.clients_of_firm.build { |client| client.name = "Another Client" } } assert_not_predicate company.clients_of_firm, :loaded? assert_equal "Another Client", new_client.name @@ -1155,10 +1131,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase def test_build_many_via_block company = companies(:first_firm) - # Load schema information so we don't query below if running just this test. - Client.define_attribute_methods - - new_clients = assert_no_queries do + new_clients = assert_queries(0) do company.clients_of_firm.build([{ "name" => "Another Client" }, { "name" => "Another Client II" }]) do |client| client.name = "changed" end @@ -1447,11 +1420,8 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end def test_transaction_when_deleting_new_record - # Load schema information so we don't query below if running just this test. - Client.define_attribute_methods - firm = Firm.new - assert_no_queries do + assert_queries(0) do client = Client.new("name" => "New Client") firm.clients_of_firm << client firm.clients_of_firm.destroy(client) @@ -1966,11 +1936,8 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end def test_transactions_when_replacing_on_new_record - # Load schema information so we don't query below if running just this test. - Client.define_attribute_methods - firm = Firm.new - assert_no_queries do + assert_queries(0) do firm.clients_of_firm = [Client.new("name" => "New Client")] end end @@ -2024,11 +1991,8 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end def test_get_ids_for_association_on_new_record_does_not_try_to_find_records - # Load schema information so we don't query below if running just this test. - companies(:first_client).contract_ids - company = Company.new - assert_no_queries do + assert_queries(0) do company.contract_ids end |