Skip to content

Commit

Permalink
allow YYYY for date_issued
Browse files Browse the repository at this point in the history
  • Loading branch information
rococodogs committed Dec 2, 2019
1 parent f7b2bd1 commit 03a2f9b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/validators/spot/date_issued_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def validate(record)
record.errors[:date_issued] << 'Date Issued may only contain one value' if record.date_issued.size > 1

record.date_issued.each do |date|
record.errors[:date_issued] << 'Date Issued must be in YYYY-MM-DD or YYYY-MM format' unless
date.match?(/\A\d{4}-\d{2}(-\d{2})?\z/)
record.errors[:date_issued] << 'Date Issued must be in YYYY-MM-DD, YYYY-MM, or YYYY format' unless
date.match?(/\A\d{4}(-\d{2}){0,2}\z/)
end
end
end
Expand Down
13 changes: 6 additions & 7 deletions spec/models/publication_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,6 @@
expect(pub.errors[:date_issued]).to include 'Date Issued must be in YYYY-MM-DD or YYYY-MM format'
end

it 'can not be YYYY' do
pub.date_issued = ['2019']

expect(pub.valid?).to be false
expect(pub.errors[:date_issued]).to include 'Date Issued must be in YYYY-MM-DD or YYYY-MM format'
end

it 'can not have multiple values' do
pub.date_issued = ['2019-09-21', '2019-11-19']

Expand All @@ -133,6 +126,12 @@
end
end

it 'can be YYYY' do
pub.date_issued = ['2019']

expect(pub.valid?).to be true
end

describe 'rights_statement' do
it 'must be present' do
pub.rights_statement = []
Expand Down

0 comments on commit 03a2f9b

Please sign in to comment.