Sha256: 1bfb94708b4abc57effebb493cee43a99dd590dd783b6f3fdf06b80097591edd

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'

describe ::User, 'ActiveModel::Validations::DateValidator' do

  shared_examples_for 'should not allow invalid dates' do |
    attr_name: nil,
    message: "is not a valid date (must be in yyyy-mm-dd format)"
  |
    it { should_not allow_value('non-date').  for(attr_name).with_message(message) }
    it { should     allow_value('2013-01-01').for(attr_name) }
    it { should     allow_value('30/12/2013').for(attr_name) }
  end

  describe 'date: true' do
    it { should     allow_value(nil).for(:optional_date) }
    it { should     allow_value(''). for(:optional_date) }
    it_behaves_like 'should not allow invalid dates', attr_name: :optional_date
  end

  describe "date: {expected_format: 'dd/mm/yyyy'}" do
    it { should     allow_value(nil).for(:custom_format_date) }
    it { should     allow_value(''). for(:custom_format_date) }
    it_behaves_like 'should not allow invalid dates', attr_name: :custom_format_date,
      message: "is not a valid date (must be in dd/mm/yyyy format)"
  end

  describe 'date: {required: true}' do
    it { should_not allow_value(nil).for(:end_date).with_message("can't be blank") }
    it { should_not allow_value(''). for(:end_date).with_message("can't be blank") }
    it_behaves_like 'should not allow invalid dates', attr_name: :end_date
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activemodel-validators-3.0.1 spec/date_validator_spec.rb
activemodel-validators-3.0.0 spec/date_validator_spec.rb
activemodel-validators-2.0.0 spec/date_validator_spec.rb
activemodel-validators-1.2.0 spec/date_validator_spec.rb
activemodel-validators-1.1.0 spec/date_validator_spec.rb