From 17854bde464b14fe353598e115753052aed5cc5b Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Tue, 12 Jan 2021 10:09:31 +0100 Subject: [PATCH 1/3] Don't do elasticsearch check on provider_prefix Related to previous work on removing indexing. Because indexing happens in indexable concern we cant check that the document here was indexed. So here we just do regular model save. --- app/controllers/provider_prefixes_controller.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/provider_prefixes_controller.rb b/app/controllers/provider_prefixes_controller.rb index 9715f8686..209997b67 100644 --- a/app/controllers/provider_prefixes_controller.rb +++ b/app/controllers/provider_prefixes_controller.rb @@ -125,9 +125,7 @@ def create @provider_prefix = ProviderPrefix.new(safe_params) authorize! :create, @provider_prefix - if @provider_prefix.save && @provider_prefix.__elasticsearch__.index_document.dig("result") == "created" - @provider_prefix.prefix.__elasticsearch__.index_document - + if @provider_prefix.save options = {} options[:include] = @include options[:is_collection] = false From bec6e736c1680cf46f65e0a1face97cd249e6616 Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Tue, 12 Jan 2021 10:09:41 +0100 Subject: [PATCH 2/3] Add back in the provider_prefix create test --- spec/requests/provider_prefixes_spec.rb | 94 ++++++++++++------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/spec/requests/provider_prefixes_spec.rb b/spec/requests/provider_prefixes_spec.rb index b9526a778..e77528a00 100644 --- a/spec/requests/provider_prefixes_spec.rb +++ b/spec/requests/provider_prefixes_spec.rb @@ -150,53 +150,53 @@ end end - # describe "POST /provider-prefixes" do - # context "when the request is valid" do - # let(:valid_attributes) do - # { - # "data" => { - # "type" => "provider-prefixes", - # "relationships": { - # "provider": { - # "data": { "type": "provider", "id": provider.uid }, - # }, - # "prefix": { "data": { "type": "prefix", "id": prefix.uid } }, - # }, - # }, - # } - # end - - # before do - # Prefix.import - # Provider.import - # sleep 2 - # end - - # it "creates a provider-prefix" do - # post "/provider-prefixes", valid_attributes, headers - - # expect(last_response.status).to eq(201) - # expect(json.dig("data", "id")).not_to be_nil - # end - # end - - # context "when the request is invalid" do - # let!(:provider) { create(:provider) } - # let(:not_valid_attributes) do - # { "data" => { "type" => "provider-prefixes" } } - # end - - # it "returns status code 422" do - # post "/provider-prefixes", - # not_valid_attributes, headers - - # expect(last_response.status).to eq(422) - # expect(json["errors"].first).to eq( - # "source" => "provider", "title" => "Must exist", - # ) - # end - # end - # end + describe "POST /provider-prefixes" do + context "when the request is valid" do + let(:valid_attributes) do + { + "data" => { + "type" => "provider-prefixes", + "relationships": { + "provider": { + "data": { "type": "provider", "id": provider.uid }, + }, + "prefix": { "data": { "type": "prefix", "id": prefix.uid } }, + }, + }, + } + end + + before do + Prefix.import + Provider.import + sleep 2 + end + + it "creates a provider-prefix" do + post "/provider-prefixes", valid_attributes, headers + + expect(last_response.status).to eq(201) + expect(json.dig("data", "id")).not_to be_nil + end + end + + context "when the request is invalid" do + let!(:provider) { create(:provider) } + let(:not_valid_attributes) do + { "data" => { "type" => "provider-prefixes" } } + end + + it "returns status code 422" do + post "/provider-prefixes", + not_valid_attributes, headers + + expect(last_response.status).to eq(422) + expect(json["errors"].first).to eq( + "source" => "provider", "title" => "Must exist", + ) + end + end + end describe "DELETE /provider-prefixes/:uid" do let!(:provider_prefix) { create(:provider_prefix) } From 27f35879b79b655f6e7d30f505ffa9b0a213ed33 Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Wed, 13 Jan 2021 13:42:06 +0100 Subject: [PATCH 3/3] Change Prefix model index immediatly on commit This matches touch --- app/models/concerns/indexable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index ce8b4a636..ef1fd8a8c 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -8,7 +8,7 @@ module Indexable included do after_commit on: %i[create update] do # use index_document instead of update_document to also update virtual attributes - unless %w[ProviderPrefix ClientPrefix].include?(self.class.name) + unless %w[Prefix ProviderPrefix ClientPrefix].include?(self.class.name) IndexJob.perform_later(self) else __elasticsearch__.index_document