File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -1410,8 +1410,8 @@ def migrate_without_lock
1410
1410
# Stores the current environment in the database.
1411
1411
def record_environment
1412
1412
return if down?
1413
- connection = ActiveRecord :: Base . connection
1414
- connection . internal_metadata [ :environment ] = connection . migration_context . current_environment
1413
+
1414
+ @ internal_metadata[ :environment ] = ActiveRecord :: Base . connection . migration_context . current_environment
1415
1415
end
1416
1416
1417
1417
def ran? ( migration )
Original file line number Diff line number Diff line change @@ -196,6 +196,30 @@ def test_migrator_forward
196
196
assert_equal ( 3 , migrator_b . current_version )
197
197
end
198
198
199
+ def test_internal_metadata_stores_environment
200
+ current_env = ActiveRecord ::ConnectionHandling ::DEFAULT_ENV . call
201
+ migrations_path = MIGRATIONS_ROOT + "/valid"
202
+ migrator = ActiveRecord ::MigrationContext . new ( migrations_path , @schema_migration_b , @internal_metadata_b )
203
+
204
+ migrator . up
205
+ assert_equal current_env , @internal_metadata_b [ :environment ]
206
+
207
+ original_rails_env = ENV [ "RAILS_ENV" ]
208
+ original_rack_env = ENV [ "RACK_ENV" ]
209
+ ENV [ "RAILS_ENV" ] = ENV [ "RACK_ENV" ] = "foofoo"
210
+ new_env = ActiveRecord ::ConnectionHandling ::DEFAULT_ENV . call
211
+
212
+ assert_not_equal current_env , new_env
213
+
214
+ sleep 1 # mysql by default does not store fractional seconds in the database
215
+ migrator . up
216
+ assert_equal new_env , @internal_metadata_b [ :environment ]
217
+ ensure
218
+ ENV [ "RAILS_ENV" ] = original_rails_env
219
+ ENV [ "RACK_ENV" ] = original_rack_env
220
+ migrator . down if migrator
221
+ end
222
+
199
223
private
200
224
def m ( name , version )
201
225
x = Sensor . new name , version
You can’t perform that action at this time.
0 commit comments