solnic / virtus

[DISCONTINUED ] Attributes on Steroids for Plain Old Ruby Objects
MIT License
3.77k stars 229 forks source link

Bug: nil default value of Array attribute ignored #369

Open csokol opened 8 years ago

csokol commented 8 years ago

I think I found a bug in virtus.

It looks like the default parameter is being ignored for Array attributes. Here's how to reproduce:

require 'virtus'
class Foo
  include Virtus.model

  attribute :array, Array, default: nil
  attribute :hash, Hash, default: nil
  attribute :string, String, default: nil
end
require './foo.rb'
require 'test/unit/assertions'
include Test::Unit::Assertions

f = Foo.new({})
assert(f.string.nil?, 'string should be nil')
assert(f.hash.nil?, 'hash should be nil')

p f.array
assert(f.array.nil?, 'array should be nil')

Am I missing something or is this a real bug?

ravicious commented 7 years ago

I ran into this too recently. I believe this issue is related to #334 and could be closed in favor of that issue.