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