Sha256: 8bd37a3ebe97facc0e1730bfdbd767102b689fb25acfd8300b8245ce437c1d4a

Contents?: true

Size: 988 Bytes

Versions: 7

Compression:

Stored size: 988 Bytes

Contents

require "test_helper"

require "reform/form/validation/unique_validator.rb"

class UniquenessValidatorOnCreateTest < MiniTest::Spec
  class SongForm < Reform::Form
    property :title
    validates :title, unique: true
  end

  it do
    Song.delete_all

    form = SongForm.new(Song.new)
    form.validate("title" => "How Many Tears").must_equal true
    form.save

    form = SongForm.new(Song.new)
    form.validate("title" => "How Many Tears").must_equal false
    form.errors.to_s.must_equal "{:title=>[\"title must be unique.\"]}"
  end
end

class UniquenessValidatorOnUpdateTest < MiniTest::Spec
  class SongForm < Reform::Form
    property :title
    validates :title, unique: true
  end

  it do
    Song.delete_all
    @song = Song.create(title: "How Many Tears")

    form = SongForm.new(@song)
    form.validate("title" => "How Many Tears").must_equal true
    form.save

    form = SongForm.new(@song)
    form.validate("title" => "How Many Tears").must_equal true
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
reform-2.0.1 test/unique_test.rb
reform-2.0.0 test/unique_test.rb
reform-2.0.0.rc3 test/unique_test.rb
reform-2.0.0.rc2 test/unique_test.rb
reform-2.0.0.rc1 test/uniqueness_test.rb
reform-2.0.0.beta2 test/uniqueness_test.rb
reform-2.0.0.beta1 test/uniqueness_test.rb