Sha256: 4363e656641f8fff66658d480a1521de1280bd51b64a705f744c8af8d70302b6

Contents?: true

Size: 1.11 KB

Versions: 19

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, from: :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

19 entries across 19 versions & 1 rubygems

Version Path
reform-2.1.0 test/custom_validation_test.rb
reform-2.1.0.rc1 test/custom_validation_test.rb
reform-2.0.5 test/custom_validation_test.rb
reform-2.0.4 test/custom_validation_test.rb
reform-2.0.3 test/custom_validation_test.rb
reform-2.0.2 test/custom_validation_test.rb
reform-2.0.1 test/custom_validation_test.rb
reform-2.0.0 test/custom_validation_test.rb
reform-2.0.0.rc3 test/custom_validation_test.rb
reform-2.0.0.rc2 test/custom_validation_test.rb
reform-2.0.0.rc1 test/custom_validation_test.rb
reform-2.0.0.beta2 test/custom_validation_test.rb
reform-2.0.0.beta1 test/custom_validation_test.rb
reform-1.2.6 test/custom_validation_test.rb
reform-1.2.5 test/custom_validation_test.rb
reform-1.2.4 test/custom_validation_test.rb
reform-1.2.3 test/custom_validation_test.rb
reform-1.2.2 test/custom_validation_test.rb
reform-1.2.1 test/custom_validation_test.rb