From bb6105bcbe60e31b74eeaa907a765abc84bed603 Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Wed, 4 Jan 2017 15:56:14 -0800 Subject: [PATCH 1/4] #body_params should fallback to an empty hash --- app/controllers/objects_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/objects_controller.rb b/app/controllers/objects_controller.rb index 0b3e665f4..6704e9345 100644 --- a/app/controllers/objects_controller.rb +++ b/app/controllers/objects_controller.rb @@ -99,13 +99,13 @@ def create_params end def body_params - return {} unless request.body.any? - case request.content_type when 'application/xml', 'text/xml' Hash.from_xml(request.body.read) when 'application/json', 'text/json' JSON.parse(request.body.read) + else + {} end end end From f05341ffd758d0adfb3551425d0631bcfbbfe83e Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Wed, 4 Jan 2017 15:56:59 -0800 Subject: [PATCH 2/4] Update dependencies --- .rubocop_todo.yml | 3 ++ Gemfile.lock | 114 +++++++++++++++++++++++----------------------- 2 files changed, 60 insertions(+), 57 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7b492dc00..a3d361522 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -255,3 +255,6 @@ Style/ZeroLengthPredicate: Bundler/OrderedGems: Enabled: false + +RSpec/MessageSpies: + Enabled: false diff --git a/Gemfile.lock b/Gemfile.lock index 499eb34d6..fc9ca0ff5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,25 +1,25 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.0.0.1) - actionpack (= 5.0.0.1) + actioncable (5.0.1) + actionpack (= 5.0.1) nio4r (~> 1.2) websocket-driver (~> 0.6.1) - actionmailer (5.0.0.1) - actionpack (= 5.0.0.1) - actionview (= 5.0.0.1) - activejob (= 5.0.0.1) + actionmailer (5.0.1) + actionpack (= 5.0.1) + actionview (= 5.0.1) + activejob (= 5.0.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.0.0.1) - actionview (= 5.0.0.1) - activesupport (= 5.0.0.1) + actionpack (5.0.1) + actionview (= 5.0.1) + activesupport (= 5.0.1) rack (~> 2.0) rack-test (~> 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.0.1) - activesupport (= 5.0.0.1) + actionview (5.0.1) + activesupport (= 5.0.1) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 2.0) @@ -39,27 +39,27 @@ GEM deprecation (~> 0.1) linkeddata (~> 1.1) rdf (~> 1.1) - activejob (5.0.0.1) - activesupport (= 5.0.0.1) + activejob (5.0.1) + activesupport (= 5.0.1) globalid (>= 0.3.6) - activemodel (5.0.0.1) - activesupport (= 5.0.0.1) - activerecord (5.0.0.1) - activemodel (= 5.0.0.1) - activesupport (= 5.0.0.1) + activemodel (5.0.1) + activesupport (= 5.0.1) + activerecord (5.0.1) + activemodel (= 5.0.1) + activesupport (= 5.0.1) arel (~> 7.0) - activesupport (5.0.0.1) + activesupport (5.0.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (~> 0.7) minitest (~> 5.1) tzinfo (~> 1.1) addressable (2.5.0) public_suffix (~> 2.0, >= 2.0.2) - airbrussh (1.1.1) + airbrussh (1.1.2) sshkit (>= 1.6.1, != 1.7.0) arel (7.1.4) ast (2.3.0) - bagit (0.3.4) + bagit (0.4.0) docopt (~> 0.5.0) validatable (~> 1.6) bcp47 (0.3.3) @@ -69,7 +69,7 @@ GEM bundler (~> 1.2) thor (~> 0.18) byebug (9.0.6) - capistrano (3.6.1) + capistrano (3.7.1) airbrussh (>= 1.0.0) capistrano-harrow i18n @@ -96,17 +96,17 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) - concurrent-ruby (1.0.2) - config (1.3.0) + concurrent-ruby (1.0.4) + config (1.4.0) activesupport (>= 3.0) deep_merge (~> 1.1.1) confstruct (0.2.7) - coveralls (0.8.16) + coveralls (0.8.17) json (>= 1.8, < 3) simplecov (~> 0.12.0) - term-ansicolor (~> 1.3.0) + term-ansicolor (~> 1.3) thor (~> 0.19.1) - tins (>= 1.6.0, < 2) + tins (~> 1.6) daemons (1.2.4) deep_merge (1.1.1) deprecation (0.2.2) @@ -165,14 +165,14 @@ GEM nokogiri (>= 1.4.3) erubis (2.7.0) fakeweb (1.3.0) - faraday (0.10.0) + faraday (0.10.1) multipart-post (>= 1.2, < 3) ffi (1.9.14) globalid (0.3.7) activesupport (>= 4.1.0) haml (4.0.7) tilt - honeybadger (2.7.1) + honeybadger (2.7.2) hooks (0.4.1) uber (~> 0.0.14) htmlentities (4.3.4) @@ -240,8 +240,8 @@ GEM iso-639 nokogiri nom-xml (~> 0.6.0) - modsulator (1.0.1) - activesupport (>= 3.0) + modsulator (1.0.4) + activesupport equivalent-xml (>= 0.6.0) nokogiri roo (>= 1.1) @@ -252,7 +252,7 @@ GEM net-ssh (>= 2.6.5) net-sftp (2.1.2) net-ssh (>= 2.6.5) - net-ssh (3.2.0) + net-ssh (4.0.0) netrc (0.11.0) nio4r (1.2.1) nokogiri (1.6.8.1) @@ -272,7 +272,7 @@ GEM parser (2.3.3.1) ast (~> 2.2) powerpack (0.1.1) - public_suffix (2.0.4) + public_suffix (2.0.5) puma (3.6.2) rack (2.0.1) rack-console (1.3.1) @@ -280,34 +280,34 @@ GEM rack-test rack-test (0.6.3) rack (>= 1.0) - rails (5.0.0.1) - actioncable (= 5.0.0.1) - actionmailer (= 5.0.0.1) - actionpack (= 5.0.0.1) - actionview (= 5.0.0.1) - activejob (= 5.0.0.1) - activemodel (= 5.0.0.1) - activerecord (= 5.0.0.1) - activesupport (= 5.0.0.1) + rails (5.0.1) + actioncable (= 5.0.1) + actionmailer (= 5.0.1) + actionpack (= 5.0.1) + actionview (= 5.0.1) + activejob (= 5.0.1) + activemodel (= 5.0.1) + activerecord (= 5.0.1) + activesupport (= 5.0.1) bundler (>= 1.3.0, < 2.0) - railties (= 5.0.0.1) + railties (= 5.0.1) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.1) actionpack (~> 5.x) actionview (~> 5.x) activesupport (~> 5.x) - rails-dom-testing (2.0.1) + rails-dom-testing (2.0.2) activesupport (>= 4.2.0, < 6.0) - nokogiri (~> 1.6.0) + nokogiri (~> 1.6) rails-html-sanitizer (1.0.3) loofah (~> 2.0) - railties (5.0.0.1) - actionpack (= 5.0.0.1) - activesupport (= 5.0.0.1) + railties (5.0.1) + actionpack (= 5.0.1) + activesupport (= 5.0.1) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rainbow (2.1.0) + rainbow (2.2.1) rake (12.0.0) rb-fsevent (0.9.8) rb-inotify (0.9.7) @@ -368,7 +368,7 @@ GEM mime-types (>= 1.16, < 4.0) netrc (~> 0.8) retries (0.0.5) - roo (2.5.1) + roo (2.7.1) nokogiri (~> 1) rubyzip (~> 1.1, < 2.0.0) rsolr (1.1.2) @@ -396,11 +396,11 @@ GEM rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) - rubocop-rspec (1.8.0) + rubocop-rspec (1.9.1) rubocop (>= 0.42.0) ruby-cache (0.3.0) ruby-graphviz (1.2.2) - ruby-oci8 (2.2.2) + ruby-oci8 (2.2.3) ruby-progressbar (1.8.1) rubydora (1.9.1) activemodel @@ -413,7 +413,7 @@ GEM rest-client rubyzip (1.2.0) scrub_rb (1.0.1) - sequel (4.41.0) + sequel (4.42.0) simplecov (0.12.0) docile (~> 1.1.0) json (>= 1.8, < 3) @@ -443,14 +443,14 @@ GEM spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) - sprockets (3.7.0) + sprockets (3.7.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-rails (3.2.0) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sshkit (1.11.4) + sshkit (1.11.5) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) stanford-mods (2.3.1) @@ -459,7 +459,7 @@ GEM stomp (1.4.3) sxp (0.1.5) systemu (2.6.5) - term-ansicolor (1.3.2) + term-ansicolor (1.4.0) tins (~> 1.0) thor (0.19.4) thread_safe (0.3.5) @@ -471,7 +471,7 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.2) - unicode-display_width (1.1.1) + unicode-display_width (1.1.2) uuidtools (2.1.5) validatable (1.6.7) websocket-driver (0.6.4) From cb7bdcfe871aef04345d1a08fab8ac4ca1a2415c Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Wed, 4 Jan 2017 16:47:21 -0800 Subject: [PATCH 3/4] Add ActionController::MimeResponds and add a test for object registration succeeding --- app/controllers/application_controller.rb | 1 + app/controllers/objects_controller.rb | 4 ++-- spec/controllers/objects_controller_spec.rb | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 24accc806..79645d58f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,6 @@ class ApplicationController < ActionController::API include ActionController::HttpAuthentication::Basic::ControllerMethods + include ActionController::MimeResponds http_basic_authenticate_with name: Dor::Config.dor.service_user, password: Dor::Config.dor.service_password diff --git a/app/controllers/objects_controller.rb b/app/controllers/objects_controller.rb index 6704e9345..9308d16a5 100644 --- a/app/controllers/objects_controller.rb +++ b/app/controllers/objects_controller.rb @@ -19,10 +19,10 @@ def create reg_response = Dor::RegistrationService.create_from_request(create_params) Rails.logger.info(reg_response) pid = reg_response['pid'] - + respond_to do |format| format.json { render status: 201, location: object_location(pid), json: Dor::RegistrationResponse.new(reg_response) } - format.txt { render status: 201, location: object_location(pid), plain: Dor::RegistrationResponse.new(reg_response).to_txt } + format.all { render status: 201, location: object_location(pid), plain: Dor::RegistrationResponse.new(reg_response).to_txt } end end diff --git a/spec/controllers/objects_controller_spec.rb b/spec/controllers/objects_controller_spec.rb index e98ed8bf0..07e4a853d 100644 --- a/spec/controllers/objects_controller_spec.rb +++ b/spec/controllers/objects_controller_spec.rb @@ -21,6 +21,16 @@ expect(response.headers['Location']).to match(/\/fedora\/objects\/druid:existing123obj/) end end + + it 'registers the object with the registration service' do + allow(Dor::RegistrationService).to receive(:create_from_request).and_return('pid' => 'druid:xyz') + + post :create + + expect(Dor::RegistrationService).to have_received(:create_from_request) + expect(response.status).to eq(201) + expect(response.location).to end_with '/fedora/objects/druid:xyz' + end end describe 'initialize_workspace' do From b5b12dcfab590eb24a2db5a47eaba7ffb730534f Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Wed, 4 Jan 2017 16:57:54 -0800 Subject: [PATCH 4/4] Delegate RegistrationResponse#to_json to the params object --- app/models/dor/registration_response.rb | 7 +++---- spec/controllers/objects_controller_spec.rb | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/models/dor/registration_response.rb b/app/models/dor/registration_response.rb index b0040d0c5..ba4236f2c 100644 --- a/app/models/dor/registration_response.rb +++ b/app/models/dor/registration_response.rb @@ -1,5 +1,8 @@ module Dor class RegistrationResponse + attr_reader :params + delegate :to_json, to: :params + def initialize(p_hash) @params = p_hash end @@ -7,9 +10,5 @@ def initialize(p_hash) def to_txt @params[:pid] end - - def to_json - @params.to_json - end end end diff --git a/spec/controllers/objects_controller_spec.rb b/spec/controllers/objects_controller_spec.rb index 07e4a853d..247eda131 100644 --- a/spec/controllers/objects_controller_spec.rb +++ b/spec/controllers/objects_controller_spec.rb @@ -25,7 +25,7 @@ it 'registers the object with the registration service' do allow(Dor::RegistrationService).to receive(:create_from_request).and_return('pid' => 'druid:xyz') - post :create + post :create, format: :json expect(Dor::RegistrationService).to have_received(:create_from_request) expect(response.status).to eq(201)