Skip to content

Commit

Permalink
Remove old style controller json (#921)
Browse files Browse the repository at this point in the history
* use whats built into Rails!

* trim down some files that we don't use
  • Loading branch information
epugh authored Jan 18, 2024
1 parent e158050 commit 23c99fe
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 64 deletions.
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/views/layouts/_footer_core_app.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
url: Rails.application.config.cookies_url,
text: 'Cookies Policy',
},
{
url: 'apipie/',
text: 'API',
},
] %>

<% footer_links.each do |link| %>
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/analytics/tries_visualization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
14 changes: 7 additions & 7 deletions test/controllers/api/v1/annotations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/v1/books_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/v1/bulk/queries_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/v1/case_scorers_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/v1/case_scores_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions test/controllers/api/v1/cases_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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'] }

Expand All @@ -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'] }

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions test/controllers/api/v1/queries/positions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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]
Expand Down
22 changes: 11 additions & 11 deletions test/controllers/api/v1/queries_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/v1/query_doc_pairs_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions test/controllers/api/v1/scorers_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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']
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/api/v1/snapshots_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/v1/team_members_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 23c99fe

Please sign in to comment.