-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor specs for DOI relations through event data into separate file (
#1021) ## Purpose Refactors the specs for DOIs by separating out the tests for related dois through events. Renables the tests for related dois ## Types of changes - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Reviewer, please remember our [guidelines](https://datacite.atlassian.net/wiki/spaces/TEC/pages/1168375809/Pull+Request+Guidelines): - Be humble in the language and feedback you give, ask don't tell. - Consider using positive language as opposed to neutral when offering feedback. This is to avoid the negative bias that can occur with neutral language appearing negative. - Offer suggestions on how to improve code e.g. simplification or expanding clarity. - Ensure you give reasons for the changes you are proposing.
- Loading branch information
Showing
2 changed files
with
160 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
|
||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
describe Doi, type: :model, vcr: true, elasticsearch: true do | ||
describe "views" do | ||
let(:client) { create(:client) } | ||
let(:doi) { create(:doi, client: client, aasm_state: "findable") } | ||
let!(:views) { create_list(:event_for_datacite_investigations, 3, obj_id: "https://doi.org/#{doi.doi}", relation_type_id: "unique-dataset-investigations-regular", total: 25) } | ||
|
||
it "has views" do | ||
expect(doi.view_events.count).to eq(3) | ||
expect(doi.view_count).to eq(75) | ||
expect(doi.views_over_time.first).to eq("total" => 25, "yearMonth" => "2015-06") | ||
|
||
view = doi.view_events.first | ||
expect(view.target_doi).to eq(doi.doi) | ||
expect(view.total).to eq(25) | ||
end | ||
end | ||
|
||
describe "downloads" do | ||
let(:client) { create(:client) } | ||
let(:doi) { create(:doi, client: client, aasm_state: "findable") } | ||
let!(:downloads) { create_list(:event_for_datacite_investigations, 3, obj_id: "https://doi.org/#{doi.doi}", relation_type_id: "unique-dataset-requests-regular", total: 10) } | ||
|
||
it "has downloads" do | ||
expect(doi.download_events.count).to eq(3) | ||
expect(doi.download_count).to eq(30) | ||
expect(doi.downloads_over_time.first).to eq("total" => 10, "yearMonth" => "2015-06") | ||
|
||
download = doi.download_events.first | ||
expect(download.target_doi).to eq(doi.doi) | ||
expect(download.total).to eq(10) | ||
end | ||
end | ||
|
||
describe "references" do | ||
let(:client) { create(:client) } | ||
let(:doi) { create(:doi, client: client, aasm_state: "findable") } | ||
let(:target_doi) { create(:doi, client: client, aasm_state: "findable") } | ||
let!(:reference_events) { create(:event_for_crossref, subj_id: "https://doi.org/#{doi.doi}", obj_id: "https://doi.org/#{target_doi.doi}", relation_type_id: "references") } | ||
|
||
it "has references" do | ||
expect(doi.references.count).to eq(1) | ||
expect(doi.reference_ids.count).to eq(1) | ||
expect(doi.reference_count).to eq(1) | ||
|
||
reference_id = doi.reference_ids.first | ||
expect(reference_id).to eq(target_doi.doi.downcase) | ||
end | ||
end | ||
|
||
describe "citations" do | ||
let(:client) { create(:client) } | ||
let(:doi) { create(:doi, client: client, aasm_state: "findable") } | ||
let(:source_doi) { create(:doi, client: client, aasm_state: "findable") } | ||
let(:source_doi2) { create(:doi, client: client, aasm_state: "findable") } | ||
let!(:citation_event) do | ||
create(:event_for_datacite_crossref, { | ||
subj_id: "https://doi.org/#{doi.doi}", | ||
obj_id: "https://doi.org/#{source_doi.doi}", | ||
relation_type_id: "is-referenced-by", | ||
occurred_at: "2015-06-13T16:14:19Z" | ||
}) | ||
end | ||
let!(:citation_event2) do | ||
create(:event_for_datacite_crossref, { | ||
subj_id: "https://doi.org/#{doi.doi}", | ||
obj_id: "https://doi.org/#{source_doi2.doi}", | ||
relation_type_id: "is-referenced-by", | ||
occurred_at: "2016-06-13T16:14:19Z" | ||
}) | ||
end | ||
let!(:citation_event3) do | ||
create(:event_for_datacite_crossref, { | ||
subj_id: "https://doi.org/#{doi.doi}", | ||
obj_id: "https://doi.org/#{source_doi2.doi}", | ||
relation_type_id: "is-cited-by", | ||
occurred_at: "2016-06-13T16:14:19Z" | ||
}) | ||
end | ||
|
||
# removing duplicate dois in citation_ids, citation_count and citations_over_time (different relation_type_id) | ||
it "has citations" do | ||
expect(doi.citations.count).to eq(3) | ||
expect(doi.citation_ids.count).to eq(2) | ||
expect(doi.citation_count).to eq(2) | ||
expect(doi.citations_over_time).to eq([{ "total" => 1, "year" => "2015" }, { "total" => 1, "year" => "2016" }]) | ||
|
||
citation_id = doi.citation_ids.first | ||
expect(citation_id).to eq(source_doi.doi.downcase) | ||
end | ||
end | ||
|
||
describe "parts" do | ||
let(:client) { create(:client) } | ||
let(:doi) { create(:doi, client: client, aasm_state: "findable") } | ||
let(:target_doi) { create(:doi, client: client, aasm_state: "findable") } | ||
let!(:part_events) { create(:event_for_datacite_parts, subj_id: "https://doi.org/#{doi.doi}", obj_id: "https://doi.org/#{target_doi.doi}", relation_type_id: "has-part") } | ||
|
||
it "has parts" do | ||
expect(doi.parts.count).to eq(1) | ||
expect(doi.part_ids.count).to eq(1) | ||
expect(doi.part_count).to eq(1) | ||
|
||
part_id = doi.part_ids.first | ||
expect(part_id).to eq(target_doi.doi.downcase) | ||
end | ||
end | ||
|
||
describe "part of" do | ||
let(:client) { create(:client) } | ||
let(:doi) { create(:doi, client: client, aasm_state: "findable") } | ||
let(:source_doi) { create(:doi, client: client, aasm_state: "findable") } | ||
let!(:part_of_events) { create(:event_for_datacite_part_of, subj_id: "https://doi.org/#{doi.doi}", obj_id: "https://doi.org/#{source_doi.doi}", relation_type_id: "is-part-of") } | ||
|
||
it "has part of" do | ||
expect(doi.part_of.count).to eq(1) | ||
expect(doi.part_of_ids.count).to eq(1) | ||
expect(doi.part_of_count).to eq(1) | ||
|
||
part_of_id = doi.part_of_ids.first | ||
expect(part_of_id).to eq(source_doi.doi.downcase) | ||
end | ||
end | ||
|
||
describe "versions" do | ||
let(:client) { create(:client) } | ||
let(:doi) { create(:doi, client: client, aasm_state: "findable") } | ||
let(:target_doi) { create(:doi, client: client, aasm_state: "findable") } | ||
let!(:version_event) { create(:event_for_datacite_versions, subj_id: "https://doi.org/#{doi.doi}", obj_id: "https://doi.org/#{target_doi.doi}") } | ||
|
||
it "has versions" do | ||
expect(doi.versions.count).to eq(1) | ||
expect(doi.version_ids.count).to eq(1) | ||
expect(doi.version_count).to eq(1) | ||
|
||
version_id = doi.version_ids.first | ||
expect(version_id).to eq(target_doi.doi.downcase) | ||
end | ||
end | ||
|
||
describe "version of" do | ||
let(:client) { create(:client) } | ||
let(:doi) { create(:doi, client: client, aasm_state: "findable") } | ||
let(:source_doi) { create(:doi, client: client, aasm_state: "findable") } | ||
let!(:version_of_events) { create(:event_for_datacite_version_of, subj_id: "https://doi.org/#{doi.doi}", obj_id: "https://doi.org/#{source_doi.doi}") } | ||
|
||
it "has version of" do | ||
expect(doi.version_of.count).to eq(1) | ||
expect(doi.version_of_ids.count).to eq(1) | ||
expect(doi.version_of_count).to eq(1) | ||
|
||
version_of_id = doi.version_of_ids.first | ||
expect(version_of_id).to eq(source_doi.doi.downcase) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters