Sha256: 70431af410fa50eb2cd1a0f571122823ce6c8dcfdee5531d13cbe69ec96f0fc3
Contents?: true
Size: 1.11 KB
Versions: 2
Compression:
Stored size: 1.11 KB
Contents
require 'test_helper' unless ActiveModel::VERSION::MAJOR == 3 and ActiveModel::VERSION::MINOR == 0 class UnexistantTitleValidator < ActiveModel::Validator def validate record if record.title == 'unexistant_song' record.errors.add(:title, 'this title does not exist!') end end end class CustomValidationTest < MiniTest::Spec class Album include ActiveModel::Validations attr_accessor :title, :artist validates_with UnexistantTitleValidator end class AlbumForm < Reform::Form extend ActiveModel::ModelValidations property :title property :artist_name, as: :artist copy_validations_from Album end let(:album) { Album.new } describe 'non-composite form' do let(:album_form) { AlbumForm.new(album) } it 'is not valid when title is unexistant_song' do album_form.validate(artist_name: 'test', title: 'unexistant_song').must_equal false end it 'is valid when title is something existant' do album_form.validate(artist_name: 'test', title: 'test').must_equal true end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
reform-1.2.0.beta2 | test/custom_validation_test.rb |
reform-1.2.0.beta1 | test/custom_validation_test.rb |