Skip to content

Commit 6b118e1

Browse files
authored
Merge pull request #489 from MITLibraries/rubocop
Ruby update and Rubocop changes
2 parents 31a5254 + a6db8d5 commit 6b118e1

File tree

11 files changed

+65
-81
lines changed

11 files changed

+65
-81
lines changed

.rubocop.yml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
require: rubocop-rails
2-
3-
Documentation:
4-
Enabled: false
1+
AllCops:
2+
TargetRubyVersion: 2.7
3+
NewCops: enable
4+
Exclude:
5+
- "db/**/*"
6+
- "config/**/*"
7+
- "bin/**"
58

6-
Rails:
7-
Enabled: true
9+
Metrics/BlockLength:
10+
CountComments: false # count full line comments?
11+
Max: 25
12+
Exclude:
13+
- "Rakefile"
14+
- "**/*.rake"
15+
- "test/**/*.rb"
16+
- "test/test_helper.rb"
817

9-
AllCops:
10-
TargetRubyVersion: 2.6
18+
Metrics/ClassLength:
1119
Exclude:
12-
- db/**/*
13-
- config/**/*
14-
- bin/**
20+
- "test/**/*"
1521

16-
ClassLength:
22+
Metrics/MethodLength:
1723
Exclude:
18-
- test/**/*
24+
- "test/**/*.rb"
1925

20-
Style/FrozenStringLiteralComment:
26+
Style/Documentation:
2127
Enabled: false
2228

23-
Metrics/BlockLength:
24-
CountComments: false # count full line comments?
25-
Max: 25
26-
Exclude:
27-
- 'Rakefile'
28-
- '**/*.rake'
29-
- 'spec/**/*.rb'
30-
- 'test/test_helper.rb'
29+
Style/FrozenStringLiteralComment:
30+
Enabled: false

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.6.5
1+
2.7.4

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
source 'https://rubygems.org'
22
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
33

4-
ruby '2.6.5'
4+
ruby '2.7.4'
55

66
gem 'aws-sdk-elasticsearchservice'
77
gem 'bootsnap', require: false

Gemfile.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ GEM
189189
racc (~> 1.4)
190190
orm_adapter (0.5.0)
191191
parallel (1.20.1)
192-
parser (3.0.1.0)
192+
parser (3.0.2.0)
193193
ast (~> 2.4.1)
194194
pg (1.2.3)
195195
public_suffix (4.0.6)
@@ -242,17 +242,17 @@ GEM
242242
actionpack (>= 5.0)
243243
railties (>= 5.0)
244244
rexml (3.2.5)
245-
rubocop (1.13.0)
245+
rubocop (1.18.4)
246246
parallel (~> 1.10)
247247
parser (>= 3.0.0.0)
248248
rainbow (>= 2.2.2, < 4.0)
249249
regexp_parser (>= 1.8, < 3.0)
250250
rexml
251-
rubocop-ast (>= 1.2.0, < 2.0)
251+
rubocop-ast (>= 1.8.0, < 2.0)
252252
ruby-progressbar (~> 1.7)
253253
unicode-display_width (>= 1.4.0, < 3.0)
254-
rubocop-ast (1.4.1)
255-
parser (>= 2.7.1.5)
254+
rubocop-ast (1.8.0)
255+
parser (>= 3.0.1.1)
256256
rubocop-rails (2.9.1)
257257
activesupport (>= 4.2.0)
258258
rack (>= 1.1)
@@ -360,7 +360,7 @@ DEPENDENCIES
360360
webmock
361361

362362
RUBY VERSION
363-
ruby 2.6.5p114
363+
ruby 2.7.4p191
364364

365365
BUNDLED WITH
366366
2.1.4

app/models/retrieve.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ def fetch(id)
33
f = to_filter(id)
44
record = Timdex::EsClient.search(index: ENV['ELASTICSEARCH_INDEX'], body: f)
55

6-
if record['hits']['total'].zero?
7-
raise Elasticsearch::Transport::Transport::Errors::NotFound
8-
end
6+
raise Elasticsearch::Transport::Transport::Errors::NotFound if record['hits']['total'].zero?
97

108
record
119
end

app/models/search.rb

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,15 @@ def query
6767
def filters
6868
f = []
6969
f.push filter(@params[:collection], 'collections') if @params[:collection]
70-
if @params[:contributor]
71-
f.push filter(@params[:contributor], 'contributors')
72-
end
70+
f.push filter(@params[:contributor], 'contributors') if @params[:contributor]
7371

