From b60e2aebe3bec21937cd7e8e24b7ab6b136187a1 Mon Sep 17 00:00:00 2001 From: Dennis Deli Date: Mon, 6 Jan 2025 16:34:47 -0500 Subject: [PATCH] first commit --- test/controllers/home_controller_test.rb | 9 ++++++ test/controllers/items_controller_test.rb | 12 +++++++ .../request_wizard_controller_test.rb | 32 ++++++++++++++++++- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/test/controllers/home_controller_test.rb b/test/controllers/home_controller_test.rb index efd0eb9..da609a2 100644 --- a/test/controllers/home_controller_test.rb +++ b/test/controllers/home_controller_test.rb @@ -80,6 +80,15 @@ class HomeControllerTest < ActionDispatch::IntegrationTest requests = get_instance_var(:requests) assert_equal 3, requests.size, 'Should only be 1 cancelled' end + + should 'default location name is "All locations"' do + get root_path, params: { which: Request::OPEN, page: 1, location: 'all' } + + assert_select 'button.dropdown-toggle', text: 'All Locations' + + assert_select 'ul.dropdown-menu li:first-child a', text: 'All Locations' + end + end context 'User' do diff --git a/test/controllers/items_controller_test.rb b/test/controllers/items_controller_test.rb index 66413fc..507329b 100644 --- a/test/controllers/items_controller_test.rb +++ b/test/controllers/items_controller_test.rb @@ -34,6 +34,18 @@ class ItemsControllerTest < ActionDispatch::IntegrationTest end end + should 'create a new item with other_isbn_issn' do + assert_difference('Item.count') do + post request_items_path(@_request), params: { + item: attributes_for(:item, other_isbn_issn: '1234-5678').except(:request) + } + item = get_instance_var(:item) + assert_equal 0, item.errors.size, "Should be no errors, #{item.errors.messages}" + assert_redirected_to request_item_path(@_request, item) + assert_equal '1234-5678', item.other_isbn_issn, 'other_isbn_issn should match' + end + end + should 'send en email to location email, after item created, if enabled' do @_request.location.setting_bcc_location_on_new_item = true @_request.location.save diff --git a/test/controllers/request_wizard_controller_test.rb b/test/controllers/request_wizard_controller_test.rb index e3653f1..e9528b2 100644 --- a/test/controllers/request_wizard_controller_test.rb +++ b/test/controllers/request_wizard_controller_test.rb @@ -62,8 +62,23 @@ class RequestWizardControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_equal 1, request.errors.size, "Should be 1 error, #{request.errors.messages.inspect}" -end + end + + should 'handle empty new request' do + assert_no_difference('Request.count') do + request_attributes = attributes_for(:request, reserve_location_id: @location.id) + request_attributes[:course_attributes] = attributes_for(:course, name: '', code: '') + request_attributes[:user] = { office: '', department: '', phone: '' } + + post new_request_step_one_save_path, params: { request: request_attributes } + request = get_instance_var(:request) + assert_not_empty request.errors, 'There should be validation errors' + assert_response :success + assert_match /can't be blank/, @response.body + end + + end should 'load the request and any items, if comping back to this' do request = create(:request, status: Request::INCOMPLETE) @@ -96,4 +111,19 @@ class RequestWizardControllerTest < ActionDispatch::IntegrationTest assert_response :redirect assert_redirected_to request_path(request), 'Show request details' end + + test 'should not allow finishing the request without items' do + request = create(:request, status: Request::INCOMPLETE) + + get new_request_step_two_path(request) + assert_response :success + assert_match /Save this request for later/, @response.body + assert_no_match /I am done, submit this request/, @response.body + + post new_request_finish_path(request) + assert_redirected_to new_request_step_two_path(request) + follow_redirect! + assert_match /You must add at least one active item for this request to be submitted!/, @response.body + end + end