Skip to content

Commit

Permalink
align repository-prefixes controller with changes in client-prefixes …
Browse files Browse the repository at this point in the history
…controller. #642
  • Loading branch information
Martin Fenner committed Sep 27, 2020
1 parent 8a613d6 commit a31bc31
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
23 changes: 22 additions & 1 deletion app/controllers/repository_prefixes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion spec/requests/repository_prefixes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit a31bc31

Please sign in to comment.