solnic/virtus

Bug: nil default value of Array attribute ignored

Opened this issue · 1 comments

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?

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