Sha256: 19779a870e2eb4e0a01906db4e535195bf6799c959fd191ac17bcda99d97a678

Contents?: true

Size: 1.52 KB

Versions: 5

Compression:

Stored size: 1.52 KB

Contents

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

describe Pupa::Concerns::Identifiable do
  let :klass do
    Class.new do
      include Pupa::Model
      include Pupa::Concerns::Identifiable
    end
  end

  let :object do
    klass.new
  end

  describe '#initialize' do
    it 'should initialize an empty IdentifierList' do
      expect(object.identifiers).to be_a(Pupa::IdentifierList)
      expect(object.identifiers).to eq([])
    end

    it 'should initialize the given IdentifierList' do
      object = klass.new(identifiers: [{identifier: '123456789', scheme: 'DUNS'}])
      expect(object.identifiers).to eq([{identifier: '123456789', scheme: 'DUNS'}])
    end
  end

  describe '#identifiers=' do
    it 'should use coerce to a IdentifierList' do
      object.identifiers = [{identifier: '123456789', scheme: 'DUNS'}]
      expect(object.identifiers).to be_a(Pupa::IdentifierList)
    end

    it 'should symbolize keys' do
      object.identifiers = [{'identifier' => '123456789', 'scheme' => 'DUNS'}]
      expect(object.identifiers).to eq([{identifier: '123456789', scheme: 'DUNS'}])
    end
  end

  describe '#add_identifier' do
    it 'should add an identifier' do
      object.add_identifier('123456789', scheme: 'duns')
      expect(object.identifiers).to eq([{identifier: '123456789', scheme: 'duns'}])
    end

    it 'should not add an identifier without an identifier' do
      object.add_identifier(nil)
      object.add_identifier('')
      expect(object.identifiers.blank?).to eq(true)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pupa-0.2.4 spec/models/concerns/identifiable_spec.rb
pupa-0.2.3 spec/models/concerns/identifiable_spec.rb
pupa-0.2.2 spec/models/concerns/identifiable_spec.rb
pupa-0.2.1 spec/models/concerns/identifiable_spec.rb
pupa-0.2.0 spec/models/concerns/identifiable_spec.rb