diff --git a/app/validators/spot/date_issued_validator.rb b/app/validators/spot/date_issued_validator.rb index 520d6d692..542c9b710 100644 --- a/app/validators/spot/date_issued_validator.rb +++ b/app/validators/spot/date_issued_validator.rb @@ -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 diff --git a/spec/models/publication_spec.rb b/spec/models/publication_spec.rb index 7f9632c59..692b3c2d5 100644 --- a/spec/models/publication_spec.rb +++ b/spec/models/publication_spec.rb @@ -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'] @@ -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 = []