Skip to content

Commit

Permalink
normalize inputs to controller
Browse files Browse the repository at this point in the history
  • Loading branch information
SaravShah committed May 2, 2018
1 parent 6a0cff3 commit beaf589
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CatalogController < ApplicationController

# POST /catalog
def create
druid = poh_params[:druid]
druid = poh_params[:druid].split(':').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}")
Expand Down
17 changes: 9 additions & 8 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
RSpec.describe CatalogController, type: :controller do
let(:size) { 2342 }
let(:ver) { 3 }
let(:druid) { 'bj102hs9687' }
let(:druid) { 'druid:bj102hs9687' }
let(:druid_no_pre) { 'bj102hs9687' }
let(:storage_location) { "#{storage_location_param}/moab_storage_trunk" }
let(:storage_location_param) { "spec/fixtures/storage_root01" }

describe 'POST #create' do
context 'with valid params' do
let(:pres_obj) { PreservedObject.find_by(druid: druid) }
let(:pres_obj) { PreservedObject.find_by(druid: druid_no_pre) }
let(:pres_copy) { PreservedCopy.find_by(preserved_object: pres_obj) }

before do
post :create, params: { druid: druid, incoming_version: ver, incoming_size: size, storage_location: storage_location_param }
end

it 'saves PreservedObject and PreservedCopy in db' do
po = PreservedObject.find_by(druid: druid)
po = PreservedObject.find_by(druid: druid_no_pre)
pc = PreservedCopy.find_by(preserved_object: po)
expect(po).to be_an_instance_of PreservedObject
expect(pc).to be_an_instance_of PreservedCopy
Expand All @@ -25,7 +26,7 @@
expect(pres_copy.endpoint.storage_location).to eq storage_location
expect(pres_copy.version).to eq ver
expect(pres_copy.size).to eq size
expect(pres_obj.druid).to eq druid
expect(pres_obj.druid).to eq druid_no_pre
end

it 'response contains create_new_object code ' do
Expand Down Expand Up @@ -79,7 +80,7 @@

context 'db update failed' do
before do
allow(PreservedObject).to receive(:create!).with(hash_including(druid: druid))
allow(PreservedObject).to receive(:create!).with(hash_including(druid: druid_no_pre))
.and_raise(ActiveRecord::ActiveRecordError, 'foo')
post :create, params: { druid: druid, incoming_version: ver, incoming_size: size, storage_location: storage_location_param }
end
Expand All @@ -96,14 +97,14 @@

it 'response body contains druid' do
post :create, params: { druid: druid, incoming_version: ver, incoming_size: size, storage_location: storage_location_param }
expect(response.body).to include(druid)
expect(response.body).to include(druid_no_pre)
end
end

describe 'PATCH #update' do
before do
po = PreservedObject.create!(
druid: "bj102hs9687", current_version: ver, preservation_policy: PreservationPolicy.default_policy
druid: "druid:bj102hs9687", current_version: ver, preservation_policy: PreservationPolicy.default_policy
)
PreservedCopy.create!(
preserved_object: po,
Expand Down Expand Up @@ -147,7 +148,7 @@

context 'object does not exist' do
before do
patch :update, params: { druid: 'rr111rr1111', incoming_version: ver, incoming_size: size, storage_location: storage_location_param }
patch :update, params: { druid: 'druid:rr111rr1111', incoming_version: ver, incoming_size: size, storage_location: storage_location_param }
end
it 'response contains error message' do
error = "#<ActiveRecord::RecordNotFound: Couldn't find PreservedObject>"
Expand Down

0 comments on commit beaf589

Please sign in to comment.