Sha256: 54771a126b2476a345d0179e6168f178627c21920a8879e725515968a200b3a0

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe ISO3166 do
  context 'validation' do
    let(:iso_3166) {ISO3166.new}
    let(:iso_records) { mock(:values_for => ['US']) }
    before { ISORecords.stub(:new => iso_records) }

    context 'on default field' do
      it 'gets a list of values' do
        iso_records.should_receive(:values_for).with(:code)
        iso_3166.validate('US')
      end
    end

    context 'on country field' do
      it 'gets a list of values' do
        iso_records.should_receive(:values_for).with(:country)
        iso_3166.validate('2345', :country)
      end
    end

    context 'on multiple fields' do
      it 'gets a list of values' do
        iso_records.should_receive(:values_for).with([:code, :country])
        iso_3166.validate('1234', [:code, :country])
      end
    end

    context 'returns true if the value is valid' do
      it 'with matching case' do
        iso_3166.validate('us').should be_true
      end

      it 'with different case' do
        iso_3166.validate('US').should be_true
      end
    end

    it 'returns false if the value is invalid' do
      iso_records.stub(:values_for => [])
      iso_3166.validate('BLABLA').should be_false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
divISOr-0.0.1 spec/divISOr/iso3166_spec.rb