Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Fix validation message when bad doi entered for primary article
Browse files Browse the repository at this point in the history
  • Loading branch information
sfisher committed Jul 8, 2022
1 parent a338d01 commit 5f9b5ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
13 changes: 10 additions & 3 deletions app/models/stash_datacite/resource/dataset_validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,16 @@ def article_id
@resource.identifier.manuscript_number.blank? &&
@resource.identifier.publication_article_doi.blank?

ErrorItem.new(message: "Fill in a {manuscript number or DOI} for the article from #{@resource.identifier.publication_name}",
page: metadata_page(@resource),
ids: %w[msid primary_article_doi])
if @resource.related_identifiers.where(work_type: 'primary_article').count.positive? # has primary, but not doi
ErrorItem.new(message: "Fill in {a correctly formatted DOI} for your article from #{@resource.identifier
.publication_name}",
page: metadata_page(@resource),
ids: %w[primary_article_doi])
else
ErrorItem.new(message: "Fill in a {manuscript number or DOI} for the article from #{@resource.identifier.publication_name}",
page: metadata_page(@resource),
ids: %w[msid primary_article_doi])
end
end

def s3_error_uploads
Expand Down
13 changes: 13 additions & 0 deletions spec/models/stash_datacite/dataset_validations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ module Resource
expect(error.ids).to eq(%w[msid primary_article_doi])
end

it 'gives a formatting error when someone puts in a URL instead of a DOI' do
StashEngine::InternalDatum.create(data_type: 'publicationName',
value: 'Barrel of Monkeys: the Primate Journal',
identifier_id: @resource.identifier_id)
create(:related_identifier, resource_id: @resource.id, related_identifier_type: 'url', work_type:
'primary_article')
validations = DatasetValidations.new(resource: @resource)
error = validations.article_id

expect(error.message).to include('formatted DOI')
expect(error.ids).to eq(%w[primary_article_doi])
end

it "doesn't give error if manuscript filled" do
StashEngine::InternalDatum.create(data_type: 'publicationName',
value: 'Barrel of Monkeys: the Primate Journal',
Expand Down

0 comments on commit 5f9b5ac

Please sign in to comment.