1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #24732 from y-yagi/update_record_specified_in_the_key

update record specified in key
This commit is contained in:
Rafael França 2016-05-21 09:01:36 -03:00
commit 91421984b7
2 changed files with 18 additions and 1 deletions

View file

@ -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)

View file

@ -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