mustmodify / valuable

quick ruby modeling -- basically attr_accessor with default values, light-weight casting, and a constructor
http://valuable.mustmodify.com/
MIT License
72 stars 3 forks source link

has_collection doesn't accept a default value #30

Closed mustmodify closed 4 years ago

mustmodify commented 5 years ago
class RoutingService
  has_value :message_routes, default -> {MessageRoute.all}
end

>> RoutingService.new.message_routes
=> []
mustmodify commented 4 years ago

Seems to be working...

$: << File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'test/unit'
require 'valuable.rb'
require 'mocha/setup'

class Album < Valuable
  has_collection :concepts, default: -> {['a', 'b', 'c']}
end

class BaseTest < Test::Unit::TestCase
  def test_that_collection_can_have_a_default_value
    album = Album.new
    assert_equal ['a', 'b', 'c'], album.concepts
  end
end