Sha256: 28e20af5188708da714dc5599d86ca49c857503a9f9a9066a1d30b9ecf7470af

Contents?: true

Size: 749 Bytes

Versions: 2

Compression:

Stored size: 749 Bytes

Contents

require "test_helper"

class BuilderTest < MiniTest::Spec
  module Model
    Song = Struct.new(:id, :title)
    Hit = Struct.new(:id, :title)
    Evergreen = Struct.new(:id, :title)
  end

  class Twin < Disposable::Twin
    property :id
    property :title
    # option   :is_released

    include Builder
    builds ->(model, options) do
      return Hit       if model.is_a? Model::Hit
      return Evergreen if options[:evergreen]
    end
  end

  class Hit < Twin
  end

  class Evergreen < Twin
  end


  it { expect(Twin.build(Model::Song.new)).must_be_instance_of Twin }
  it { expect(Twin.build(Model::Hit.new)).must_be_instance_of  Hit }
  it { expect(Twin.build(Model::Evergreen.new, evergreen: true)).must_be_instance_of Evergreen }
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
disposable-0.5.0 test/twin/builder_test.rb
disposable-0.4.7 test/twin/builder_test.rb