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 of ShallowAttributes values #26

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

Conversation

morr
Copy link
Contributor

@morr morr commented Apr 8, 2019

This PR fixes such cases:

class A
  include ShallowAttributes
  attribute :a, Integer
end

class B
  include ShallowAttributes
  attribute :b, Array, of: A
end
  
a = A.new(a: 1)
b = B.new(b: [a])
NoMethodError: undefined method `each_pair' for #<A a=1>
from /Users/morr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/shallow_attributes-0.9.4/lib/shallow_attributes/instance_methods.rb:90:in `attributes='

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 99.758% when pulling 6008302 on morr:fix-coercion into 37fe194 on davydovanton:master.

@coveralls
Copy link

coveralls commented Apr 8, 2019

Coverage Status

Coverage increased (+0.002%) to 99.881% when pulling 9f0b031 on morr:fix-coercion into 37fe194 on davydovanton:master.

morr added 2 commits April 8, 2019 17:40
* nil-strings:
  inverse logic of allow_nil
  add allow_nil option to String type similar to other types
Copy link
Owner

@davydovanton davydovanton left a comment

Choose a reason for hiding this comment

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

Code looks good. Could you add some tests for this bug?

@morr morr force-pushed the fix-coercion branch 2 times, most recently from 51543ca to 1994464 Compare April 9, 2019 14:06
@morr
Copy link
Contributor Author

morr commented Apr 9, 2019

@davydovanton done

morr added 2 commits April 9, 2019 17:17
* nil-strings:
  change tests accoring to changed logic
  add test for allow_nil case for String
  bugfix
* fix-coercion:
  add test for array of ShallowAttributes objects
@lmmendes
Copy link

It seems that pull request #32 also addresses this issue.

morr added 3 commits July 20, 2020 16:43
* original/master:
  Create a note about strange ruby behaviour
  New release 🎉
  Force Bundler 1.x
  Add strict option to attributes
  Add Date type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants