Embedded Value Coercer missing methods? #212

Closed
MichaelXavier opened this Issue Oct 10, 2013 · 1 comment

Comments

Projects
None yet
2 participants

I'm not all that familiar with Virtus' internals but it looks like the coercer for virtus-like objects may be missing a success? method. Example:

require 'virtus'
require 'pp'

class CanadianTaxRate
  include Virtus.value_object(:strict => true)

  attribute :percentage, Float
end

class CanadianTaxTable
  include Virtus.value_object(:strict => true)

  attribute :gst,          CanadianTaxRate
end

pp CanadianTaxTable.new(:gst => CanadianTaxRate.new(:percentage => 5.0))

Output:

/home/michael/.rvm/gems/ruby-2.0.0-p247/gems/virtus-1.0.0.beta8/lib/virtus/attribute/strict.rb:10:in `coerce': undefined method `success?' for #<Virtus::Attribute::EmbeddedValue::FromOpenStruct:0x000000044a9940> (NoMethodError)
    from /home/michael/.rvm/gems/ruby-2.0.0-p247/gems/virtus-1.0.0.beta8/lib/virtus/attribute/coercible.rb:8:in `set'
    from /home/michael/.rvm/gems/ruby-2.0.0-p247/gems/virtus-1.0.0.beta8/lib/virtus/attribute_set.rb:146:in `block in define_writer_method'
    from /home/michael/.rvm/gems/ruby-2.0.0-p247/gems/virtus-1.0.0.beta8/lib/virtus/attribute_set.rb:173:in `block in set'
    from /home/michael/.rvm/gems/ruby-2.0.0-p247/gems/virtus-1.0.0.beta8/lib/virtus/attribute_set.rb:170:in `each'
    from /home/michael/.rvm/gems/ruby-2.0.0-p247/gems/virtus-1.0.0.beta8/lib/virtus/attribute_set.rb:170:in `set'
    from /home/michael/.rvm/gems/ruby-2.0.0-p247/gems/virtus-1.0.0.beta8/lib/virtus/instance_methods.rb:17:in `initialize'
    from virtus_coercion_bug.rb:16:in `new'
    from virtus_coercion_bug.rb:16:in `<main>'

The workaround is to turn off coercion but obviously this undermines strict as it will let any old value breeze through.

Owner

solnic commented Oct 10, 2013

Thanks, this is a bug. I forgot about this interface. I'll fix it quickly.

@solnic solnic closed this in ee92681 Oct 13, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment