mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Call define_attribute_methods
before assert_no_queries
to address CI flakiness
Follow up 45be690f8e
.
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`.
This commit is contained in:
parent
3882a4d0d4
commit
a1ee4a9ff9
5 changed files with 80 additions and 9 deletions
|
@ -310,6 +310,10 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
def test_build
|
def test_build
|
||||||
devel = Developer.find(1)
|
devel = Developer.find(1)
|
||||||
|
|
||||||
|
# Load schema information so we don't query below if running just this test.
|
||||||
|
Project.define_attribute_methods
|
||||||
|
|
||||||
proj = assert_no_queries { devel.projects.build("name" => "Projekt") }
|
proj = assert_no_queries { devel.projects.build("name" => "Projekt") }
|
||||||
assert_not_predicate devel.projects, :loaded?
|
assert_not_predicate devel.projects, :loaded?
|
||||||
|
|
||||||
|
@ -325,6 +329,10 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
def test_new_aliased_to_build
|
def test_new_aliased_to_build
|
||||||
devel = Developer.find(1)
|
devel = Developer.find(1)
|
||||||
|
|
||||||
|
# Load schema information so we don't query below if running just this test.
|
||||||
|
Project.define_attribute_methods
|
||||||
|
|
||||||
proj = assert_no_queries { devel.projects.new("name" => "Projekt") }
|
proj = assert_no_queries { devel.projects.new("name" => "Projekt") }
|
||||||
assert_not_predicate devel.projects, :loaded?
|
assert_not_predicate devel.projects, :loaded?
|
||||||
|
|
||||||
|
|
|
@ -458,6 +458,10 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
||||||
def test_finder_method_with_dirty_target
|
def test_finder_method_with_dirty_target
|
||||||
company = companies(:first_firm)
|
company = companies(:first_firm)
|
||||||
new_clients = []
|
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_no_queries do
|
||||||
new_clients << company.clients_of_firm.build(name: "Another Client")
|
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 II")
|
||||||
|
@ -478,6 +482,10 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
||||||
def test_finder_bang_method_with_dirty_target
|
def test_finder_bang_method_with_dirty_target
|
||||||
company = companies(:first_firm)
|
company = companies(:first_firm)
|
||||||
new_clients = []
|
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_no_queries do
|
||||||
new_clients << company.clients_of_firm.build(name: "Another Client")
|
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 II")
|
||||||
|
@ -955,8 +963,11 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_transactions_when_adding_to_new_record
|
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_no_queries do
|
||||||
firm = Firm.new
|
|
||||||
firm.clients_of_firm.concat(Client.new("name" => "Natural Company"))
|
firm.clients_of_firm.concat(Client.new("name" => "Natural Company"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -970,6 +981,10 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
def test_new_aliased_to_build
|
def test_new_aliased_to_build
|
||||||
company = companies(:first_firm)
|
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_no_queries { company.clients_of_firm.new("name" => "Another Client") }
|
||||||
assert_not_predicate company.clients_of_firm, :loaded?
|
assert_not_predicate company.clients_of_firm, :loaded?
|
||||||
|
|
||||||
|
@ -980,6 +995,10 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
def test_build
|
def test_build
|
||||||
company = companies(:first_firm)
|
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_no_queries { company.clients_of_firm.build("name" => "Another Client") }
|
||||||
assert_not_predicate company.clients_of_firm, :loaded?
|
assert_not_predicate company.clients_of_firm, :loaded?
|
||||||
|
|
||||||
|
@ -1037,6 +1056,10 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
def test_build_many
|
def test_build_many
|
||||||
company = companies(:first_firm)
|
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_no_queries { company.clients_of_firm.build([{ "name" => "Another Client" }, { "name" => "Another Client II" }]) }
|
||||||
assert_equal 2, new_clients.size
|
assert_equal 2, new_clients.size
|
||||||
end
|
end
|
||||||
|
@ -1049,10 +1072,12 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
def test_build_without_loading_association
|
def test_build_without_loading_association
|
||||||
first_topic = topics(:first)
|
first_topic = topics(:first)
|
||||||
Reply.column_names
|
|
||||||
|
|
||||||
assert_equal 1, first_topic.replies.length
|
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_no_queries do
|
||||||
first_topic.replies.build(title: "Not saved", content: "Superstars")
|
first_topic.replies.build(title: "Not saved", content: "Superstars")
|
||||||
assert_equal 2, first_topic.replies.size
|
assert_equal 2, first_topic.replies.size
|
||||||
|
@ -1063,6 +1088,10 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
def test_build_via_block
|
def test_build_via_block
|
||||||
company = companies(:first_firm)
|
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_no_queries { company.clients_of_firm.build { |client| client.name = "Another Client" } }
|
||||||
assert_not_predicate company.clients_of_firm, :loaded?
|
assert_not_predicate company.clients_of_firm, :loaded?
|
||||||
|
|
||||||
|
@ -1073,6 +1102,10 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
def test_build_many_via_block
|
def test_build_many_via_block
|
||||||
company = companies(:first_firm)
|
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_no_queries do
|
||||||
company.clients_of_firm.build([{ "name" => "Another Client" }, { "name" => "Another Client II" }]) do |client|
|
company.clients_of_firm.build([{ "name" => "Another Client" }, { "name" => "Another Client II" }]) do |client|
|
||||||
client.name = "changed"
|
client.name = "changed"
|
||||||
|
@ -1086,8 +1119,6 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
def test_create_without_loading_association
|
def test_create_without_loading_association
|
||||||
first_firm = companies(:first_firm)
|
first_firm = companies(:first_firm)
|
||||||
Firm.column_names
|
|
||||||
Client.column_names
|
|
||||||
|
|
||||||
assert_equal 2, first_firm.clients_of_firm.size
|
assert_equal 2, first_firm.clients_of_firm.size
|
||||||
first_firm.clients_of_firm.reset
|
first_firm.clients_of_firm.reset
|
||||||
|
@ -1364,8 +1395,11 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_transaction_when_deleting_new_record
|
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_no_queries do
|
||||||
firm = Firm.new
|
|
||||||
client = Client.new("name" => "New Client")
|
client = Client.new("name" => "New Client")
|
||||||
firm.clients_of_firm << client
|
firm.clients_of_firm << client
|
||||||
firm.clients_of_firm.destroy(client)
|
firm.clients_of_firm.destroy(client)
|
||||||
|
@ -1822,8 +1856,11 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_transactions_when_replacing_on_new_record
|
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_no_queries do
|
||||||
firm = Firm.new
|
|
||||||
firm.clients_of_firm = [Client.new("name" => "New Client")]
|
firm.clients_of_firm = [Client.new("name" => "New Client")]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -274,6 +274,9 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
||||||
assert_queries(1) { posts(:thinking) }
|
assert_queries(1) { posts(:thinking) }
|
||||||
new_person = nil # so block binding catches it
|
new_person = nil # so block binding catches it
|
||||||
|
|
||||||
|
# Load schema information so we don't query below if running just this test.
|
||||||
|
Person.define_attribute_methods
|
||||||
|
|
||||||
assert_no_queries do
|
assert_no_queries do
|
||||||
new_person = Person.new first_name: "bob"
|
new_person = Person.new first_name: "bob"
|
||||||
end
|
end
|
||||||
|
@ -294,6 +297,9 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
||||||
def test_associate_new_by_building
|
def test_associate_new_by_building
|
||||||
assert_queries(1) { posts(:thinking) }
|
assert_queries(1) { posts(:thinking) }
|
||||||
|
|
||||||
|
# Load schema information so we don't query below if running just this test.
|
||||||
|
Person.define_attribute_methods
|
||||||
|
|
||||||
assert_no_queries do
|
assert_no_queries do
|
||||||
posts(:thinking).people.build(first_name: "Bob")
|
posts(:thinking).people.build(first_name: "Bob")
|
||||||
posts(:thinking).people.new(first_name: "Ted")
|
posts(:thinking).people.new(first_name: "Ted")
|
||||||
|
|
|
@ -231,9 +231,13 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_build_association_dont_create_transaction
|
def test_build_association_dont_create_transaction
|
||||||
assert_no_queries {
|
# Load schema information so we don't query below if running just this test.
|
||||||
Firm.new.build_account
|
Account.define_attribute_methods
|
||||||
}
|
|
||||||
|
firm = Firm.new
|
||||||
|
assert_no_queries do
|
||||||
|
firm.build_account
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_building_the_associated_object_with_implicit_sti_base_class
|
def test_building_the_associated_object_with_implicit_sti_base_class
|
||||||
|
|
|
@ -642,6 +642,10 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCa
|
||||||
|
|
||||||
def test_build_before_save
|
def test_build_before_save
|
||||||
company = companies(:first_firm)
|
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_no_queries { company.clients_of_firm.build("name" => "Another Client") }
|
||||||
assert_not_predicate company.clients_of_firm, :loaded?
|
assert_not_predicate company.clients_of_firm, :loaded?
|
||||||
|
|
||||||
|
@ -653,6 +657,10 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCa
|
||||||
|
|
||||||
def test_build_many_before_save
|
def test_build_many_before_save
|
||||||
company = companies(:first_firm)
|
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" }]) }
|
assert_no_queries { company.clients_of_firm.build([{ "name" => "Another Client" }, { "name" => "Another Client II" }]) }
|
||||||
|
|
||||||
company.name += "-changed"
|
company.name += "-changed"
|
||||||
|
@ -662,6 +670,10 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCa
|
||||||
|
|
||||||
def test_build_via_block_before_save
|
def test_build_via_block_before_save
|
||||||
company = companies(:first_firm)
|
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_no_queries { company.clients_of_firm.build { |client| client.name = "Another Client" } }
|
||||||
assert_not_predicate company.clients_of_firm, :loaded?
|
assert_not_predicate company.clients_of_firm, :loaded?
|
||||||
|
|
||||||
|
@ -673,6 +685,10 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCa
|
||||||
|
|
||||||
def test_build_many_via_block_before_save
|
def test_build_many_via_block_before_save
|
||||||
company = companies(:first_firm)
|
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
|
assert_no_queries do
|
||||||
company.clients_of_firm.build([{ "name" => "Another Client" }, { "name" => "Another Client II" }]) do |client|
|
company.clients_of_firm.build([{ "name" => "Another Client" }, { "name" => "Another Client II" }]) do |client|
|
||||||
client.name = "changed"
|
client.name = "changed"
|
||||||
|
|
Loading…
Reference in a new issue