diff --git a/app/models/requests/scan.rb b/app/models/requests/scan.rb index dbf918a95..b312eeaf3 100644 --- a/app/models/requests/scan.rb +++ b/app/models/requests/scan.rb @@ -6,6 +6,7 @@ class Scan < Request validate :scannable_validator validates :section_title, presence: true + validates :page_range, length: { maximum: 30 } def requestable_with_sunet_only? true diff --git a/app/views/scans/_form_additional.html.erb b/app/views/scans/_form_additional.html.erb index bf8299922..054671cc1 100644 --- a/app/views/scans/_form_additional.html.erb +++ b/app/views/scans/_form_additional.html.erb @@ -2,7 +2,7 @@ <%= f.label :page_range, class: "#{label_column_class} control-label" %>
<%= f.text_field_without_bootstrap :page_range, class: 'form-control', aria: { describedby: 'page_range_help_block' } %> - Examples: '1-15, 25-30' or '249-275, index' + Examples: '1-15, 25-30' or '249-275, index'; Up to 30 characters.
<%= f.text_area :section_title, rows: '3', required: true %> diff --git a/spec/models/requests/scan_spec.rb b/spec/models/requests/scan_spec.rb index 5748e6ed2..2d13f2d8d 100644 --- a/spec/models/requests/scan_spec.rb +++ b/spec/models/requests/scan_spec.rb @@ -9,7 +9,7 @@ it 'validates based on if the item is scannable or not' do expect do - described_class.create!(item_id: '1234', + described_class.create!(item_id: '123', origin: 'GREEN', origin_location: 'STACKS', section_title: 'Some chapter title') @@ -18,6 +18,21 @@ ) end + it 'validates that the page range length is 30 charachters or less' do + expect do + described_class.create!( + item_id: '1234', + origin: 'SAL3', + origin_location: 'STACKS', + section_title: 'Some chapter title', + page_range: 'pages 1-30 and then some long comment describing something more specific about the specified range.' + ) + end.to raise_error( + ActiveRecord::RecordInvalid, + 'Validation failed: This item is not scannable, Page range is too long (maximum is 30 characters)' + ) + end + it 'allows temporary access materials to be requested for scan' do stub_searchworks_api_json(build(:temporary_access_holdings)) @@ -39,7 +54,8 @@ item_id: '123456', origin: 'SAL', origin_location: 'SAL-TEMP', - section_title: 'Chapter 1' + section_title: 'Chapter 1', + page_range: 'pages 1-30' ) end.not_to raise_error end