Sha256: 1f6613d971bc0265c926af172a8d6337580fc7365146e547289c08f69218c902

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

require 'test_helper'

class ActiveModelCustomValidationTranslationsTest < MiniTest::Spec
  module SongForm
    class WithBlock < Reform::Form
      property :title

      validate do
        errors.add :title, :blank
      end
    end

    class WithLambda < Reform::Form
      property :title

      validate ->{ errors.add :title, :blank }
    end

    class WithMethod < Reform::Form
      property :title

      validate :custom_validation_method
      def custom_validation_method
        errors.add :title, :blank
      end
    end
  end


  it 'translates the error message when custom validation is used with block' do
    form = SongForm::WithBlock.new(Song.new)
    form.validate({})
    form.errors[:title].must_include "can't be blank"
  end

  it 'translates the error message when custom validation is used with lambda' do
    form = SongForm::WithLambda.new(Song.new)
    form.validate({})
    form.errors[:title].must_include "can't be blank"
  end

  it 'translates the error message when custom validation is used with method' do
    form = SongForm::WithMethod.new(Song.new)
    form.validate({})
    form.errors[:title].must_include "can't be blank"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reform-2.0.2 test/active_model_custom_validation_translations_test.rb
reform-2.0.1 test/active_model_custom_validation_translations_test.rb