Skip to content

Commit

Permalink
Merge 732ff24 into 0ba997c
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed May 16, 2019
2 parents 0ba997c + 732ff24 commit c72d7ef
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
2 changes: 2 additions & 0 deletions app/controllers/objects_controller.rb
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion config/settings.yml
Expand Up @@ -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
Expand Down
43 changes: 35 additions & 8 deletions spec/controllers/objects_controller_spec.rb
Expand Up @@ -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 = "<stanfordCreationRequest><objectId>#{item.pid}</objectId></stanfordCreationRequest>"
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) { "<stanfordCreationRequest><objectId>#{item.pid}</objectId></stanfordCreationRequest>" }

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

Expand Down

0 comments on commit c72d7ef

Please sign in to comment.