Sha256: f0dc09ac3ddc4f8d6981d5befdb3fbbf5586c8b0b986ce0294d5d693c28628e3

Contents?: true

Size: 1.16 KB

Versions: 19

Compression:

Stored size: 1.16 KB

Contents

require 'test_helper'
require 'reform/form/coercion'

class ChangedTest < MiniTest::Spec
  Song  = Struct.new(:title, :album, :composer)
  Album = Struct.new(:name, :songs, :artist)
  Artist = Struct.new(:name)

  class AlbumForm < Reform::Form
    property :name

    collection :songs do
      property :title

      property :composer do
        property :name
      end
    end
  end

  let (:song_with_composer) { Song.new("Resist Stance", nil, composer) }
  let (:composer)           { Artist.new("Greg Graffin") }
  let (:album)              { Album.new("The Dissent Of Man", [song_with_composer]) }

  let (:form) { AlbumForm.new(album) }

  # nothing changed after setup.
  it do
    form.changed?(:name).must_equal false
    form.songs[0].changed?(:title).must_equal false
    form.songs[0].composer.changed?(:name).must_equal false
  end

  # after validate, things might have changed.
  it do
    form.validate("name" => "Out Of Bounds", "songs" => [{"composer" => {"name" => "Ingemar Jansson & Mikael Danielsson"}}])
    form.changed?(:name).must_equal true
    form.songs[0].changed?(:title).must_equal false
    form.songs[0].composer.changed?(:name).must_equal true
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
reform-2.2.4 test/changed_test.rb
reform-2.2.3 test/changed_test.rb
reform-2.2.2 test/changed_test.rb
reform-2.2.1 test/changed_test.rb
reform-2.2.0 test/changed_test.rb
reform-2.2.0.rc1 test/changed_test.rb
reform-2.1.0 test/changed_test.rb
reform-2.1.0.rc1 test/changed_test.rb
reform-2.0.5 test/changed_test.rb
reform-2.0.4 test/changed_test.rb
reform-2.0.3 test/changed_test.rb
reform-2.0.2 test/changed_test.rb
reform-2.0.1 test/changed_test.rb
reform-2.0.0 test/changed_test.rb
reform-2.0.0.rc3 test/changed_test.rb
reform-2.0.0.rc2 test/changed_test.rb
reform-2.0.0.rc1 test/changed_test.rb
reform-2.0.0.beta2 test/changed_test.rb
reform-2.0.0.beta1 test/changed_test.rb