Skip to content

Commit

Permalink
Merge 76c676a into 988d617
Browse files Browse the repository at this point in the history
  • Loading branch information
ndushay committed Jul 17, 2018
2 parents 988d617 + 76c676a commit 3c1e572
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 137 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,6 @@ Style/TernaryParentheses:
Exclude:
- spec/lib/active_record_utils_spec.rb # reads better with parens
- 'spec/models/preserved_copy_spec.rb'

Style/WordArray:
Enabled: false # I hate this rule; "precious" ruby syntax
43 changes: 29 additions & 14 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##
# CatalogController allows clients to manipulate the Object Inventory Catalog, e.g.
# CatalogController allows consumers to interact with the Preservation Catalog, e.g.
# to add an existing moab object to the catalog, or to update an entry for a moab object
# that's already in the catalog.
class CatalogController < ApplicationController
Expand All @@ -8,12 +8,8 @@ class CatalogController < ApplicationController

# POST /catalog
def create
druid = poh_params[:druid].split(':', 2).last
incoming_version = poh_params[:incoming_version].to_i
incoming_size = poh_params[:incoming_size].to_i
endpoint = Endpoint.find_by(storage_location: "#{poh_params[:storage_location]}/#{Moab::Config.storage_trunk}")
@poh = PreservedObjectHandler.new(druid, incoming_version, incoming_size, endpoint)
poh.create
@poh = PreservedObjectHandler.new(bare_druid, incoming_version, incoming_size, endpoint)
poh.create(checksums_validated)
status_code =
if poh.results.contains_result_code?(:created_new_object)
:created # 201
Expand All @@ -30,12 +26,8 @@ def create
# PATCH /catalog/:id
# User can only update a partial record (application controls what can be updated)
def update
druid = poh_params[:druid].split(':', 2).last
incoming_version = poh_params[:incoming_version].to_i
incoming_size = poh_params[:incoming_size].to_i
endpoint = Endpoint.find_by(storage_location: "#{poh_params[:storage_location]}/#{Moab::Config.storage_trunk}")
@poh = PreservedObjectHandler.new(druid, incoming_version, incoming_size, endpoint)
poh.update_version
@poh = PreservedObjectHandler.new(bare_druid, incoming_version, incoming_size, endpoint)
poh.update_version(checksums_validated)
status_code =
if poh.results.contains_result_code?(:actual_vers_gt_db_obj)
:ok # 200
Expand All @@ -55,6 +47,29 @@ def update

# strong params / whitelist params
def poh_params
params.permit(:druid, :incoming_version, :incoming_size, :storage_location)
params.permit(:druid, :incoming_version, :incoming_size, :storage_location, :checksums_validated)
end

def bare_druid
poh_params[:druid].split(':', 2).last if poh_params[:druid]
end

def incoming_version
poh_params[:incoming_version].to_i if poh_params[:incoming_version]
end

def incoming_size
poh_params[:incoming_size].to_i if poh_params[:incoming_size]
end

def endpoint
return unless poh_params[:storage_location]
Endpoint.find_by(storage_location: "#{poh_params[:storage_location]}/#{Moab::Config.storage_trunk}")
end

# @return boolean
def checksums_validated
return poh_params[:checksums_validated].casecmp('true').zero? if poh_params[:checksums_validated]
false
end
end
37 changes: 0 additions & 37 deletions app/controllers/moab_storage_controller.rb

This file was deleted.

1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

Rails.application.routes.draw do
resources :catalog, param: :druid, only: %i[create update]
resources :moab_storage, only: %i[index show]

mount Resque::Server.new, at: '/resque',
constraints: ->(req) { Settings.resque_dashboard_hostnames.include?(req.host) }
Expand Down
43 changes: 43 additions & 0 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,49 @@
end
end

describe 'parameters' do
describe 'checksums_validated' do
let(:results) { instance_double(AuditResults) }
let(:poh) { instance_double(PreservedObjectHandler) }

before do
allow(results).to receive(:contains_result_code?)
allow(poh).to receive(:results).and_return(results)
allow(PreservedObjectHandler).to receive(:new).and_return(poh)
end

it 'false if not present' do
expect(poh).to receive(:create).with(false)
post :create, params: { druid: bare_druid, incoming_version: ver, incoming_size: size, storage_location: storage_location_param }
end
['true', 'True', 'TRUE'].each do |t_val|
it "#{t_val} evaluates to true" do
expect(poh).to receive(:create).with(true)
post :create, params: { druid: bare_druid, incoming_version: ver, incoming_size: size, storage_location: storage_location_param, checksums_validated: t_val }
end
end
['nil', '1', 'on'].each do |t_val|
it "#{t_val} evaluates to false" do
expect(poh).to receive(:update_version).with(false)
patch :update, params: { druid: bare_druid, incoming_version: ver, incoming_size: size, storage_location: storage_location_param, checksums_validated: 'false' }
end
end
end

describe 'incoming_size is required' do
it 'incoming_size absent - errors' do
patch :create, params: { druid: bare_druid, incoming_version: ver, storage_location: storage_location_param }
expect(response).to have_http_status(:not_acceptable)
expect(response.body).to match(/encountered validation error\(s\)\:.*Incoming size is not a number/)
end
it 'incoming size present - no errors' do
patch :create, params: { druid: bare_druid, incoming_version: ver, incoming_size: size, storage_location: storage_location_param }
expect(response).to have_http_status(:created)
expect(response.body).not_to include('encountered validation error(s):')
end
end
end

describe 'Routing' do
let(:druid) { "xx000xx0000" }

Expand Down
85 changes: 0 additions & 85 deletions spec/controllers/moab_storage_controller_spec.rb

This file was deleted.

0 comments on commit 3c1e572

Please sign in to comment.