davydovanton / shallow_attributes

Simple and lightweight Virtus analog.
MIT License
101 stars 18 forks source link

fix coercion of ShallowAttributes values #26

Open morr opened 5 years ago

morr commented 5 years ago

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 commented 5 years ago

Coverage Status

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

coveralls commented 5 years ago

Coverage Status

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

morr commented 5 years ago

@davydovanton done

lmmendes commented 5 years ago

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