Sha256: 5b70f4702796a958dddfc25239e86e0a1e83407caf2cef8bfef05091d3fe414b

Contents?: true

Size: 827 Bytes

Versions: 6

Compression:

Stored size: 827 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 | DRY_TYPES_CONSTANT::Nil
    end

    unnest :amount, from: :content
  end


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

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

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

    expect(twin.amount).must_be_nil
    twin.amount = "1.8"
    expect(twin.amount).must_equal 1.8
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
disposable-0.6.3 test/twin/struct/coercion_test.rb
disposable-0.6.2 test/twin/struct/coercion_test.rb
disposable-0.6.1 test/twin/struct/coercion_test.rb
disposable-0.6.0 test/twin/struct/coercion_test.rb
disposable-0.5.0 test/twin/struct/coercion_test.rb
disposable-0.4.7 test/twin/struct/coercion_test.rb