Skip to content

Commit

Permalink
Merge pull request #1204 from samvera/harmonize_noid_testing
Browse files Browse the repository at this point in the history
Combine noid tests
  • Loading branch information
dazza-codes authored Jun 12, 2017
2 parents 7816e4c + 0400ddd commit 0b82da5
Showing 1 changed file with 33 additions and 40 deletions.
73 changes: 33 additions & 40 deletions spec/models/file_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,34 +221,50 @@ class AltFile < ActiveFedora::Base

describe 'noid integration', :clean_repo do
let(:service) { instance_double(ActiveFedora::Noid::Service, mint: noid) }
let(:noid) { 'wd3763094' }
let!(:default) { Hyrax.config.enable_noids? }

before do
allow(ActiveFedora::Noid::Service).to receive(:new).and_return(service)
end

let(:noid) { 'wd3763094' }
after { Hyrax.config.enable_noids = default }

subject do
described_class.create { |f| f.apply_depositor_metadata('mjg36') }
end
context 'with noids enabled' do
before { Hyrax.config.enable_noids = true }

it 'runs the overridden #assign_id method' do
expect(service).to receive(:mint).once
described_class.create { |f| f.apply_depositor_metadata('mjg36') }
end
it 'uses the noid service' do
expect(service).to receive(:mint).once
subject.assign_id
end

it 'returns the expected identifier' do
expect(subject.id).to eq noid
end
context "after saving" do
before { subject.save! }

it "has a treeified URL" do
expect(subject.uri.to_s).to end_with '/wd/37/63/09/wd3763094'
it 'returns the expected identifier' do
expect(subject.id).to eq noid
end

it "has a treeified URL" do
expect(subject.uri.to_s).to end_with '/wd/37/63/09/wd3763094'
end
end

context 'when a url is provided' do
let(:url) { "#{ActiveFedora.fedora.host}/test/wd/37/63/09/wd3763094" }

it 'transforms the url into an id' do
expect(described_class.uri_to_id(url)).to eq 'wd3763094'
end
end
end

context 'when a url is provided' do
let(:url) { "#{ActiveFedora.fedora.host}/test/wd/37/63/09/wd3763094" }
context 'with noids disabled' do
before { Hyrax.config.enable_noids = false }

it 'transforms the url into an id' do
expect(described_class.uri_to_id(url)).to eq 'wd3763094'
it 'does not use the noid service' do
expect(service).not_to receive(:mint)
subject.assign_id
end
end
end
Expand Down Expand Up @@ -500,29 +516,6 @@ def paranoid_edit_permissions
end
end

describe 'assign_id' do
let(:service) { instance_double(ActiveFedora::Noid::Service) }
before do
allow(ActiveFedora::Noid::Service).to receive(:new).and_return(service)
end
context 'with noids enabled (by default)' do
it 'uses the noid service' do
expect(service).to receive(:mint).once
subject.assign_id
end
end

context 'with noids disabled' do
before { Hyrax.config.enable_noids = false }
after { Hyrax.config.enable_noids = true }

it 'does not use the noid service' do
expect(service).not_to receive(:mint)
subject.assign_id
end
end
end

describe 'with a parent work' do
let(:parent) { create(:work_with_one_file) }
let(:parent_id) { parent.id }
Expand Down

0 comments on commit 0b82da5

Please sign in to comment.