Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky primary key test #48473

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 13 additions & 7 deletions activerecord/test/cases/primary_keys_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,20 +271,26 @@ def test_serial_with_unquoted_sequence_name
end

class PrimaryKeyWithNoConnectionTest < ActiveRecord::TestCase
class NoConnection < ActiveRecord::Base
self.abstract_class = true
self.primary_key = "foo"
end

self.use_transactional_tests = false

unless in_memory_db?
def test_set_primary_key_with_no_connection
connection = ActiveRecord::Base.remove_connection

model = Class.new(ActiveRecord::Base)
model.primary_key = "foo"
NoConnection.establish_connection :arunit
# execute to fully establish a connection
NoConnection.connection.execute("SELECT 1")

assert_equal "foo", model.primary_key
assert NoConnection.connected?
assert_equal "foo", NoConnection.primary_key

ActiveRecord::Base.establish_connection(connection)
ActiveRecord::Base.connection_handler.remove_connection_pool("PrimaryKeyWithNoConnectionTest::NoConnection")
assert_nil NoConnection.connected?

assert_equal "foo", model.primary_key
assert_equal "foo", NoConnection.primary_key
end
end
end
Expand Down