Fix bug in internal metadata

Since changing internal metadata to no longer inherit from Base
in #45982 I accidentally changed the behavior when a key's value is the
same. Prior to this change the record would not be updated if the
environment key was found an the value had not changed. So instead of
just checking whether we have an entry here we also need to check if the
value should actually be updated, otherwise we should return the entry.
This commit is contained in:
eileencodes 2022-09-12 16:02:59 -04:00
parent ac751f8cbe
commit 3d50f34af0
No known key found for this signature in database
GPG Key ID: BA5C575120BBE8DF
2 changed files with 30 additions and 1 deletions

@ -96,7 +96,11 @@ def update_or_create_entry(key, value)
entry = select_entry(key)
if entry
update_entry(key, value)
if entry[value_key] != value
update_entry(key, value)
else
entry[value_key]
end
else
create_entry(key, value)
end

@ -762,6 +762,31 @@ def test_internal_metadata_not_used_when_not_enabled
@internal_metadata.create_table
end
def test_inserting_a_new_entry_into_internal_metadata
@internal_metadata[:version] = "foo"
assert_equal "foo", @internal_metadata[:version]
ensure
@internal_metadata.delete_all_entries
end
def test_updating_an_existing_entry_into_internal_metadata
@internal_metadata[:version] = "foo"
updated_at = @internal_metadata.send(:select_entry, :version)["updated_at"]
assert_equal "foo", @internal_metadata[:version]
# same version doesn't update timestamps
@internal_metadata[:version] = "foo"
assert_equal "foo", @internal_metadata[:version]
assert_equal updated_at, @internal_metadata.send(:select_entry, :version)["updated_at"]
# updated version updates timestamps
@internal_metadata[:version] = "not_foo"
assert_equal "not_foo", @internal_metadata[:version]
assert_not_equal updated_at, @internal_metadata.send(:select_entry, :version)["updated_at"]
ensure
@internal_metadata.delete_all_entries
end
def test_internal_metadata_create_table_wont_be_affected_by_schema_cache
@internal_metadata.drop_table
assert_not_predicate @internal_metadata, :table_exists?