Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Hash.fetch(v) resulting in KeyError: key not found: nil #62

Closed

Conversation

henningthies
Copy link
Contributor

If an enum value is set to nil the snapshot creation fails.

If an enum value is set to nil the snapshot creation fails.
@@ -48,7 +48,7 @@ def metadata=(h)
def build_snapshot_item(instance, child_group_name: nil)
attributes = instance.attributes
attributes.each do |k, v|
if instance.class.defined_enums.key?(k)
if instance.class.defined_enums.key?(k) && v.present?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if instance.class.defined_enums.key?(k) && v.present?
if v && instance.class.defined_enums.key?(k)


assert snapshot_item.object['status'] == 0

assert_equal @snapshot.snapshot_items.first.object['status'], snapshot_item.object['status']

# Test for enum value nil
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this to a separate test case?

snapshot_item = @snapshot.build_snapshot_item(post)

assert snapshot_item.object['status'].nil?
assert_equal @snapshot.snapshot_items.last.object['status'], snapshot_item.object['status']
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we asserting on @snapshot.snapshot_items? I think we only need to assert on snapshot_item.object['status'] in these tests?

@westonganger
Copy link
Owner

Thanks for the first attempt. However I ended up resolving this in #63 where I made a few tweaks to the code

@westonganger
Copy link
Owner

This bug is fixed in v0.5.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants