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

pulibrary / orangelight / 2e8abe27-f09a-4a85-94ed-3a143217d06e

25 Mar 2025 08:20PM UTC coverage: 95.346% (-0.09%) from 95.437%
2e8abe27-f09a-4a85-94ed-3a143217d06e

Pull #3386

circleci

christinach
Refactor method browse_subject
set broeslists csv_length:230
Pull Request #3386: Adds vocabulary column to subject table

33 of 40 new or added lines in 4 files covered. (82.5%)

9 existing lines in 3 files now uncovered.

6023 of 6317 relevant lines covered (95.35%)

1517.13 hits per line

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

95.28
/app/controllers/orangelight/browsables_controller.rb
1
# frozen_string_literal: true
2

3
class Orangelight::BrowsablesController < ApplicationController
3✔
4
  # GET /orangelight/names
5
  # GET /orangelight/names.json
6
  def index
3✔
7
    # if rpp isn't specified default is 50
8
    # if rpp has values other than 10, 25, 50, 100 then set it to 50
9
    # previous/next page links need to pass
10
    # manually set rpp
11

12
    assign_values
28✔
13

14
    # makes sure valid page is displayed
15
    if !(@last_id - @rpp + 1..@last_id).cover?(@start) && @is_last
28✔
16
      @start = @last_id - @rpp + 1
8✔
17
      @start = 1 if @start < 1 # catch for start ids higher than last id
8✔
18
    end
19

20
    assign_pagination_values
28✔
21

22
    @facet = facet
28✔
23
    @list_name = list_name
28✔
24

25
    respond_to do |format|
28✔
26
      format.html # index.html.erb
28✔
27
      format.json { render json: @orangelight_browsables }
46✔
28
    end
29
  end
30

31
  private
3✔
32

33
    def assign_values
3✔
34
      @model = model_table_name
28✔
35
      @rpp = rpp
28✔
36
      @page_link = page_link
28✔
37

38
      # @start gets the id of the first entry to display on page
39
      # specific ids are given based on search results
40
      @start = first_model_id
28✔
41

42
      populate_search_results
28✔
43

44
      # gets last page of table's results
45
      @last_id = last_model_id
28✔
46

47
      # makes sure no next page link is shown for last page
48
      @is_last = (@last_id - @rpp + 1) <= @start
28✔
49
    end
50

51
    def rpp
3✔
52
      if rpp_param.nil?
28✔
53
        50
12✔
54
      else
55
        validate_rpp(requested_rpp)
16✔
56
      end
57
    end
58

59
    def page_link
3✔
60
      if rpp_param.nil?
28✔
61
        '?'
12✔
62
      else
63
        size = validate_rpp(requested_rpp)
16✔
64
        "?rpp=#{size}&"
16✔
65
      end
66
    end
67

68
    def validate_rpp(size)
3✔
69
      rpp_range = [10, 25, 50, 100]
32✔
70
      if rpp_range.include? size
32✔
71
        size
24✔
72
      else
73
        50
8✔
74
      end
75
    end
76

77
    def populate_search_results
3✔
78
      return if query_param.nil?
28✔
79

80
      search_result = model_param.where('sort <= ?', search_term).order('sort').last
12✔
81

82
      return if search_result.nil?
12✔
83

84
      populate_search_params(search_result)
11✔
85
    end
86

87
    def populate_search_params(search_result)
3✔
88
      @search_result = search_result.label
11✔
89
      @search_term = search_term
11✔
90
      @exact_match = search_term == search_result.sort
11✔
91
      @match = search_result.id
11✔
92
      @start = search_result.id - 1
11✔
93
      @start -= 1 if @exact_match
11✔
94
      @start = 1 if @start < 1
11✔
95
      @query = query_param
11✔
96
    end
97

98
    def assign_pagination_values
3✔
99
      @is_first = @start == 1
28✔
100

101
      @page_last = if (@start + @rpp - 1) > @last_id
28✔
102
                     @last_id
3✔
103
                   else
104
                     @start + @rpp - 1
25✔
105
                   end
106

107
      @prev = @start - @rpp
28✔
108
      @prev = 1 if @prev < 1
28✔
109
      @next = @start + @rpp
