Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/datacite/lupo
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jan 14, 2021
2 parents f9223dc + 27f3587 commit d46e3bb
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 51 deletions.
4 changes: 1 addition & 3 deletions app/controllers/provider_prefixes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
94 changes: 47 additions & 47 deletions spec/requests/provider_prefixes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down

0 comments on commit d46e3bb

Please sign in to comment.