Sha256: 1d40dd03737d7480b5917a07cf705df513b915f440a98a5d11ec161e0102bb8f

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

require "test_helper"

class InheritanceTest < Minitest::Spec
  let (:song) { OpenStruct.new(id: 0) }

  module Id
    def id
      super - 1
    end

    def id=(v)
      super(v+1)
    end
  end

  class Twin < Disposable::Twin
    property :id
    include Id
  end

  it do
    twin = Twin.new(song)
    expect(twin.id).must_equal 0
  end

  class TwinComposition < Disposable::Twin
    include Composition

    property :id, on: :song
    include Id
  end

  it do
    twin = TwinComposition.new(song: song)
    expect(twin.id).must_equal 0
    twin.id= 3
    expect(twin.id).must_equal 3
  end


  class TwinCompositionDefineMethod < Disposable::Twin
    include Composition

    property :id, on: :song

    define_method :id do
      super() + 9
    end
  end

  it do
    twin = TwinCompositionDefineMethod.new(song: song)
    expect(twin.id).must_equal 9
  end


  describe ":from" do
    let (:song) { Struct.new(:ident).new(1) }

    class TwinWithFrom < Disposable::Twin
      include Expose
      property :id, from: :ident
    end

    class InheritingFrom < TwinWithFrom
    end

    it do
      expect(TwinWithFrom.new(song).id).must_equal 1
      expect(InheritingFrom.new(song).id).must_equal 1
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

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