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

Commit

Permalink
Merge pull request #1546 from YaleSTC/1544_request_prompt
Browse files Browse the repository at this point in the history
[1544] Request text is now shown after invalid cart edit
  • Loading branch information
orenyk committed Apr 19, 2016
2 parents f535152 + b616d44 commit 1a8dfaa
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# rubocop:disable ClassLength
class CatalogController < ApplicationController
helper ReservationsHelper # for request_text
layout 'application_with_sidebar'

before_action :set_equipment_model, only:
Expand Down
10 changes: 1 addition & 9 deletions app/controllers/reservations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ def view_all_dates
def show
end

# rubocop:disable BlockNesting
def new # rubocop:disable MethodLength, PerceivedComplexity
def new # rubocop:disable MethodLength
if cart.items.empty?
flash[:error] = 'You need to add items to your cart before making a '\
'reservation.'
Expand All @@ -119,12 +118,6 @@ def new # rubocop:disable MethodLength, PerceivedComplexity
flash[:error] = 'Please review the errors below. If uncorrected, '\
'any reservations with errors will be filed as a request, and '\
'subject to administrator approval.'
if AppConfig.get(:request_text).empty?
@request_text = 'Please give a short justification for this '\
'equipment request.'
else
@request_text = AppConfig.get(:request_text)
end
end
end

Expand All @@ -134,7 +127,6 @@ def new # rubocop:disable MethodLength, PerceivedComplexity
reserver_id: cart.reserver_id)
end
end
# rubocop:enable BlockNesting

def create # rubocop:disable all
@errors = cart.validate_all
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/reservations_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ def manage_reservations_btn # rubocop:disable all
end
end

def request_text
if AppConfig.get(:request_text).empty?
'Please give a short justification for this equipment request.'
else
AppConfig.get(:request_text)
end
end

private

# the "+ 1" terms are to account for the fact that the first
Expand Down
2 changes: 1 addition & 1 deletion app/views/reservations/_new_request.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</p>
<%= render partial: 'reservations/edit_reservation_form' %>
<div class="well">
<%= markdown(@request_text) %>
<%= markdown(request_text) %>
</div>
<%= simple_form_for @reservation do |f| %>
<div class="form-group text <%= 'error' if @notes_required %>">
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/app_configs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
send_notifications_for_deleted_missed_reservations true
notify_admin_on_create false
checkout_persons_can_edit false
request_text ''
request_text 'tell me whyyy?'
end
end
2 changes: 2 additions & 0 deletions spec/features/reservations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@
quantity_forms[1].submit_form!
# loading right page
expect(page).to have_content 'Confirm Reservation Request'
expect(page).to have_content AppConfig.get(:request_text)
# changes applied
expect(page).to \
have_selector("input[value='#{@eq_model.max_per_user + 1}']")
Expand Down Expand Up @@ -680,6 +681,7 @@
find('#dates_form').submit_form!
# loads right page
expect(page).to have_content 'Confirm Reservation Request'
expect(page).to have_content AppConfig.get(:request_text)
# has altered date
expect(page).to have_selector("input[value='#{bad_due_date}']")
end
Expand Down

0 comments on commit 1a8dfaa

Please sign in to comment.