-
Notifications
You must be signed in to change notification settings - Fork 19
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
Conversation
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
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'] |
There was a problem hiding this comment.
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?
Thanks for the first attempt. However I ended up resolving this in #63 where I made a few tweaks to the code |
This bug is fixed in v0.5.1 |
If an enum value is set to nil the snapshot creation fails.