diff --git a/app/controllers/objects_controller.rb b/app/controllers/objects_controller.rb
index 314799911e..10c517905e 100644
--- a/app/controllers/objects_controller.rb
+++ b/app/controllers/objects_controller.rb
@@ -57,6 +57,8 @@ def update_marc_record
def notify_goobi
response = Dor::Goobi.new(@item).register
proxy_rest_client_response(response)
+ rescue RestClient::Conflict => e
+ render status: 409, plain: e.http_body
end
# You can post a release tag as JSON in the body to add a release tag to an item.
diff --git a/config/settings.yml b/config/settings.yml
index 35a17dac2e..a16deeaa9e 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -87,7 +87,7 @@ RELEASE:
PURL_BASE_URI : 'http://purl.stanford.edu'
GOOBI:
- URL: 'http://localhost:9292'
+ URL: 'http://goobi-env.stanford.edu:9292'
DPG_WORKFLOW_NAME: 'goobiWF'
DEFAULT_GOOBI_WORKFLOW_NAME: 'Example_Workflow'
MAX_TRIES: 3
diff --git a/spec/controllers/objects_controller_spec.rb b/spec/controllers/objects_controller_spec.rb
index 223937f830..5a5601e064 100644
--- a/spec/controllers/objects_controller_spec.rb
+++ b/spec/controllers/objects_controller_spec.rb
@@ -108,14 +108,41 @@
end
describe '/notify_goobi' do
- it 'notifies goobi of a new registration by making a web service call' do
- fake_request = "#{item.pid}"
- stub_request(:post, Dor::Config.goobi.url).to_return(body: fake_request, headers: { 'Content-Type' => 'application/xml' }, status: 201)
- allow_any_instance_of(Dor::Goobi).to receive(:xml_request).and_return(fake_request)
- fake_response = double(RestClient::Response, headers: { content_type: 'text/xml' }, code: 201, body: '')
- expect_any_instance_of(Dor::Goobi).to receive(:register).once.and_return(fake_response)
- post :notify_goobi, params: { id: item.pid }
- expect(response.status).to eq(201)
+ let(:fake_request) { "#{item.pid}" }
+
+ before do
+ allow_any_instance_of(Dor::Goobi).to receive(:xml_request).and_return fake_request
+ end
+
+ context 'when it is successful' do
+ before do
+ stub_request(:post, Dor::Config.goobi.url)
+ .to_return(body: fake_request,
+ headers: { 'Content-Type' => 'application/xml' },
+ status: 201)
+ end
+
+ it 'notifies goobi of a new registration by making a web service call' do
+ post :notify_goobi, params: { id: item.pid }
+ expect(response.status).to eq(201)
+ end
+ end
+
+ context 'when it is a conflict' do
+ before do
+ stub_request(:post, Dor::Config.goobi.url)
+ .to_return(body: 'conflict',
+ status: 409)
+
+ # This just speeds up the test by avoiding retries
+ allow_any_instance_of(Dor::Goobi).to receive(:with_retries).and_yield(nil)
+ end
+
+ it 'returns the conflict code' do
+ post :notify_goobi, params: { id: item.pid }
+ expect(response.status).to eq(409)
+ expect(response.body).to eq('conflict')
+ end
end
end