From 23c99fe970978d81841d0ee3e9d4317bba644b36 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Thu, 18 Jan 2024 12:03:34 -0500 Subject: [PATCH] Remove old style controller json (#921) * use whats built into Rails! * trim down some files that we don't use --- .rubocop.yml | 3 --- app/views/layouts/_footer_core_app.html.erb | 4 ++++ .../analytics/tries_visualization_test.rb | 2 +- .../api/v1/annotations_controller_test.rb | 14 ++++++------ .../api/v1/books_controller_test.rb | 2 +- .../api/v1/bulk/queries_controller_test.rb | 2 +- .../api/v1/case_scorers_controller_test.rb | 2 +- .../api/v1/case_scores_controller_test.rb | 2 +- .../api/v1/cases_controller_test.rb | 12 +++++----- .../information_needs_controller_test.rb | 2 +- .../v1/queries/positions_controller_test.rb | 10 ++++----- .../api/v1/queries_controller_test.rb | 22 +++++++++---------- .../api/v1/query_doc_pairs_controller_test.rb | 2 +- .../api/v1/scorers_controller_test.rb | 4 ++-- .../api/v1/snapshots_controller_test.rb | 4 ++-- .../api/v1/team_members_controller_test.rb | 2 +- .../api/v1/tries_controller_test.rb | 16 +++++++------- .../api/v1/users_controller_test.rb | 22 +++++++++---------- test/controllers/sessions_controller_test.rb | 2 +- 19 files changed, 65 insertions(+), 64 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index d99b890d3..4fb654e46 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,10 +11,7 @@ AllCops: - bin/**/* - vendor/**/* - node_modules/**/* - - lib/templates/rails/jbuilder/index.json.jbuilder - - lib/railgun/mailer_decorator.rb - config/initializers/content_security_policy.rb - - test/support/json_response.rb Capybara/ClickLinkOrButtonStyle: Enabled: false # we aren't running system tests diff --git a/app/views/layouts/_footer_core_app.html.erb b/app/views/layouts/_footer_core_app.html.erb index c6214757c..6b93a80b8 100644 --- a/app/views/layouts/_footer_core_app.html.erb +++ b/app/views/layouts/_footer_core_app.html.erb @@ -20,6 +20,10 @@ url: Rails.application.config.cookies_url, text: 'Cookies Policy', }, + { + url: 'apipie/', + text: 'API', + }, ] %> <% footer_links.each do |link| %> diff --git a/test/controllers/analytics/tries_visualization_test.rb b/test/controllers/analytics/tries_visualization_test.rb index e3c784c95..0dc0cb0a7 100644 --- a/test/controllers/analytics/tries_visualization_test.rb +++ b/test/controllers/analytics/tries_visualization_test.rb @@ -19,7 +19,7 @@ class TriesVisualizationControllerTest < ActionController::TestCase assert_response :ok - tries = json_response + tries = response.parsed_body assert_equal 2, tries.size tries.each do |json_try| diff --git a/test/controllers/api/v1/annotations_controller_test.rb b/test/controllers/api/v1/annotations_controller_test.rb index a320fac04..368d099da 100644 --- a/test/controllers/api/v1/annotations_controller_test.rb +++ b/test/controllers/api/v1/annotations_controller_test.rb @@ -40,7 +40,7 @@ class AnnotationsControllerTest < ActionController::TestCase assert_response :ok - assert_equal data[:score][:score], json_response['score']['score'] + assert_equal data[:score][:score], response.parsed_body['score']['score'] end end @@ -83,10 +83,10 @@ class AnnotationsControllerTest < ActionController::TestCase assert_response :ok - assert_equal user.id, json_response['user_id'] - assert_equal 'message', json_response['message'] + assert_equal user.id, response.parsed_body['user_id'] + assert_equal 'message', response.parsed_body['message'] - assert_not_nil json_response['score'] + assert_not_nil response.parsed_body['score'] end end end @@ -151,12 +151,12 @@ class AnnotationsControllerTest < ActionController::TestCase assert_response :ok - assert_equal 1, json_response['annotations'].count + assert_equal 1, response.parsed_body['annotations'].count - ids = json_response['annotations'].map { |each| each['id'] } + ids = response.parsed_body['annotations'].map { |each| each['id'] } assert_includes ids, annotation.id - the_annotation = json_response['annotations'].first + the_annotation = response.parsed_body['annotations'].first assert_equal annotation.score.score, the_annotation['score']['score'] assert_equal annotation.score.try_id, the_annotation['score']['try_id'] diff --git a/test/controllers/api/v1/books_controller_test.rb b/test/controllers/api/v1/books_controller_test.rb index 84671d7bc..57461a1ea 100644 --- a/test/controllers/api/v1/books_controller_test.rb +++ b/test/controllers/api/v1/books_controller_test.rb @@ -32,7 +32,7 @@ class BooksControllerTest < ActionController::TestCase assert_response :ok - assert_equal json_response['name'], book_name + assert_equal response.parsed_body['name'], book_name assert_equal doug.books_involved_with.count, count + 1 end diff --git a/test/controllers/api/v1/bulk/queries_controller_test.rb b/test/controllers/api/v1/bulk/queries_controller_test.rb index 3461ecd4c..0fbe8ed14 100644 --- a/test/controllers/api/v1/bulk/queries_controller_test.rb +++ b/test/controllers/api/v1/bulk/queries_controller_test.rb @@ -45,7 +45,7 @@ class QueriesControllerTest < ActionController::TestCase first_query = acase.queries[0] assert_equal 'one', first_query.query_text - assert_equal json_response['display_order'][0], first_query.id + assert_equal response.parsed_body['display_order'][0], first_query.id end test 'doesnt allow duplicate queries to be created' do diff --git a/test/controllers/api/v1/case_scorers_controller_test.rb b/test/controllers/api/v1/case_scorers_controller_test.rb index 079aef35c..f978ba5bf 100644 --- a/test/controllers/api/v1/case_scorers_controller_test.rb +++ b/test/controllers/api/v1/case_scorers_controller_test.rb @@ -72,7 +72,7 @@ class CaseScorersControllerTest < ActionController::TestCase assert_response :bad_request - assert_equal json_response['scorer_id'], [ 'is not valid' ] + assert_equal response.parsed_body['scorer_id'], [ 'is not valid' ] acase.reload diff --git a/test/controllers/api/v1/case_scores_controller_test.rb b/test/controllers/api/v1/case_scores_controller_test.rb index a1c1b622b..9a4e53ae3 100644 --- a/test/controllers/api/v1/case_scores_controller_test.rb +++ b/test/controllers/api/v1/case_scores_controller_test.rb @@ -205,7 +205,7 @@ class CaseScoresControllerTest < ActionController::TestCase assert_equal assigns(:shallow), false assert_equal @last_score.id, json_response['id'] - assert_not_nil json_response['queries'] + assert_not_nil response.parsed_body['queries'] assert_equal @last_score.queries, json_response['queries'] end end diff --git a/test/controllers/api/v1/cases_controller_test.rb b/test/controllers/api/v1/cases_controller_test.rb index 977e55a17..e114fb555 100644 --- a/test/controllers/api/v1/cases_controller_test.rb +++ b/test/controllers/api/v1/cases_controller_test.rb @@ -28,7 +28,7 @@ class CasesControllerTest < ActionController::TestCase assert_response :ok - assert_equal json_response['case_name'], case_name + assert_equal response.parsed_body['case_name'], case_name assert_equal joe.cases.count, count + 1 assert_equal joe.cases.first.case_name, case_name end @@ -49,7 +49,7 @@ class CasesControllerTest < ActionController::TestCase assert_response :ok - assert_equal json_response['case_name'], case_name + assert_equal response.parsed_body['case_name'], case_name acase = Case.where(case_name: case_name).first assert_equal 1, acase.tries.count @@ -430,7 +430,7 @@ class CasesControllerTest < ActionController::TestCase assert_response :ok - cases = json_response['all_cases'] + cases = response.parsed_body['all_cases'] ids = cases.map { |c| c['case_id'] } @@ -447,7 +447,7 @@ class CasesControllerTest < ActionController::TestCase assert_response :ok - cases = json_response['all_cases'] + cases = response.parsed_body['all_cases'] ids = cases.map { |c| c['case_id'] } @@ -513,7 +513,7 @@ class CasesControllerTest < ActionController::TestCase assert_response :ok - cases = json_response['all_cases'] + cases = response.parsed_body['all_cases'] names = cases.map { |c| c['case_name'] } assert_not_includes names, shared.case_name @@ -614,7 +614,7 @@ class CasesControllerTest < ActionController::TestCase assert_response :bad_request - assert_equal json_response['scorer_id'], [ 'is not valid' ] + assert_equal response.parsed_body['scorer_id'], [ 'is not valid' ] one.reload assert_equal one.scorer, scorer diff --git a/test/controllers/api/v1/import/queries/information_needs_controller_test.rb b/test/controllers/api/v1/import/queries/information_needs_controller_test.rb index 19e86389e..90ff77a80 100644 --- a/test/controllers/api/v1/import/queries/information_needs_controller_test.rb +++ b/test/controllers/api/v1/import/queries/information_needs_controller_test.rb @@ -129,7 +129,7 @@ class InformationNeedsControllerTest < ActionController::TestCase post :create, params: { case_id: acase.id, csv_text: csv_text } assert_response :unprocessable_entity - assert_equal "Didn't find this query for the case: boxing movie", json_response['message'] + assert_equal "Didn't find this query for the case: boxing movie", response.parsed_body['message'] end end diff --git a/test/controllers/api/v1/queries/positions_controller_test.rb b/test/controllers/api/v1/queries/positions_controller_test.rb index 43d1919d9..9d3306004 100644 --- a/test/controllers/api/v1/queries/positions_controller_test.rb +++ b/test/controllers/api/v1/queries/positions_controller_test.rb @@ -38,7 +38,7 @@ class PositionsControllerTest < ActionController::TestCase assert_response :ok - display_order = json_response['display_order'] + display_order = response.parsed_body['display_order'] assert_equal query.id, display_order[1] assert_equal second.id, display_order[0] @@ -52,7 +52,7 @@ class PositionsControllerTest < ActionController::TestCase assert_response :ok - display_order = json_response['display_order'] + display_order = response.parsed_body['display_order'] assert_equal query.id, display_order[0] assert_equal second.id, display_order[1] @@ -66,7 +66,7 @@ class PositionsControllerTest < ActionController::TestCase assert_response :ok - display_order = json_response['display_order'] + display_order = response.parsed_body['display_order'] assert_equal query.id, display_order.last end @@ -79,7 +79,7 @@ class PositionsControllerTest < ActionController::TestCase assert_response :ok - display_order = json_response['display_order'] + display_order = response.parsed_body['display_order'] assert_equal query.id, display_order[2] assert_equal second.id, display_order[1] @@ -93,7 +93,7 @@ class PositionsControllerTest < ActionController::TestCase assert_response :ok - display_order = json_response['display_order'] + display_order = response.parsed_body['display_order'] assert_equal query.id, display_order[1] assert_equal second.id, display_order[2] diff --git a/test/controllers/api/v1/queries_controller_test.rb b/test/controllers/api/v1/queries_controller_test.rb index 5cdab0fca..31a1a2869 100644 --- a/test/controllers/api/v1/queries_controller_test.rb +++ b/test/controllers/api/v1/queries_controller_test.rb @@ -21,7 +21,7 @@ class QueriesControllerTest < ActionController::TestCase assert_response :bad_request - assert_includes json_response['query_text'], "can't be blank" + assert_includes response.parsed_body['query_text'], "can't be blank" end test 'to the end of the query list if no position is provided' do @@ -30,7 +30,7 @@ class QueriesControllerTest < ActionController::TestCase assert_response :ok - query_response = json_response['query'] + query_response = response.parsed_body['query'] assert_not_nil query_response['query_id'] assert_equal query_response['arranged_at'], 0 @@ -48,7 +48,7 @@ class QueriesControllerTest < ActionController::TestCase assert_response :ok - display_order = json_response['display_order'] + display_order = response.parsed_body['display_order'] assert_not_nil display_order assert_instance_of Array, display_order @@ -61,7 +61,7 @@ class QueriesControllerTest < ActionController::TestCase assert_response :ok - query_response = json_response['query'] + query_response = response.parsed_body['query'] assert_not_nil query_response['query_id'] assert_equal query_response['query_text'], query_text @@ -79,7 +79,7 @@ class QueriesControllerTest < ActionController::TestCase assert_response :ok - query_response = json_response['query'] + query_response = response.parsed_body['query'] assert_not_nil query_response['query_id'] assert_equal query_response['arranged_at'], 0 @@ -92,7 +92,7 @@ class QueriesControllerTest < ActionController::TestCase assert_response :ok - query_response = json_response['query'] + query_response = response.parsed_body['query'] assert_not_nil query_response['query_id'] assert_equal query_response['arranged_at'], 0 @@ -117,7 +117,7 @@ class QueriesControllerTest < ActionController::TestCase assert_response :ok - query_response = json_response['query'] + query_response = response.parsed_body['query'] assert_not_nil query_response['query_id'] assert_equal query_response['arranged_at'], 0 @@ -144,7 +144,7 @@ class QueriesControllerTest < ActionController::TestCase assert_response :ok - query_response = json_response['query'] + query_response = response.parsed_body['query'] assert_equal query_response['query_text'], query_text end @@ -156,7 +156,7 @@ class QueriesControllerTest < ActionController::TestCase assert_response :ok - query_response = json_response(true)['query'] + query_response = response.parsed_body['query'] assert_equal query_response['query_text'], query_text end @@ -168,7 +168,7 @@ class QueriesControllerTest < ActionController::TestCase assert_response :ok - query_response = json_response(true)['query'] + query_response = response.parsed_body['query'] assert_equal query_response['query_text'], query_text end @@ -180,7 +180,7 @@ class QueriesControllerTest < ActionController::TestCase assert_response :ok - query_response = json_response(true)['query'] + query_response = response.parsed_body['query'] assert_equal query_response['query_text'], query_text end diff --git a/test/controllers/api/v1/query_doc_pairs_controller_test.rb b/test/controllers/api/v1/query_doc_pairs_controller_test.rb index e53621535..5c7ecd472 100644 --- a/test/controllers/api/v1/query_doc_pairs_controller_test.rb +++ b/test/controllers/api/v1/query_doc_pairs_controller_test.rb @@ -36,7 +36,7 @@ class QueryDocPairsControllerTest < ActionController::TestCase assert_response :ok - assert_equal json_response['doc_id'], qdp.doc_id + assert_equal response.parsed_body['doc_id'], qdp.doc_id assert_equal book.query_doc_pairs.count, count + 1 end diff --git a/test/controllers/api/v1/scorers_controller_test.rb b/test/controllers/api/v1/scorers_controller_test.rb index e68009e5e..9b1198b20 100644 --- a/test/controllers/api/v1/scorers_controller_test.rb +++ b/test/controllers/api/v1/scorers_controller_test.rb @@ -20,7 +20,7 @@ class ScorersControllerTest < ActionController::TestCase assert_response :ok - scorer = json_response + scorer = response.parsed_body assert_not_nil scorer['scorer_id'] assert_nil scorer['code'] @@ -42,7 +42,7 @@ class ScorersControllerTest < ActionController::TestCase assert_response :ok - scorer = json_response + scorer = response.parsed_body regex = /Scorer/ assert_match regex, scorer['name'] diff --git a/test/controllers/api/v1/snapshots_controller_test.rb b/test/controllers/api/v1/snapshots_controller_test.rb index 22d247543..ff9d07150 100644 --- a/test/controllers/api/v1/snapshots_controller_test.rb +++ b/test/controllers/api/v1/snapshots_controller_test.rb @@ -174,7 +174,7 @@ class SnapshotsControllerTest < ActionController::TestCase assert_response :ok - assert_equal json_response['name'], "Snapshot #{Time.zone.now.strftime('%D')}" + assert_equal response.parsed_body['name'], "Snapshot #{Time.zone.now.strftime('%D')}" end data = { @@ -207,7 +207,7 @@ class SnapshotsControllerTest < ActionController::TestCase assert_response :ok - assert_equal json_response(true)['name'], "Snapshot #{Time.zone.now.strftime('%D')}" + assert_equal response.parsed_body['name'], "Snapshot #{Time.zone.now.strftime('%D')}" end end diff --git a/test/controllers/api/v1/team_members_controller_test.rb b/test/controllers/api/v1/team_members_controller_test.rb index 5ab5c5dc2..6c0ae910d 100644 --- a/test/controllers/api/v1/team_members_controller_test.rb +++ b/test/controllers/api/v1/team_members_controller_test.rb @@ -83,7 +83,7 @@ class TeamMembersControllerTest < ActionController::TestCase post :invite, params: { team_id: team.id, id: invitee_email } assert_response :ok - assert json_response['pending_invite'] + assert response.parsed_body['pending_invite'] user = User.find_by(email: invitee_email) assert_not_nil user.stored_raw_invitation_token diff --git a/test/controllers/api/v1/tries_controller_test.rb b/test/controllers/api/v1/tries_controller_test.rb index c71688a0a..b3548e651 100644 --- a/test/controllers/api/v1/tries_controller_test.rb +++ b/test/controllers/api/v1/tries_controller_test.rb @@ -268,7 +268,7 @@ def assert_curator_vars_equal vars, response_vars assert_response :ok - try_response = json_response + try_response = response.parsed_body created_try = the_case.tries.where(try_number: try_response['try_number']).first assert_try_matches_response try_response, created_try @@ -313,9 +313,9 @@ def assert_curator_vars_equal vars, response_vars assert_response :ok the_case.reload - created_try = the_case.tries.where(try_number: json_response['try_number']).first + created_try = the_case.tries.where(try_number: response.parsed_body['try_number']).first - assert_equal false, json_response['escape_query'] + assert_equal false, response.parsed_body['escape_query'] assert_equal false, created_try.escape_query end @@ -327,9 +327,9 @@ def assert_curator_vars_equal vars, response_vars assert_response :ok the_case.reload - created_try = the_case.tries.where(try_number: json_response['try_number']).first + created_try = the_case.tries.where(try_number: response.parsed_body['try_number']).first - assert_equal 'get', json_response['api_method'] + assert_equal 'get', response.parsed_body['api_method'] assert_equal 'get', created_try.search_endpoint.api_method end @@ -340,10 +340,10 @@ def assert_curator_vars_equal vars, response_vars assert_response :ok the_case.reload - created_try = the_case.tries.where(try_number: json_response['try_number']).first + created_try = the_case.tries.where(try_number: response.parsed_body['try_number']).first assert_equal 20, created_try.number_of_rows - assert_equal 20, json_response['number_of_rows'] + assert_equal 20, response.parsed_body['number_of_rows'] end test 'assigns default attributes' do @@ -381,7 +381,7 @@ def assert_curator_vars_equal vars, response_vars assert_response :ok the_case.reload - created_try = the_case.tries.where(try_number: json_response['try_number']).first + created_try = the_case.tries.where(try_number: response.parsed_body['try_number']).first assert_not_equal try, created_try assert_equal created_try.search_endpoint.search_engine, 'os' diff --git a/test/controllers/api/v1/users_controller_test.rb b/test/controllers/api/v1/users_controller_test.rb index 9e71c831c..170c7203b 100644 --- a/test/controllers/api/v1/users_controller_test.rb +++ b/test/controllers/api/v1/users_controller_test.rb @@ -126,8 +126,8 @@ class UsersControllerTest < ActionController::TestCase assert_response :ok - assert_instance_of Array, json_response['users'] - assert_equal [], json_response['users'] + assert_instance_of Array, response.parsed_body['users'] + assert_equal [], response.parsed_body['users'] end end end @@ -144,10 +144,10 @@ class UsersControllerTest < ActionController::TestCase assert_response :ok - assert_instance_of Array, json_response['users'] - assert_equal 1, json_response['users'].size + assert_instance_of Array, response.parsed_body['users'] + assert_equal 1, response.parsed_body['users'].size - emails = json_response['users'].pluck('email') + emails = response.parsed_body['users'].pluck('email') assert_includes emails, 'matt@example.com' end @@ -159,20 +159,20 @@ class UsersControllerTest < ActionController::TestCase assert_response :ok - assert_instance_of Array, json_response['users'] - assert_equal 1, json_response['users'].size + assert_instance_of Array, response.parsed_body['users'] + assert_equal 1, response.parsed_body['users'].size - emails = json_response['users'].pluck('email') + emails = response.parsed_body['users'].pluck('email') assert_includes emails, 'doug@example.com' get :index, params: { prefix: 'DOUG' } assert_response :ok - assert_instance_of Array, json_response['users'] - assert_equal 1, json_response['users'].size + assert_instance_of Array, response.parsed_body['users'] + assert_equal 1, response.parsed_body['users'].size - emails = json_response['users'].pluck('email') + emails = response.parsed_body['users'].pluck('email') assert_includes emails, 'doug@example.com' end end diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb index 1a967e3df..6e436ed52 100644 --- a/test/controllers/sessions_controller_test.rb +++ b/test/controllers/sessions_controller_test.rb @@ -58,7 +58,7 @@ class SessionsControllerTest < ActionController::TestCase post :create, params: { user: { email: user.email, password: 'password' }, format: :json } assert_response :unprocessable_entity - assert_equal 'LOCKED', json_response['reason'] + assert_equal 'LOCKED', response.parsed_body['reason'] end end