Skip to content
Merged
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
2 changes: 2 additions & 0 deletions app/controllers/account/renewals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ def create

renew_loan(@loan)
redirect_to account_loans_path, success: "#{@loan.item.name} was renewed.", status: :see_other
rescue Pundit::NotAuthorizedError
redirect_to account_loans_path, warning: "This loan can no longer be renewed.", status: :see_other
end
end
end
12 changes: 6 additions & 6 deletions test/controllers/account/renewals_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ class RenewalsControllerTest < ActionDispatch::IntegrationTest
end

test "member cannot renew a non-renewable loan" do
assert_raises Pundit::NotAuthorizedError do
post account_renewals_url(loan_id: @loan1)
end
post account_renewals_url(loan_id: @loan1)
assert_redirected_to account_loans_url
assert_equal "This loan can no longer be renewed.", flash[:warning]
end

test "member cannot renew another member's loan" do
assert_raises Pundit::NotAuthorizedError do
post account_renewals_url(loan_id: @loan2)
end
post account_renewals_url(loan_id: @loan2)
assert_redirected_to account_loans_url
assert_equal "This loan can no longer be renewed.", flash[:warning]
end
end
end
Loading