Sha256: c06b4a51463b1953ba67dba665d5e0dd667f24517b27ad6a9c08625fcd05e585

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

require "test_helper"

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

  class AlbumForm < TestForm
    property :name
    collection :songs do
      property :title

      property :composer do
        property :name
      end
    end

    property :artist do
      property :name
    end
  end

  let(:song)               { Song.new("Broken") }
  let(:song_with_composer) { Song.new("Resist Stance", nil, composer) }
  let(:composer)           { Artist.new("Greg Graffin") }
  let(:artist)             { Artist.new("Bad Religion") }

  describe "with nested objects" do
    let(:album) { Album.new("The Dissent Of Man", [song, song_with_composer], artist) }

    it do
      form = AlbumForm.new(album)

      form.name.must_equal "The Dissent Of Man"
      form.songs[0].title.must_equal "Broken"
      assert_nil form.songs[0].composer
      form.songs[1].title.must_equal "Resist Stance"
      form.songs[1].composer.name.must_equal "Greg Graffin"
      form.artist.name.must_equal "Bad Religion"

      # make sure all is wrapped in forms.
      form.songs[0].must_be_kind_of Reform::Form
      form.songs[1].must_be_kind_of Reform::Form
      form.songs[1].composer.must_be_kind_of Reform::Form
      form.artist.must_be_kind_of Reform::Form
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reform-2.3.2 test/setup_test.rb
reform-2.3.1 test/setup_test.rb
reform-2.3.0.rc2 test/setup_test.rb