Sha256: d6fc663a40c11c82fe2e9f2dfa673ea1861909c45bf2d92ef93901015524a32a

Contents?: true

Size: 769 Bytes

Versions: 2

Compression:

Stored size: 769 Bytes

Contents

require "test_helper"
require "disposable/twin/coercion"
require "disposable/twin/property/struct"

class StructCoercionTest < Minitest::Spec
  ExpenseModel = Struct.new(:content)

  class Expense < Disposable::Twin
    feature Property::Struct
    feature Coercion

    property :content do
      property :amount, type: DRY_TYPES_CONSTANT::Float
    end

    unnest :amount, from: :content
  end


  it do
    twin = Expense.new( ExpenseModel.new({}) )

    #- direct access, without unnest
    twin.content.amount.must_be_nil
    twin.content.amount = "1.8"
    twin.content.amount.must_equal 1.8
  end

  it "via unnest" do
    twin = Expense.new( ExpenseModel.new({}) )

    twin.amount.must_be_nil
    twin.amount = "1.8"
    twin.amount.must_equal 1.8
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
disposable-0.4.5 test/twin/struct/coercion_test.rb
disposable-0.4.4 test/twin/struct/coercion_test.rb