74-
if @params[:content_type]
75-
f.push filter_single(@params[:content_type], 'content_type')
76-
end
72+
f.push filter_single(@params[:content_type], 'content_type') if @params[:content_type]
7773

78-
if @params[:content_format]
79-
f.push filter(@params[:content_format], 'format')
80-
end
74+
f.push filter(@params[:content_format], 'format') if @params[:content_format]
8175

8276
f.push filter(@params[:language], 'languages') if @params[:language]
8377

84-
if @params[:literary_form]
85-
f.push filter_single(@params[:literary_form], 'literary_form')
86-
end
78+
f.push filter_single(@params[:literary_form], 'literary_form') if @params[:literary_form]
8779

8880
f.push filter_single(@params[:source], 'source') if @params[:source]
8981
f.push filter(@params[:subject], 'subjects') if @params[:subject]
@@ -112,7 +104,7 @@ def filter(param, field)
112104
}
113105
)
114106
else
115-
terms.push('term': { "#{field}.keyword": t })
107+
terms.push(term: { "#{field}.keyword": t })
116108
end
117109
end
118110

@@ -122,7 +114,7 @@ def filter(param, field)
122114
# use `filter_single` when we only accept a single value in our data model
123115
def filter_single(param, field)
124116
{
125-
'term': { "#{field}.keyword": param }
117+
term: { "#{field}.keyword": param }
126118
}
127119
end
128120

app/views/api/v1/search/_extended.json.jbuilder

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,14 @@ json.issns result['issns'] if result['issns']
33
json.dois result['dois'] if result['dois']
44
json.available 'Not Yet Implemented'
55
json.alternate_titles result['alternate_titles'] if result['alternate_titles']
6-
if json.place_of_publication result['place_of_publication']
7-
result['place_of_publication']
8-
end
6+
result['place_of_publication'] if json.place_of_publication result['place_of_publication']
97
json.languages result['languages'] if result['languages']
108
json.call_numbers result['call_numbers'] if result['call_numbers']
119
json.edition result['edition'] if result['edition']
1210
json.imprint result['imprint'] if result['imprint']
13-
if result['physical_description']
14-
json.physical_description result['physical_description']
15-
end
11+
json.physical_description result['physical_description'] if result['physical_description']
1612
json.summary result['summary'] if result['summary']
1713
json.imprint result['imprint'] if result['imprint']
1814
json.notes result['notes'] if result['notes']
19-
if result['publication_frequency']
20-
json.publication_frequency result['publication_frequency']
21-
end
15+
json.publication_frequency result['publication_frequency'] if result['publication_frequency']
2216
json.literary_form result['literary_form'] if result['literary_form']

config.ru

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is used by Rack-based servers to start the application.
22

3-
require_relative "config/environment"
3+
require_relative 'config/environment'
44

55
run Rails.application
66
Rails.application.load_server

test/controllers/auth_controller_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
class AuthControllerTest < ActionDispatch::IntegrationTest
44
test 'valid credentials returns JWT' do
55
u = users(:yo)
6-
b = Base64.encode64(u.email + ':123greetings')
7-
get '/api/v1/auth', headers: { 'Authorization': "Basic #{b}" }
6+
b = Base64.encode64("#{u.email}:123greetings")
7+
get '/api/v1/auth', headers: { Authorization: "Basic #{b}" }
88
assert_equal(200, response.status)
99
assert_equal(u.id, JwtWrapper.decode(JSON.parse(response.body))['user_id'])
1010
end

test/controllers/graphql_controller_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class GraphqlControllerTest < ActionDispatch::IntegrationTest
137137
test 'search with multiple subjects applied' do
138138
VCR.use_cassette('graphql search multiple subjects') do
139139
post '/graphql', params: { query: '{
140-
search(searchterm: "space",
140+
search(searchterm: "space",
141141
subjects: ["space and time.",
142142
"quantum theory."]) {
143143
hits
@@ -167,7 +167,7 @@ class GraphqlControllerTest < ActionDispatch::IntegrationTest
167167
json = JSON.parse(response.body)
168168
assert(json['errors'].first['message'].present?)
169169
assert_equal("Field 'search' doesn't accept argument 'fake'",
170-
json['errors'].first['message'])
170+
json['errors'].first['message'])
171171
end
172172
end
173173

0 commit comments

Comments
 (0)