Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/models/crossref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ def push_data(result, _options = {})
# Rails.logger.info "Extracting related identifiers for #{items.size} DOIs updated from #{options[:from_date]} until #{options[:until_date]}."

Array.wrap(items).map do |item|
subj_ra = item.dig("subject", "registration-agency")
obj_ra = item.dig("object", "registration-agency")

next if subj_ra&.downcase == "crossref" && obj_ra&.downcase == "crossref"

CrossrefImportJob.perform_later(item)
end
end
Expand Down
54 changes: 49 additions & 5 deletions spec/models/crossref_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,19 @@
describe "#push_item" do
it "sends a message to the events queue" do
allow(Crossref).to(receive(:send_event_import_message).and_return(nil))
allow(Base).to(receive(:cached_crossref_response).and_return({ subj: "subj" }))
allow(Base).to(receive(:cached_datacite_response).and_return({ obj: "obj" }))
allow(described_class).to(receive(:cached_crossref_response).and_return({ subj: "subj" }))
allow(described_class).to(receive(:cached_datacite_response).and_return({ obj: "obj" }))
allow(Rails.logger).to(receive(:info))

item = {
"timestamp" => "2002-07-25T03:18:25Z",
"relation" => "example_relation_type",
"subject" => {
"id" => "example_subj_id"
"id" => "example_subj_id",
},
"object" => {
"id" => "example_obj_id"
}
"id" => "example_obj_id",
},
}

Crossref.push_item(item)
Expand All @@ -133,4 +133,48 @@
expect(Rails.logger).to(have_received(:info).with("[Event Data] example_subj_id example_relation_type example_obj_id sent to the events queue."))
end
end

describe "#push_data" do
let(:model) { described_class.new }

let(:item_crossref_to_datacite) do
{
"subject" => { "id" => "https://doi.org/10.1234/subj", "registration-agency" => "Crossref" },
"object" => { "id" => "https://doi.org/10.5678/obj", "registration-agency" => "DataCite" },
}
end

let(:item_crossref_to_crossref) do
{
"subject" => { "id" => "https://doi.org/10.1234/subj", "registration-agency" => "Crossref" },
"object" => { "id" => "https://doi.org/10.5678/obj", "registration-agency" => "Crossref" },
}
end

let(:result_crossref_to_datacite) do
instance_double(Faraday::Response,
body: { "data" => { "message" => { "items" => [item_crossref_to_datacite] } } })
end

let(:result_crossref_to_crossref) do
instance_double(Faraday::Response,
body: { "data" => { "message" => { "items" => [item_crossref_to_crossref] } } })
end

it "does not enqueue when both subject and object are Crossref" do
allow(CrossrefImportJob).to receive(:perform_later)

model.push_data(result_crossref_to_crossref)

expect(CrossrefImportJob).not_to have_received(:perform_later)
end

it "enqueues when object is DataCite" do
allow(CrossrefImportJob).to receive(:perform_later)

model.push_data(result_crossref_to_datacite)

expect(CrossrefImportJob).to have_received(:perform_later).once
end
end
end
Loading