Skip to content

Fix coercion for embedded shallow attributes type, receiving unexpected parameters#34

Open
javierseixas wants to merge 6 commits into
davydovanton:masterfrom
LemontechSA:fix-nested-shallow-attributes-with-unexpected-parameters
Open

Fix coercion for embedded shallow attributes type, receiving unexpected parameters#34
javierseixas wants to merge 6 commits into
davydovanton:masterfrom
LemontechSA:fix-nested-shallow-attributes-with-unexpected-parameters

Conversation

@javierseixas

Copy link
Copy Markdown

PROBLEM

Having two classes related like follow:

class Address
  include ShallowAttributes

  attribute :street,  String
end

class Person
  include ShallowAttributes

  attribute :name,      String
  attribute :address,   Address
end

... when the embedded class receives parameters that doesn't match the defined attributes:

{
    name: 'John',
        address: {
            street: 'Street',
            number: '12'
        }
}

... an error raises because doesn't find the definition in the class.

When a class including ShallowAttribues is initialized, during the initialization parameters non matching attributes are dismissed. But it doesn't happen during the lower levels in the hierarchy, because the objects are creating according to the type.

SOLUTION

Adding some logic during the type coercion and initialization avoid the conflict.

# @private
#
# @since 0.9.4
class Boolean; end

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Needs to define Boolean class for adding to the DEFAULT_TYPE_OBJECTS.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.003%) to 99.781% when pulling c4c8b43 on LemontechSA:fix-nested-shallow-attributes-with-unexpected-parameters into 51f5c1b on davydovanton:master.

@coveralls

coveralls commented Nov 15, 2019

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.005%) to 99.784% when pulling 80990d9 on LemontechSA:fix-nested-shallow-attributes-with-unexpected-parameters into 51f5c1b on davydovanton:master.

@javierseixas javierseixas changed the title Adds test for embedded shallow attributes with unexpected parameters Fix coercion for embedded shallow attributes type, receiving unexpected parameters Nov 15, 2019
@javierseixas
javierseixas force-pushed the fix-nested-shallow-attributes-with-unexpected-parameters branch from c4c8b43 to 80990d9 Compare August 14, 2020 02:48
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.

3 participants