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 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 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) }