Skip to content

Commit 18a9e8a

Browse files
committed
Fix protected envs multi-db test
Locally, this test was failing because the configurations for the test environment were empty. If they are empty, we won't raise the appropriate error. In the Rails test suite locally the environment in this test is `default_env`, but in CI it's `test`. We can fix this by pass `env` to `check_protected_environment!` instead of passing a string of the enviornment. Followup to rails#46340
1 parent 83601ab commit 18a9e8a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

activerecord/test/cases/tasks/database_tasks_test.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ class DatabaseTasksCheckProtectedEnvironmentsMultiDatabaseTest < ActiveRecord::T
154154

155155
def test_with_multiple_databases
156156
env = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call
157+
157158
with_multi_db_configurations(env) do
158159
protected_environments = ActiveRecord::Base.protected_environments
159160
current_env = ActiveRecord::Base.connection.migration_context.current_environment
@@ -167,7 +168,7 @@ def test_with_multiple_databases
167168

168169
assert_not_includes protected_environments, current_env
169170
# Assert not raises
170-
ActiveRecord::Tasks::DatabaseTasks.check_protected_environments!("test")
171+
ActiveRecord::Tasks::DatabaseTasks.check_protected_environments!(env)
171172

172173
ActiveRecord::Base.establish_connection(:secondary)
173174
connection = ActiveRecord::Base.connection
@@ -176,8 +177,9 @@ def test_with_multiple_databases
176177
schema_migration.create_version("1")
177178

178179
ActiveRecord::Base.protected_environments = [current_env.to_sym]
180+
179181
assert_raise(ActiveRecord::ProtectedEnvironmentError) do
180-
ActiveRecord::Tasks::DatabaseTasks.check_protected_environments!("test")
182+
ActiveRecord::Tasks::DatabaseTasks.check_protected_environments!(env)
181183
end
182184
ensure
183185
ActiveRecord::Base.protected_environments = protected_environments

0 commit comments

Comments
 (0)