Sha256: a34e025cf1b3c3881e30411d142e248a204e5372b3992d4cb4ada37d529cad43

Contents?: true

Size: 621 Bytes

Versions: 8

Compression:

Stored size: 621 Bytes

Contents

require "test_helper"

class PopulatorSkipTest < MiniTest::Spec
  Album = Struct.new(:songs)
  Song  = Struct.new(:title)


  class AlbumForm < Reform::Form
    collection :songs,
      populator: ->(options) {
        return skip! if options[:fragment][:title] == "Good"
        songs[options[:index]]
      } do
        property :title
    end
  end

  it do
    form = AlbumForm.new(Album.new([Song.new, Song.new]))
    hash = {songs: [{title: "Good"}, {title: "Bad"}]}

    form.validate(hash)

    form.songs.size.must_equal 2
    form.songs[0].title.must_equal nil
    form.songs[1].title.must_equal "Bad"
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
reform-2.2.4 test/populator_skip_test.rb
reform-2.2.3 test/populator_skip_test.rb
reform-2.2.2 test/populator_skip_test.rb
reform-2.2.1 test/populator_skip_test.rb
reform-2.2.0 test/populator_skip_test.rb
reform-2.2.0.rc1 test/populator_skip_test.rb
reform-2.1.0 test/populator_skip_test.rb
reform-2.1.0.rc1 test/populator_skip_test.rb