From a31bc31acca64aa496157e9f735b5acaf88e1daa Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sun, 27 Sep 2020 19:26:23 +0200 Subject: [PATCH] align repository-prefixes controller with changes in client-prefixes controller. #642 --- .../repository_prefixes_controller.rb | 23 ++++++++++++++++++- spec/requests/repository_prefixes_spec.rb | 7 +++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/controllers/repository_prefixes_controller.rb b/app/controllers/repository_prefixes_controller.rb index 79f0cf1a9..48cb9427f 100644 --- a/app/controllers/repository_prefixes_controller.rb +++ b/app/controllers/repository_prefixes_controller.rb @@ -85,6 +85,16 @@ def create authorize! :create, @client_prefix if @client_prefix.save + if @client_prefix.__elasticsearch__.index_document.dig("result") != "created" + logger.error "Error adding Repository Prefix #{@client_prefix.uid} to Elasticsearch index." + end + if @client_prefix.prefix.__elasticsearch__.index_document.dig("result") != "updated" + logger.error "Error updating Elasticsearch index for Prefix #{@client_prefix.prefix.uid}." + end + if @client_prefix.provider_prefix.__elasticsearch__.index_document.dig("result") != "updated" + logger.error "Error updating Elasticsearch index for Provider Prefix #{@client_prefix.provider_prefix.uid}." + end + options = {} options[:include] = @include options[:is_collection] = false @@ -105,8 +115,19 @@ def update def destroy authorize! :destroy, @client_prefix message = "Client prefix #{@client_prefix.uid} deleted." + if @client_prefix.destroy - Rails.logger.warn message + if @client_prefix.__elasticsearch__.delete_document.dig("result") != "deleted" + logger.error "Error deleting Repository Prefix #{@client_prefix.uid} from Elasticsearch index." + end + if @client_prefix.prefix.__elasticsearch__.index_document.dig("result") != "updated" + logger.error "Error updating Elasticsearch index for Prefix #{@client_prefix.prefix.uid}." + end + if @client_prefix.provider_prefix.__elasticsearch__.index_document + logger.error "Error updating Elasticsearch index for Provider Prefix #{@client_prefix.provider_prefix.uid}." + end + + logger.warn message head :no_content else Rails.logger.error @client_prefix.errors.inspect diff --git a/spec/requests/repository_prefixes_spec.rb b/spec/requests/repository_prefixes_spec.rb index 82baad7ce..a56f00363 100644 --- a/spec/requests/repository_prefixes_spec.rb +++ b/spec/requests/repository_prefixes_spec.rb @@ -89,9 +89,14 @@ end end - describe 'DELETE /repository-prefixes/:uid' do + describe 'DELETE /repository-prefixes/:uid', elasticsearch: true do let!(:client_prefix) { create(:client_prefix, client: client, prefix: prefix, provider_prefix: provider_prefix) } + before do + ClientPrefix.import + sleep 2 + end + it 'deletes a repository-prefix' do delete "/repository-prefixes/#{client_prefix.uid}", nil, headers