Sha256: 41dc844e6ee026dd70928f0330d28e41a05bc24e37f34cc48566ca3da69aa1d2

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true
shared_examples 'a minter' do
  describe '#mint' do
    subject     { minter.mint }
    let(:other) { described_class.new('.reedddk') }

    it { is_expected.not_to be_empty }

    it 'does not mint the same ID twice in a row' do
      expect(subject).not_to eq described_class.new.mint
    end

    it 'is valid' do
      expect(minter.valid?(subject)).to be true
      expect(described_class.new.valid?(subject)).to be true
    end

    it 'is invalid under a different template' do
      expect(described_class.new('.reedddk').valid?(subject)).to be false
    end

    it 'is invalid under a different template' do
      expect(other).not_to be_valid(minter.mint)
    end
  end

  context 'conflicts' do
    let(:existing_pid) { 'ef12ef12f' }
    let(:unique_pid)   { 'bb22bb22b' }

    before do
      expect(subject).to receive(:next_id).and_return(existing_pid, unique_pid)
    end

    context 'when the pid already exists in Fedora' do
      before do
        expect(ActiveFedora::Base).to receive(:exists?).with(existing_pid).and_return(true)
      end
      it 'skips the existing pid' do
        expect(subject.mint).to eq unique_pid
      end
    end

    context 'when the pid already existed in Fedora and now is gone' do
      let(:gone_pid) { existing_pid }

      before do
        expect(ActiveFedora::Base).to receive(:gone?).with(gone_pid).and_return(true)
      end

      it 'skips the deleted pid' do
        expect(subject.mint).to eq unique_pid
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_fedora-noid-2.0.0 spec/support/shared_examples/minter.rb
active_fedora-noid-2.0.0.beta6 spec/support/shared_examples/minter.rb