Skip to content

Commit

Permalink
Adjust tests to new UI and account for the fact that we are generatin…
Browse files Browse the repository at this point in the history
…g the ARK and DOI on creation.
  • Loading branch information
hectorcorrea committed May 27, 2022
1 parent cef5453 commit d017d10
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 38 deletions.
7 changes: 7 additions & 0 deletions app/models/ark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def self.find(ezid)
nil
end

def self.update(ezid, new_url)
return if ezid.start_with?(EZID_TEST_SHOULDER)
identifier = Ezid::Identifier.find(ezid)
identifier.target = new_url
identifier.save!
end

# Determines whether or not a given EZID string is a valid ARK
# @param [ezid] [String] the EZID being validated
# @return [Boolean]
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,6 @@ def submitter_collections

def family_name
# Hard-coded for now until we fetch the data from CAS, it comes in the [sn] attribute.
return "family-name"
"family-name"
end
end
19 changes: 5 additions & 14 deletions app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ class Work < ApplicationRecord
# Ensure that the metadata JSON is persisted properly
if work.dublin_core.present?
work.dublin_core = work.dublin_core.to_json
end
end

before_update do |work|
if dublin_core.present?
# we don't mint ARKs for these records
elsif work.ark.blank?
elsif work.profile == "DATACITE" && work.ark.blank?
work.ark = Ark.mint
end
end
Expand All @@ -26,11 +20,7 @@ class Work < ApplicationRecord
# Set this value in config/update_ark_url.yml
if Rails.configuration.update_ark_url
if work.ark.present?
# Ensure that the ARK metadata is updated for the new URL
if ark_object.target != work.url
ark_object.target = work.url
ark_object.save!
end
Ark.update(work.ark, work.url)
end
end
end
Expand Down Expand Up @@ -62,7 +52,7 @@ def self.create_skeleton(title, user_id, collection_id, work_type, profile)
end

# Convenience method to create Datasets with the DataCite profile
def self.create_dataset(title, user_id, collection_id, datacite_resource = nil)
def self.create_dataset(title, user_id, collection_id, datacite_resource = nil, ark = nil)
datacite_resource = PULDatacite::Resource.new(title: title) if datacite_resource.nil?
work = Work.new(
title: title,
Expand All @@ -72,7 +62,8 @@ def self.create_dataset(title, user_id, collection_id, datacite_resource = nil)
state: "AWAITING-APPROVAL",
profile: "DATACITE",
doi: "10.1234/tbd",
data_cite: datacite_resource.to_json
data_cite: datacite_resource.to_json,
ark: ark
)
# We skip the validation since we don't have all the required fields yet
work.save!(validate: false)
Expand Down
40 changes: 21 additions & 19 deletions spec/models/work_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,11 @@
let(:ezid) { @ezid }
let(:identifier) { @identifier }

it "creates a skeleton dataset" do
it "creates a skeleton dataset with a DOI and an ARK" do
expect(work.created_by_user.id).to eq user.id
expect(work.collection.id).to eq collection.id
expect(work.ark).to be_blank
expect(work.doi).to be_blank
end

it "mints an ARK on save (and only when needed)" do
expect(work.ark).to be_blank
work.save
expect(work.doi).to be_present
expect(work.ark).to be_present
original_ark = work.ark
work.save
expect(work.ark).to eq original_ark
end

it "prevents datasets with no users" do
Expand Down Expand Up @@ -89,7 +80,7 @@

context "when created with an existing ARK" do
context "and when the ARK is valid" do
let(:ezid) { "ark:/88435/dsp01qb98mj541" }
let(:ezid) { "ark:/99999/dsp01qb98mj541" }

around do |example|
Rails.configuration.update_ark_url = true
Expand All @@ -105,13 +96,6 @@
expect(work.persisted?).to be true
expect(work.ark).to eq(ezid)
end

it "updates the ARK metadata" do
work.ark = ezid
work.save

expect(identifier).to have_received(:modify)
end
end

context "and when the ARK is invalid" do
Expand All @@ -129,6 +113,24 @@
end
end

context "when updating the ARK" do
before { allow(Ark).to receive(:update) }
let(:ezid) { "ark:/99999/dsp01qb98mj541" }

around do |example|
Rails.configuration.update_ark_url = true
example.run
Rails.configuration.update_ark_url = false
end

it "updates the ARK metadata" do
work.ark = ezid
work.save
# one on create + one on update
expect(Ark).to have_received(:update).exactly(2).times
end
end

it "returns datasets waiting for approval depending on the user" do
described_class.create_dataset("test title", user.id, collection.id)
described_class.create_dataset("test title", user_other.id, collection.id)
Expand Down
3 changes: 2 additions & 1 deletion spec/system/accessibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
it "complies with WCAG 2.0 AA and Section 508" do
datacite_resource = PULDatacite::Resource.new(title: "Test dataset")
datacite_resource.creators << PULDatacite::Creator.new_person("Harriet", "Tubman", "1234-5678-9012-3456")
work = Work.create_dataset("Test dataset", user.id, user.default_collection_id, datacite_resource)
ark = "ark:/99999/dsp01qb98mj541"
work = Work.create_dataset("Test dataset", user.id, user.default_collection_id, datacite_resource, ark)
visit work_path(work)
expect(page).to be_axe_clean
.according_to(:wcag2a, :wcag2aa, :wcag21a, :wcag21aa, :section508)
Expand Down
6 changes: 3 additions & 3 deletions spec/system/work_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
sign_in user
visit new_work_path
expect(page).to have_content "ARK"
click_on "Update Work"
click_on "Save Work"
expect(page).to have_content "ARK"
expect(page).to have_content Work.last.ark
end
Expand All @@ -24,7 +24,7 @@
sign_in user
visit new_work_path
fill_in "title_main", with: ""
click_on "Update Work"
click_on "Save Work"
expect(page).to have_content "Must provide a title"
end

Expand All @@ -33,7 +33,7 @@
sign_in user
visit new_work_path
click_on "Creator(s)"
click_on "Add Creator"
click_on "Add Another Creator"
within("#creator_row_1") do
fill_in "orcid_1", with: "0000-0000-1111-2222"
end
Expand Down

0 comments on commit d017d10

Please sign in to comment.