Skip to content
This repository was archived by the owner on Jul 24, 2020. It is now read-only.

Commit 1a8dfaa

Browse files
committed
Merge pull request #1546 from YaleSTC/1544_request_prompt
[1544] Request text is now shown after invalid cart edit
2 parents f535152 + b616d44 commit 1a8dfaa

File tree

6 files changed

+14
-11
lines changed

6 files changed

+14
-11
lines changed

app/controllers/catalog_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# rubocop:disable ClassLength
22
class CatalogController < ApplicationController
3+
helper ReservationsHelper # for request_text
34
layout 'application_with_sidebar'
45

56
before_action :set_equipment_model, only:

app/controllers/reservations_controller.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ def view_all_dates
101101
def show
102102
end
103103

104-
# rubocop:disable BlockNesting
105-
def new # rubocop:disable MethodLength, PerceivedComplexity
104+
def new # rubocop:disable MethodLength
106105
if cart.items.empty?
107106
flash[:error] = 'You need to add items to your cart before making a '\
108107
'reservation.'
@@ -119,12 +118,6 @@ def new # rubocop:disable MethodLength, PerceivedComplexity
119118
flash[:error] = 'Please review the errors below. If uncorrected, '\
120119
'any reservations with errors will be filed as a request, and '\
121120
'subject to administrator approval.'
122-
if AppConfig.get(:request_text).empty?
123-
@request_text = 'Please give a short justification for this '\
124-
'equipment request.'
125-
else
126-
@request_text = AppConfig.get(:request_text)
127-
end
128121
end
129122
end
130123

@@ -134,7 +127,6 @@ def new # rubocop:disable MethodLength, PerceivedComplexity
134127
reserver_id: cart.reserver_id)
135128
end
136129
end
137-
# rubocop:enable BlockNesting
138130

139131
def create # rubocop:disable all
140132
@errors = cart.validate_all

app/helpers/reservations_helper.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ def manage_reservations_btn # rubocop:disable all
5757
end
5858
end
5959

60+
def request_text
61+
if AppConfig.get(:request_text).empty?
62+
'Please give a short justification for this equipment request.'
63+
else
64+
AppConfig.get(:request_text)
65+
end
66+
end
67+
6068
private
6169

6270
# the "+ 1" terms are to account for the fact that the first

app/views/reservations/_new_request.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</p>
2424
<%= render partial: 'reservations/edit_reservation_form' %>
2525
<div class="well">
26-
<%= markdown(@request_text) %>
26+
<%= markdown(request_text) %>
2727
</div>
2828
<%= simple_form_for @reservation do |f| %>
2929
<div class="form-group text <%= 'error' if @notes_required %>">

spec/factories/app_configs.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
send_notifications_for_deleted_missed_reservations true
2626
notify_admin_on_create false
2727
checkout_persons_can_edit false
28-
request_text ''
28+
request_text 'tell me whyyy?'
2929
end
3030
end

spec/features/reservations_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@
597597
quantity_forms[1].submit_form!
598598
# loading right page
599599
expect(page).to have_content 'Confirm Reservation Request'
600+
expect(page).to have_content AppConfig.get(:request_text)
600601
# changes applied
601602
expect(page).to \
602603
have_selector("input[value='#{@eq_model.max_per_user + 1}']")
@@ -680,6 +681,7 @@
680681
find('#dates_form').submit_form!
681682
# loads right page
682683
expect(page).to have_content 'Confirm Reservation Request'
684+
expect(page).to have_content AppConfig.get(:request_text)
683685
# has altered date
684686
expect(page).to have_selector("input[value='#{bad_due_date}']")
685687
end

0 commit comments

Comments
 (0)