Sha256: cb0d20699cee083d24d674e737a97af7b3c6351f16f271aa530d6c756a035c0d
Contents?: true
Size: 1.56 KB
Versions: 2
Compression:
Stored size: 1.56 KB
Contents
require 'spec_helper' describe Hydra::Validations::FormatValidator do before(:all) do class Validatable include ActiveModel::Validations include Hydra::Validations attr_accessor :field validates :field, format: { with: /\A[[:alpha:]]+\Z/ } end end after(:all) { Object.send(:remove_const, :Validatable) } before(:each) { allow(record).to receive(:field) { value } } let(:record) { Validatable.new } describe "when the value is a scalar" do describe "which matches the format" do let(:value) { "foo" } it "should be valid" do expect(record).to be_valid end end describe "which does not match the format" do let(:value) { "foo1" } it "should be invalid" do expect(record).to be_invalid end it "should have the standard error message" do record.valid? # TODO i18n expect(record.errors[:field]).to eq ["is invalid"] end end end describe "when the value is an enumerable" do describe "and all value members match the format" do let(:value) { ["foo", "bar"] } it "should be valid" do expect(record).to be_valid end end describe "and one value member does not match the format" do let(:value) { ["foo1", "bar"] } it "should be invalid" do expect(record).to be_invalid end it "should 'fix' the error message to include the value" do record.valid? # TODO i18n expect(record.errors[:field]).to eq ["value \"foo1\" is invalid"] end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hydra-validations-0.5.0 | spec/validations/format_validator_spec.rb |
hydra-validations-0.4.0 | spec/validations/format_validator_spec.rb |