Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds validation that page_range can only be up to 30 characrters #1114

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/requests/scan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/scans/_form_additional.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<%= f.label :page_range, class: "#{label_column_class} control-label" %>
<div class='<%= content_column_class %>'>
<%= f.text_field_without_bootstrap :page_range, class: 'form-control', aria: { describedby: 'page_range_help_block' } %>
<span class="help-block" id="page_range_help_block">Examples: '1-15, 25-30' or '249-275, index'</span>
<span class="help-block" id="page_range_help_block">Examples: '1-15, 25-30' or '249-275, index'; Up to 30 characters.</span>
</div>
</div>
<%= f.text_area :section_title, rows: '3', required: true %>
Expand Down
20 changes: 18 additions & 2 deletions spec/models/requests/scan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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))

Expand All @@ -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
Expand Down