Sha256: 6fe25d71fbf47ad8943ccea585a410b898e29aa1215720c2adf99c64d26e68b9

Contents?: true

Size: 987 Bytes

Versions: 10

Compression:

Stored size: 987 Bytes

Contents

require "test_helper"
require "disposable/twin/parent.rb"

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

  class Album < Disposable::Twin
    feature Parent

    property :id

    property :artist do
      property :name
    end

    collection :songs do
      property :title
      property :composer do
        property :name
      end
    end
  end

  let (:album) { Album.new(Model::Album.new(1, Model::Artist.new("Helloween"), [Model::Song.new("I'm Alive", Model::Artist.new("Kai Hansen"))])) }

  it { album.parent.must_equal nil }
  it { album.artist.parent.must_equal album }
  it { album.songs[0].parent.must_equal album }
  it { album.songs[0].composer.parent.must_equal album.songs[0] }

  describe "Collection#append" do
    it do
      album.songs.append(song = Model::Song.new)
      album.songs[1].parent.must_equal album
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
disposable-0.4.3 test/twin/parent_test.rb
disposable-0.4.2 test/twin/parent_test.rb
disposable-0.4.1 test/twin/parent_test.rb
disposable-0.4.0 test/twin/parent_test.rb
disposable-0.3.2 test/twin/parent_test.rb
disposable-0.3.1 test/twin/parent_test.rb
disposable-0.3.0 test/twin/parent_test.rb
disposable-0.2.6 test/twin/parent_test.rb
disposable-0.2.5 test/twin/parent_test.rb
disposable-0.2.4 test/twin/parent_test.rb