Sha256: 7fa70a1b441c4fccf4928811d0af655f1ba88cef5c640c17a071769e5161de2f

Contents?: true

Size: 1.88 KB

Versions: 15

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true

require 'spec_helper'
require File.expand_path('../lib/countries/mongoid', __dir__)

describe 'Mongoid support' do
  let(:britain) { ISO3166::Country.new('GB') }
  context 'instance methods' do
    describe 'mongoize' do
      it 'should delegate mongoization to the class method' do
        expect(britain.mongoize).to eql ISO3166::Country.mongoize(britain)
      end
    end
  end

  context 'class methods' do
    describe 'mongoize' do
      it 'should store the alpha2 given a country object' do
        expect(ISO3166::Country.mongoize(britain)).to eql britain.alpha2
      end

      it 'should store the alpha2 given a valid alpha2' do
        expect(ISO3166::Country.mongoize('GB')).to eql britain.alpha2
      end

      it 'should store nil given an invalid object' do
        bad_types = [[], Time.now.utc, {}, Date.new(2029, 10, 1)]
        bad_types.each do |type|
          expect(ISO3166::Country.mongoize(type)).to eql nil
        end
      end

      it 'should store nil given an empty country object' do
        expect(ISO3166::Country.mongoize(ISO3166::Country.new(''))).to eql nil
      end

      it 'should store nil given a bad alpha2' do
        expect(ISO3166::Country.mongoize('bad_alpha_2')).to eql nil
      end
    end

    describe 'demongoize' do
      it 'should instantiate an equivalent object from stored alpha2 code' do
        expect(ISO3166::Country.demongoize(britain.mongoize).data)
          .to eql britain.data
      end

      it 'should be indifferent to storage by alpha2' do
        expect(ISO3166::Country.demongoize(ISO3166::Country.mongoize('GB'))
        .data).to eql britain.data
      end
    end

    describe 'evolve' do
      it 'should delegate to self.mongoize and return the mongoized object' do
        expect(ISO3166::Country).to receive(:mongoize).with(britain)
        ISO3166::Country.evolve(britain)
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
countries-5.7.0 spec/mongoid_spec.rb
countries-5.6.0 spec/mongoid_spec.rb
countries-5.5.0 spec/mongoid_spec.rb
countries-5.4.0 spec/mongoid_spec.rb
countries-5.3.2 spec/mongoid_spec.rb
countries-5.3.1 spec/mongoid_spec.rb
countries-5.3.0 spec/mongoid_spec.rb
countries-5.2.1 spec/mongoid_spec.rb
countries-5.2.0 spec/mongoid_spec.rb
countries-5.1.2 spec/mongoid_spec.rb
countries-5.1.1 spec/mongoid_spec.rb
countries-5.1.0 spec/mongoid_spec.rb
countries-5.0.2 spec/mongoid_spec.rb
countries-5.0.1 spec/mongoid_spec.rb
countries-5.0.0 spec/mongoid_spec.rb