Skip to content

Commit 5168f61

Browse files
committed
Fix nil behaviour
``` Failure: StandardEditionTranslationBlockContentConsistencyTest#test_editions_without_images_should_not_have_image_key_in_block_content [test/unit/app/models/standard_edition_translation_block_content_consistency_test.rb:45]: English translation should not have image key. Expected ["field_attribute", "body", "image"] to not include "image". bin/rails test test/unit/app/models/standard_edition_translation_block_content_consistency_test.rb:42 ``` This test was failing after the tweak in the previous commit. Why? - When we call `BlockContent#assign_attributes`, it iterates every attribute in the schema and calls the setter for it. - For "image" (type "object"), the code does `public_send("image=", values["image"])`. - If values["image"] is missing, that's `nil` — and because the attributes class has `attribute :image`, `to_h` will include `"image" => nil`, which makes `block_content.keys` include "image". So we've just had to add a `.compact` to filter out all `nil`s.
1 parent d3442bd commit 5168f61

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

app/models/standard_edition/block_content.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def attributes_class_for(attribute_config)
9191
delegate :[], to: :attributes
9292

9393
def to_h
94-
attributes
94+
attributes.compact
9595
end
9696
end
9797
attributes_class.set_temporary_name("Block content attributes")

0 commit comments

Comments
 (0)