Skip to content

Commit

Permalink
Merge pull request #51 from sul-dlss/body-params-fallback
Browse files Browse the repository at this point in the history
#body_params should fallback to an empty hash
  • Loading branch information
ndushay committed Jan 5, 2017
2 parents ce95e8d + b5b12dc commit 9a5753b
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 65 deletions.
3 changes: 3 additions & 0 deletions .rubocop_todo.yml
Expand Up @@ -255,3 +255,6 @@ Style/ZeroLengthPredicate:

Bundler/OrderedGems:
Enabled: false

RSpec/MessageSpies:
Enabled: false
114 changes: 57 additions & 57 deletions 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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -272,42 +272,42 @@ 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)
rack (>= 1.1)
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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions 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

Expand Down
8 changes: 4 additions & 4 deletions app/controllers/objects_controller.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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
7 changes: 3 additions & 4 deletions app/models/dor/registration_response.rb
@@ -1,15 +1,14 @@
module Dor
class RegistrationResponse
attr_reader :params
delegate :to_json, to: :params

def initialize(p_hash)
@params = p_hash
end

def to_txt
@params[:pid]
end

def to_json
@params.to_json
end
end
end
10 changes: 10 additions & 0 deletions spec/controllers/objects_controller_spec.rb
Expand Up @@ -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, format: :json

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
Expand Down

0 comments on commit 9a5753b

Please sign in to comment.