Sha256: 8ea0b301e8866eb1322d0804e3e82e84916269536bf1b93a95ea142166e7fc1d

Contents?: true

Size: 1.52 KB

Versions: 5

Compression:

Stored size: 1.52 KB

Contents

require "test_helper"

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


  module Twin
    class Album < Disposable::Twin
      feature Setup
      feature Sync
      feature Sync::SkipUnchanged

      property :name

      collection :songs do
        property :title

        property :composer do
          property :name
        end
      end

      property :artist do
        property :name
      end
    end
  end


  let (:song) { Model::Song.new() }
  let (:composer) { Model::Artist.new(nil) }
  let (:song_with_composer) { Model::Song.new("American Jesus", composer) }
  let (:artist) { Model::Artist.new("Bad Religion") }


  let (:album) { Model::Album.new("30 Years Live", [song, song_with_composer], artist) }

  it do
    twin = Twin::Album.new(album)

    twin.songs[1].composer.name = "Greg Graffin"
    twin.songs[0].title = "Resist Stance"

    # raises exceptions when setters are called.
    album.instance_eval { def name=; end }
    artist.instance_eval { def name=; end }
    song_with_composer.instance_eval { def title=; end }

    twin.sync

    # unchanged, and no exception raised.
    album.name.must_equal "30 Years Live"
    song_with_composer.title.must_equal "American Jesus"
    artist.name.must_equal "Bad Religion"

    # this actually got synced.
    song_with_composer.composer.name.must_equal "Greg Graffin" # was nil.
    song.title.must_equal "Resist Stance" # was nil.
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
disposable-0.1.4 test/twin/skip_unchanged_test.rb
disposable-0.1.3 test/twin/skip_unchanged_test.rb
disposable-0.1.2 test/twin/skip_unchanged_test.rb
disposable-0.1.1 test/twin/skip_unchanged_test.rb
disposable-0.1.0 test/twin/skip_unchanged_test.rb