diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-10-09 03:31:34 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-10-09 03:46:22 +0900 |
commit | a1ee4a9ff9d4a3cb255365310ead0dc7b739c6be (patch) | |
tree | d2ad6db8cfd9b65a6101e9a57b0c4269e36f648f /activerecord/test/cases/autosave_association_test.rb | |
parent | 3882a4d0d475f1347a7dc3774e9285c80b1c8fe2 (diff) | |
download | rails-a1ee4a9ff9d4a3cb255365310ead0dc7b739c6be.tar.gz rails-a1ee4a9ff9d4a3cb255365310ead0dc7b739c6be.tar.bz2 rails-a1ee4a9ff9d4a3cb255365310ead0dc7b739c6be.zip |
Call `define_attribute_methods` before `assert_no_queries` to address CI flakiness
Follow up 45be690f8e6db019aac6198ba49d608a2e14824b.
Somehow calling `define_attribute_methods` in `build`/`new` sometimes
causes the `table_exists?` query.
To address CI flakiness due to `assert_no_queries` failure, ensure
`define_attribute_methods` before `assert_no_queries`.
Diffstat (limited to 'activerecord/test/cases/autosave_association_test.rb')
-rw-r--r-- | activerecord/test/cases/autosave_association_test.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb index 42d47527b2..88df0eed55 100644 --- a/activerecord/test/cases/autosave_association_test.rb +++ b/activerecord/test/cases/autosave_association_test.rb @@ -642,6 +642,10 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCa def test_build_before_save 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") } assert_not_predicate company.clients_of_firm, :loaded? @@ -653,6 +657,10 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCa def test_build_many_before_save company = companies(:first_firm) + + # Load schema information so we don't query below if running just this test. + Client.define_attribute_methods + assert_no_queries { company.clients_of_firm.build([{ "name" => "Another Client" }, { "name" => "Another Client II" }]) } company.name += "-changed" @@ -662,6 +670,10 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCa def test_build_via_block_before_save 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" } } assert_not_predicate company.clients_of_firm, :loaded? @@ -673,6 +685,10 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCa def test_build_many_via_block_before_save company = companies(:first_firm) + + # Load schema information so we don't query below if running just this test. + Client.define_attribute_methods + assert_no_queries do company.clients_of_firm.build([{ "name" => "Another Client" }, { "name" => "Another Client II" }]) do |client| client.name = "changed" |