Sha256: f387fb8ec903f50b2191b5e6f1f7f7b5219b9365da0aee348ff4893efcb60539

Contents?: true

Size: 1.16 KB

Versions: 11

Compression:

Stored size: 1.16 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)
    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)
    twin.id.must_equal 0
    twin.id= 3
    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)
    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
      TwinWithFrom.new(song).id.must_equal 1
      InheritingFrom.new(song).id.must_equal 1
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
disposable-0.4.6 test/twin/inheritance_test.rb
disposable-0.4.5 test/twin/inheritance_test.rb
disposable-0.4.4 test/twin/inheritance_test.rb
disposable-0.4.3 test/twin/inheritance_test.rb
disposable-0.4.2 test/twin/inheritance_test.rb
disposable-0.4.1 test/twin/inheritance_test.rb
disposable-0.4.0 test/twin/inheritance_test.rb
disposable-0.3.2 test/twin/inheritance_test.rb
disposable-0.3.1 test/twin/inheritance_test.rb
disposable-0.3.0 test/twin/inheritance_test.rb
disposable-0.2.6 test/twin/inheritance_test.rb