diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-05-21 09:01:36 -0300 |
---|---|---|
committer | Rafael França <rafaelmfranca@gmail.com> | 2016-05-21 09:01:36 -0300 |
commit | 91421984b7182a483db0f96239e2d5f27ea3a9de (patch) | |
tree | 782cb2cca41df9ebea3d3bcefea464b8ece8ef6f /activerecord | |
parent | db312a9fb04097e7d584d24dd446aac7dea7e11f (diff) | |
parent | cfa1df4b07bee5b2bbcbf9edd2ac287b4fb23c18 (diff) | |
download | rails-91421984b7182a483db0f96239e2d5f27ea3a9de.tar.gz rails-91421984b7182a483db0f96239e2d5f27ea3a9de.tar.bz2 rails-91421984b7182a483db0f96239e2d5f27ea3a9de.zip |
Merge pull request #24732 from y-yagi/update_record_specified_in_the_key
update record specified in key
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/internal_metadata.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/migration_test.rb | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/internal_metadata.rb b/activerecord/lib/active_record/internal_metadata.rb index 81db96bffd..17a5dc1d1b 100644 --- a/activerecord/lib/active_record/internal_metadata.rb +++ b/activerecord/lib/active_record/internal_metadata.rb @@ -19,7 +19,7 @@ module ActiveRecord end def []=(key, value) - first_or_initialize(key: key).update_attributes!(value: value) + find_or_initialize_by(key: key).update_attributes!(value: value) end def [](key) diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 6ad028d31b..36b6662820 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -428,6 +428,23 @@ class MigrationTest < ActiveRecord::TestCase ENV["RACK_ENV"] = original_rack_env end + def test_internal_metadata_stores_environment_when_other_data_exists + ActiveRecord::InternalMetadata.delete_all + ActiveRecord::InternalMetadata[:foo] = 'bar' + + current_env = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call + migrations_path = MIGRATIONS_ROOT + "/valid" + old_path = ActiveRecord::Migrator.migrations_paths + ActiveRecord::Migrator.migrations_paths = migrations_path + + current_env = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call + ActiveRecord::Migrator.up(migrations_path) + assert_equal current_env, ActiveRecord::InternalMetadata[:environment] + assert_equal 'bar', ActiveRecord::InternalMetadata[:foo] + ensure + ActiveRecord::Migrator.migrations_paths = old_path + end + def test_rename_internal_metadata_table original_internal_metadata_table_name = ActiveRecord::Base.internal_metadata_table_name |