Skip to content

Commit 879b4f1

Browse files
Hide Cancel button on fulfilled requests
Cancelling a fulfilled request returns a validation error: "Status cannot be changed once fulfilled". Since fulfilled requests cannot be cancelled, to prevent raising an error, this commit hides the Cancel button for fulfilled requests.
1 parent 604088d commit 879b4f1

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

app/views/requests/show.html.erb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@
107107
<%= submit_button_to start_request_path(@request), {text: "Fulfill request", size: "md"} unless @request.distribution %>
108108
<%= view_button_to(distribution_path(@request.distribution), {text: "View Associated Distribution", size: "md"}) if @request.distribution %>
109109
<%= print_button_to print_picklist_request_path(@request), { format: :pdf, text: "Print", size: "md" } %>
110-
<%= button_to 'Cancel', new_request_cancelation_path(request_id: @request.id),
111-
method: :get, data: { disable_with: "Please wait..." }, form_class: 'd-inline', class: 'btn btn-danger btn-md' %>
110+
<% unless @request.status_fulfilled? %>
111+
<%= button_to 'Cancel', new_request_cancelation_path(request_id: @request.id),
112+
method: :get, data: { disable_with: "Please wait..." }, form_class: 'd-inline', class: 'btn btn-danger btn-md' %>
113+
<% end %>
112114
</div>
113115
</div>
114116
</div>

spec/requests/requests_requests_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,19 @@
156156
expect(response.body).not_to include('Units (if applicable)')
157157
end
158158
end
159+
160+
context 'when the request has a Fulfilled status' do
161+
it 'does not display the Cancel button' do
162+
fulfilled_request = create(:request, :fulfilled)
163+
164+
get requests_path(fulfilled_request)
165+
166+
page = Nokogiri::HTML(response.body)
167+
cancel_button = page.at_css('button') { |el| el.text.strip == 'Cancel' }
168+
169+
expect(cancel_button).not_to be_present
170+
end
171+
end
159172
end
160173

161174
describe 'POST #start' do

0 commit comments

Comments
 (0)