Sha256: 2f0b20d57a07637d0df9710446f76165c0dcb205512b7520c29bacf31da904bb

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

require "test_helper"

# Overridden setter won't be called in setup.
# Overridden getter won't be called in sync.
class SetupSkipSetterAndGetterTest < MiniTest::Spec
  Song  = Struct.new(:title, :album, :composer)
  Album = Struct.new(:title, :artist)
  Artist = Struct.new(:name)

  class AlbumForm < TestForm
    property :title

    def title
      super.upcase
    end

    def title=(v)
      super v.reverse
    end

    property :artist do
      property :name

      def name
        super.downcase
      end

      def name=(v)
        super v.chop
      end
    end
  end

  let (:artist) { Artist.new("Bad Religion") }


  it do
    album = Album.new("Greatest Hits", artist)
    form  = AlbumForm.new(album)

    form.title.must_equal "GREATEST HITS"
    form.artist.name.must_equal "bad religion"

    form.validate("title" => "Resiststance", "artist" => {"name" => "Greg Graffin"})

    form.title.must_equal "ECNATSTSISER" # first, setter called, then getter.
    form.artist.name.must_equal "greg graffi"

    form.sync

    album.title.must_equal "ecnatstsiseR" # setter called, but not getter.
    album.artist.name.must_equal "Greg Graffi"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reform-2.3.0.rc1 test/skip_setter_and_getter_test.rb