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 coercion for embedded shallow attributes type, receiving unexpected parameters #34

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

javierseixas
Copy link

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
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

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
Copy link

coveralls commented Nov 15, 2019

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