• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / allsearch_api / 8b9aaf5e-cf64-41ee-baf6-46eb5bd68826

14 Oct 2025 03:46AM UTC coverage: 99.32% (-0.2%) from 99.514%
8b9aaf5e-cf64-41ee-baf6-46eb5bd68826

Pull #395

circleci

sandbergja
Make search controller shared examples less coupled to solr
Pull Request #395: Migrate a few more controllers away from Rails

8 of 8 new or added lines in 4 files covered. (100.0%)

121 existing lines in 22 files now uncovered.

1022 of 1029 relevant lines covered (99.32%)

96.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.82
/app/controllers/service_controller.rb
1
# frozen_string_literal: true
2

3
class ServiceController < ApplicationController
3✔
4
  rescue_from StandardError, with: :show_standard_error
3✔
5
  rescue_from Timeout::Error, Errno::ECONNRESET, Net::ProtocolError, with: :show_http_error
3✔
6
  rescue_from AllsearchError, with: :show_allsearch_error
3✔
7
  rescue_from ActionController::ParameterMissing, with: :show_query_error
3✔
8
  rescue_from URI::InvalidURIError, with: :rescue_from_error
3✔
9
  rescue_from ArgumentError, with: :rescue_from_error
3✔
10
  attr_reader :query
3✔
11

12
  def show
3✔
13
    @query = service.new(query_terms: query_params)
106✔
14

15
    render json: query.our_response
93✔
16
  end
17

18
  private
3✔
19

20
  attr_reader :service
3✔
21

22
  def query_params
3✔
23
    params.require(:query).gsub(/[#{Regexp.escape(special_characters)}]/, ' ')
106✔
24
          .gsub(/\s+/, ' ')
25
          .strip
26
  end
27

28
  def show_standard_error(exception)
3✔
29
    Honeybadger.notify exception
×
30
    render_error(problem: 'APPLICATION_ERROR',
×
31
                 message: "This application threw #{exception.class}",
32
                 status: :internal_server_error)
33
  end
34

35
  # :reek:FeatureEnvy
36
  def show_http_error(exception)
3✔
UNCOV
37
    Honeybadger.notify exception
×
UNCOV
38
    render_error(problem: 'UPSTREAM_ERROR',
×
39
                 message: "Query to upstream failed with #{exception.class}, message: #{exception.message}",
40
                 status: :internal_server_error)
41
  end
42

43
  # :reek:FeatureEnvy
44
  def show_allsearch_error(exception)
3✔
45
    Honeybadger.notify exception
4✔
46
    render_error(problem: exception.problem,
4✔
47
                 message: exception.message,
48
                 status: :internal_server_error)
49
  end
50

51
  def show_query_error
3✔
52
    # We don't report these to Honeybadger, since the system is working as
53
    # expected in these cases by telling the user they need to enter a query.
54
    render_error(problem: 'QUERY_IS_EMPTY',
12✔
55
                 message: 'The query param must contain non-whitespace characters.',
56
                 status: :bad_request)
57
  end
58

59
  def rescue_from_error
3✔
60
    @query = service.new(query_terms: URI.encode_uri_component(query_params))
×
61

62
    render json: query.our_response
×
63
  end
64

65
  def render_error(problem:, message:, status:)
3✔
66
    render json: { error: {
16✔
67
      problem:,
68
      message:
69
    } }, status:
70
  end
71

72
  def special_characters
3✔
73
    '{}#!</>'
94✔
74
  end
75
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc