From a153d1f5a572c16f27f5844d7f02da0eceb87af4 Mon Sep 17 00:00:00 2001 From: "Michael J. Giarlo" Date: Thu, 19 Sep 2019 10:47:32 -0700 Subject: [PATCH] Remove route and controller action no longer used Now that Argo uses the `Dor::Services::Client.virtual_objects` method, which hits `VirtualObjectsController` instead of the route and controller action removed in this branch, no code hits this anymore and can be removed. --- app/controllers/objects_controller.rb | 18 -------- config/routes.rb | 3 +- spec/requests/virtual_merge_spec.rb | 66 --------------------------- 3 files changed, 1 insertion(+), 86 deletions(-) delete mode 100644 spec/requests/virtual_merge_spec.rb diff --git a/app/controllers/objects_controller.rb b/app/controllers/objects_controller.rb index 6e6178951..e21eb5de1 100644 --- a/app/controllers/objects_controller.rb +++ b/app/controllers/objects_controller.rb @@ -40,24 +40,6 @@ def create end end - # TODO: Remove this once Argo, in stage and prod, uses a version of dor-services-client that no longer hits this endpoint - # Handles updates to the record. - # Presently this only needs to handle the merge object use case. - # Do this by providing: constituent_ids => ['druid:123', 'druid:345'] - def update - # validate that the constituent_ids parameter is an present, raises ActionController::ParameterMissing - params.require(:constituent_ids) - filtered_params = params.permit(constituent_ids: []) - raise ActionController::ParameterMissing, 'constituent_ids must be an array' unless filtered_params[:constituent_ids] - - # Update the constituent relationship - errors = ConstituentService.new(parent_druid: params[:id]).add(child_druids: filtered_params[:constituent_ids]) - - return render json: { errors: errors }, status: :unprocessable_entity if errors - - head :no_content - end - def show render json: Cocina::Mapper.build(@item) end diff --git a/config/routes.rb b/config/routes.rb index 7ff09bb40..b2c0470dc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,8 +26,7 @@ resources :background_job_results, only: [:show], defaults: { format: :json } - # TODO: Remove :update once Argo, in stage and prod, uses a version of dor-services-client that no longer hits this endpoint - resources :objects, only: [:create, :update, :show] do + resources :objects, only: [:create, :show] do member do post 'publish' post 'update_marc_record' diff --git a/spec/requests/virtual_merge_spec.rb b/spec/requests/virtual_merge_spec.rb deleted file mode 100644 index f6412fdbc..000000000 --- a/spec/requests/virtual_merge_spec.rb +++ /dev/null @@ -1,66 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe 'Virtual merge of objects' do - let(:parent_id) { 'druid:mk420bs7601' } - let(:child1_id) { 'druid:child1' } - let(:child2_id) { 'druid:child2' } - - let(:object) { Dor::Item.new(pid: parent_id) } - let(:service) { instance_double(ConstituentService, add: nil) } - - before do - allow(Dor).to receive(:find).and_return(object) - allow(ConstituentService).to receive(:new).with(parent_druid: parent_id).and_return(service) - end - - context 'when constituent_ids is provided' do - it 'merges the objects' do - put "/v1/objects/#{parent_id}", - params: { constituent_ids: [child1_id, child2_id] }, - headers: { 'Authorization' => "Bearer #{jwt}" } - expect(service).to have_received(:add).with(child_druids: [child1_id, child2_id]) - expect(response).to be_successful - end - end - - context 'when constituent_ids is not provided' do - it 'renders an error' do - put "/v1/objects/#{parent_id}", - params: { title: 'New name' }, - headers: { 'Authorization' => "Bearer #{jwt}" } - expect(service).not_to have_received(:add) - expect(response).to be_bad_request - json = JSON.parse(response.body) - expect(json['errors'][0]['detail']).to eq 'param is missing or the value is empty: constituent_ids' - end - end - - context 'when constituent_ids is not an array' do - it 'renders an error' do - put "/v1/objects/#{parent_id}", - params: { constituent_ids: child1_id }, - headers: { 'Authorization' => "Bearer #{jwt}" } - expect(service).not_to have_received(:add) - expect(response).to be_bad_request - json = JSON.parse(response.body) - expect(json['errors'][0]['detail']).to eq 'param is missing or the value is empty: constituent_ids must be an array' - end - end - - context 'when constituent_ids contain objects that are not combinable' do - before do - allow(service).to receive(:add).and_return(child2_id => "Item #{child2_id} is not open for modification") - end - - it 'renders an error' do - put "/v1/objects/#{parent_id}", - params: { constituent_ids: [child1_id, child2_id] }, - headers: { 'Authorization' => "Bearer #{jwt}" } - expect(service).to have_received(:add).with(child_druids: [child1_id, child2_id]) - expect(response).to be_unprocessable - expect(response.body).to eq '{"errors":{"druid:child2":"Item druid:child2 is not open for modification"}}' - end - end -end