28✔
110

111
      @orangelight_browsables = model_param.where(id: @start..@page_last)
28✔
112
    end
113

114
    def facet
3✔
115
      if browsing_names?
28✔
116
        'author_s'
1✔
117
      elsif browsing_subjects?
27✔
118
        'lc_subject_facet' || 'homoit_subject_facet' || 'homoit_genre_facet' || 'lcgft_genre_facet' || 'local_subject_facet' || 'rbgenr_genre_facet' || 'aat_genre_facet' || 'siku_subject_facet'
4✔
119
      elsif browsing_titles?
23✔
120
        'name_title_browse_s'
1✔
121
      end
122
    end
123

124
    # Retrieve the Model mapped to the request parameter
125
    # @return [Class]
126
    def model_param
3✔
127
      params[:model]
264✔
128
    end
129

130
    # Generates the name of the table mapped to the model in the request
131
    # @return [String]
132
    def model_table_name
3✔
133
      model_name = model_param.name
168✔
134
      model_class = model_name.demodulize
168✔
135
      model_class.tableize
168✔
136
    end
137

138
    # Determines whether or not the client is requesting to browse call numbers
139
    # @return [Boolean]
140
    def browsing_call_numbers?
3✔
141
      model_table_name == 'call_numbers'
34✔
142
    end
143

144
    # Determines whether or not the client is requesting to browse names
145
    # @return [Boolean]
146
    def browsing_names?
3✔
147
      model_table_name == 'names'
28✔
148
    end
149

150
    # Determines whether or not the client is requesting to browse subjects
151
    # @return [Boolean]
152
    def browsing_subjects?
3✔
153
      model_table_name == 'subjects'
27✔
154
    end
155

156
    # Determines whether or not the client is requesting to browse titles
157
    # @return [Boolean]
158
    def browsing_titles?
3✔
159
      model_table_name == 'name_titles'
23✔
160
    end
161

162
    # Generates the name of the list (based upon the model for the request)
163
    # @return [String]
164
    def list_name
3✔
165
      value = model_table_name.humanize
28✔
166
      return 'author-title headings' if value == 'Name titles'
28✔
167
      value
27✔
168
    end
169

170
    # Retrieves the ID requested by the client
171
    # @return [String]
172
    def id_param
3✔
UNCOV
173
      params[:id]
×
174
    end
175

176
    # Retrieves the query transmitted by the client
177
    # @return [String]
178
    def query_param
3✔
179
      params[:q]
73✔
180
    end
181

182
    # Retrieves the ID for the first object requested by the client
183
    # @return [String]
184
    def start_param
3✔
185
      params[:start]
42✔
186
    end
187

188
    # Retrieves the ID of the first object for this request
189
    # @return [Integer]
190
    def first_model_id
3✔
191
      return 1 if start_param.nil?
28✔
192
      start_param.to_i
14✔
193
    end
194

195
    # Normalizes the query transmitted by the client
196
    # @return [String]
197
    def search_term
3✔
198
      return StringFunctions.cn_normalize(query_param) if browsing_call_numbers?
34✔
199

200
      query_param.normalize_em
×
201
    end
202

203
    # Retrieves the ID of the last object for this request
204
    # @return [Integer]
205
    def last_model_id
3✔
206
      return model_param.last.id if model_param.last
28✔
UNCOV
207
      1
×
208
    end
209

210
    # Retrieves the requested rows per page (rpp) from the client
211
    # @return [String]
212
    def rpp_param
3✔
213
      params[:rpp]
88✔
214
    end
215

216
    # Generates the requested rows per page as an Integer
217
    # @return [Integer]
218
    def requested_rpp
3✔
219
      rpp_param.to_i
32✔
220
    end
221

222
    # Use callbacks to share common setup or constraints between actions.
223
    def set_orangelight_browsable
3✔
UNCOV
224
      @orangelight_browsable = model_param.find(id_param) if model_param
×
225
    end
226

227
    # Never trust parameters from the scary internet; run the params we receive through an allowlist
228
    def orangelight_browsable_params
3✔
UNCOV
229
      params.require(:orangelight_browsable).permit(:model, :id)
×
230
    end
231
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