test/skip_getter_test.rb in disposable-0.1.1 vs test/skip_getter_test.rb in disposable-0.1.2

- old
+ new

@@ -32,6 +32,90 @@ twin.sync # does NOT call getter. album.title.must_equal "Wild Frontier" album.artist.name.must_equal "Gary Moore" end +end + + +class SkipSetterTest < MiniTest::Spec + Album = Struct.new(:title, :artist) + Artist = Struct.new(:name) + + class AlbumTwin < Disposable::Twin + feature Setup::SkipSetter + + property :title + property :artist do + property :name + + def name=(v) + super(v.upcase) + end + end + + def title=(v) + super(v.reverse) + end + end + + it do + twin = AlbumTwin.new(Album.new("Wild Frontier", Artist.new("Gary Moore"))) + + twin.title.must_equal "Wild Frontier" + twin.artist.name.must_equal "Gary Moore" + end +end + + +class SkipGetterAndSetterWithChangedTest < MiniTest::Spec + Album = Struct.new(:title, :artist) + Artist = Struct.new(:name) + + class AlbumTwin < Disposable::Twin + feature Sync + feature Sync::SkipGetter + feature Setup::SkipSetter + feature Changed + + property :title + property :artist do + property :name + + def name + super.upcase + end + + def name=(v) + super v.chop + end + end + + def title + super.reverse + end + + def title=(v) + super v.reverse + end + end + + it do + album = Album.new("Wild Frontier", Artist.new("Gary Moore")) + twin = AlbumTwin.new(album) # does not call getter (Changed). + + + twin.title.must_equal "reitnorF dliW" + twin.artist.name.must_equal "GARY MOORE" + + twin.changed?.must_equal false + twin.artist.changed?.must_equal false + + twin.title = "Self-Entitled" + twin.artist.name = "Nofx" + + twin.sync # does NOT call getter. + + album.title.must_equal "deltitnE-fleS" + album.artist.name.must_equal "Nof" + end end \ No newline at end of file