Sha256: 0a2b7bb6b630dc4538647f937ff5776f663ef2d4abfdb744db3b0fa34fc29e24

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

require 'spec_helper'

describe ProvinceValidator do
  class Validatable
    include ActiveModel::Validations
    include ActiveModel::Model
    attr_accessor :country, :province

    validates :province, province: { country: :country }
  end

  subject { Validatable.new({ country: country, province: province }) }

  context 'province is in selected country as a string' do
    let(:country) { 'canada' }
    let(:province) { 'Alberta' }

    it 'is valid' do
      expect(subject).to be_valid
    end
  end

  context 'province is in selected country' do
    let(:country) { :canada }
    let(:province) { 'Alberta' }

    it 'is valid' do
      expect(subject).to be_valid
    end
  end

  context 'province is not in selected country' do
    let(:country) { :canada }
    let(:province) { 'Alabama' }

    it 'is not valid' do
      expect(subject).to_not be_valid
      expect(subject.errors[:province]).to_not be_empty
    end
  end

  context 'province is blank' do
    let(:country) { :canada }
    let(:province) { '' }

    it 'is not valid' do
      expect(subject).to_not be_valid
      expect(subject.errors[:province]).to_not be_empty
    end
  end

  context 'province is nil' do
    let(:country) { :canada }
    let(:province) { nil }

    it 'is not valid' do
      expect(subject).to_not be_valid
      expect(subject.errors[:province]).to_not be_empty
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ama_validators-0.0.7 spec/province_validator_spec.rb