Sha256: 0c577383fa6f2bb24e975de2338a62eaf0d46b461038b86803419af9e8150da8

Contents?: true

Size: 1.29 KB

Versions: 11

Compression:

Stored size: 1.29 KB

Contents

require 'test_helper'

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

  class ArtistForm < Reform::Form
    property :name
  end

  class AlbumForm < Reform::Contract
    property :name
    validates :name, presence: true

    collection :songs do
      property :title
      validates :title, presence: true

      property :composer do
        validates :name, presence: true
        property :name
      end
    end

    property :artist, form: ArtistForm
  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") }
  let (:album)              { Album.new("The Dissent Of Man", [song, song_with_composer], artist) }

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

  # accept `property form: SongForm`.
  it do
    form.artist.must_be_instance_of ArtistForm
  end

  describe "#options_for" do
    it { AlbumForm.options_for(:name).inspect.must_match "#<Representable::Definition ==>name @options" }
    it { AlbumForm.new(album).options_for(:name).inspect.must_match "#<Representable::Definition ==>name @options" }
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
reform-2.0.5 test/contract_test.rb
reform-2.0.4 test/contract_test.rb
reform-2.0.3 test/contract_test.rb
reform-2.0.2 test/contract_test.rb
reform-2.0.1 test/contract_test.rb
reform-2.0.0 test/contract_test.rb
reform-2.0.0.rc3 test/contract_test.rb
reform-2.0.0.rc2 test/contract_test.rb
reform-2.0.0.rc1 test/contract_test.rb
reform-2.0.0.beta2 test/contract_test.rb
reform-2.0.0.beta1 test/contract_test.rb