Skip to content

present: true not working as expected on embedded values #25

@jits

Description

@jits

Hi – firstly, thank you for this library!

I've noticed that using present: true on embedded values throws an error (seemingly every time).

To reproduce: if you add , present: true to

attribute :name, String
the test will fail with error messages like:

ShallowAttributes::MissingAttributeError: Mandatory attribute "name" was not provided
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/instance_methods.rb:214:in `block in define_mandatory_attributes'
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/instance_methods.rb:212:in `each'
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/instance_methods.rb:212:in `define_mandatory_attributes'
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/instance_methods.rb:40:in `initialize'
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/type.rb:80:in `new'
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/type.rb:80:in `type_instance'
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/type.rb:57:in `coerce'
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/class_methods.rb:117:in `city='
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/instance_methods.rb:227:in `block in define_attributes'
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/instance_methods.rb:226:in `each'
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/instance_methods.rb:226:in `define_attributes'
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/instance_methods.rb:93:in `attributes='
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/instance_methods.rb:142:in `coerce'
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/type.rb:57:in `coerce'
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/type/array.rb:31:in `block in coerce'
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/type/array.rb:30:in `map!'
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/type/array.rb:30:in `coerce'
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/type.rb:57:in `coerce'
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/class_methods.rb:117:in `addresses='
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/instance_methods.rb:227:in `block in define_attributes'
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/instance_methods.rb:226:in `each'
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/instance_methods.rb:226:in `define_attributes'
    /Users/jits/Src/shallow_attributes/lib/shallow_attributes/instance_methods.rb:38:in `initialize'
    /Users/jits/Src/shallow_attributes/test/custom_types_test.rb:62:in `new'
    /Users/jits/Src/shallow_attributes/test/custom_types_test.rb:62:in `block (4 levels) in <top (required)>'

I may be able to take a closer look and work on a PR when I have more time; any pointers are gladly welcome.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions