Sha256: 4b65b532a8ea967f59793bcf9e67828ddeea1d1693da901c68078f037c5c47c0

Contents?: true

Size: 1.52 KB

Versions: 8

Compression:

Stored size: 1.52 KB

Contents

require "test_helper"

class InheritTest < MiniTest::Spec
  module Model
    Song  = Struct.new(:title, :album)
    Album = Struct.new(:name, :songs, :artist)
    Artist = Struct.new(:name)
  end

  module Twin
    class Album < Disposable::Twin
      feature Setup

      property :name, fromage: :_name

      collection :songs do
        property :name
      end

      property :artist do
        property :name

        def artist_id
          1
        end
      end
    end

    class EmptyCompilation < Album
    end

    class Compilation < Album
      property :name, writeable: false, inherit: true

      property :artist, inherit: true do

      end
    end
  end

  # definitions are not shared.
  it do
    Twin::Album.definitions.get(:name).extend(Declarative::Inspect).inspect.must_equal "#<Disposable::Twin::Definition: @options={:fromage=>:_name, :private_name=>:name, :name=>\"name\"}>"
    Twin::Compilation.definitions.get(:name).extend(Declarative::Inspect).inspect.must_equal "#<Disposable::Twin::Definition: @options={:fromage=>:_name, :private_name=>:name, :name=>\"name\", :writeable=>false}>" # FIXME: where did :inherit go?
  end


  let (:album) { Model::Album.new("In The Meantime And Inbetween Time", [], Model::Artist.new) }

  it { Twin::Album.new(album).artist.artist_id.must_equal 1 }

  # inherit inline twins when not overriding.
  it { Twin::EmptyCompilation.new(album).artist.artist_id.must_equal 1 }

  # inherit inline twins when overriding.
  it { Twin::Compilation.new(album).artist.artist_id.must_equal 1 }
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
disposable-0.2.5 test/twin/inherit_test.rb
disposable-0.2.4 test/twin/inherit_test.rb
disposable-0.2.3 test/twin/inherit_test.rb
disposable-0.2.2 test/twin/inherit_test.rb
disposable-0.2.1 test/twin/inherit_test.rb
disposable-0.2.0 test/twin/inherit_test.rb
disposable-0.2.0.rc2 test/twin/inherit_test.rb
disposable-0.2.0.rc1 test/twin/inherit_test.rb