Skip to content

Commit 602a504

Browse files
committed
Add new rubocop rules and run autocorrect
1 parent aaf12cc commit 602a504

8 files changed

+135
-33
lines changed

Diff for: .rubocop.yml

+104
Original file line numberDiff line numberDiff line change
@@ -384,3 +384,107 @@ Performance/StringInclude: # new in 1.7
384384
Enabled: true
385385
Performance/Sum: # new in 1.8
386386
Enabled: true
387+
Gemspec/DevelopmentDependencies: # new in 1.44
388+
Enabled: true
389+
Lint/DuplicateMatchPattern: # new in 1.50
390+
Enabled: true
391+
Lint/ItWithoutArgumentsInBlock: # new in 1.59
392+
Enabled: true
393+
Lint/LiteralAssignmentInCondition: # new in 1.58
394+
Enabled: true
395+
Lint/MixedCaseRange: # new in 1.53
396+
Enabled: true
397+
Lint/RedundantRegexpQuantifiers: # new in 1.53
398+
Enabled: true
399+
Lint/UselessRescue: # new in 1.43
400+
Enabled: true
401+
Metrics/CollectionLiteralLength: # new in 1.47
402+
Enabled: true
403+
Style/ComparableClamp: # new in 1.44
404+
Enabled: true
405+
Style/ConcatArrayLiterals: # new in 1.41
406+
Enabled: true
407+
Style/DataInheritance: # new in 1.49
408+
Enabled: true
409+
Style/DirEmpty: # new in 1.48
410+
Enabled: true
411+
Style/ExactRegexpMatch: # new in 1.51
412+
Enabled: true
413+
Style/FileEmpty: # new in 1.48
414+
Enabled: true
415+
Style/MapIntoArray: # new in 1.63
416+
Enabled: true
417+
Style/MapToSet: # new in 1.42
418+
Enabled: true
419+
Style/MinMaxComparison: # new in 1.42
420+
Enabled: true
421+
Style/RedundantArrayConstructor: # new in 1.52
422+
Enabled: true
423+
Style/RedundantCurrentDirectoryInPath: # new in 1.53
424+
Enabled: true
425+
Style/RedundantDoubleSplatHashBraces: # new in 1.41
426+
Enabled: true
427+
Style/RedundantFilterChain: # new in 1.52
428+
Enabled: true
429+
Style/RedundantHeredocDelimiterQuotes: # new in 1.45
430+
Enabled: true
431+
Style/RedundantLineContinuation: # new in 1.49
432+
Enabled: true
433+
Style/RedundantRegexpArgument: # new in 1.53
434+
Enabled: true
435+
Style/RedundantRegexpConstructor: # new in 1.52
436+
Enabled: true
437+
Style/ReturnNilInPredicateMethodDefinition: # new in 1.53
438+
Enabled: true
439+
Style/SendWithLiteralMethodName: # new in 1.64
440+
Enabled: true
441+
Style/SingleLineDoEndBlock: # new in 1.57
442+
Enabled: true
443+
Style/SuperArguments: # new in 1.64
444+
Enabled: true
445+
Style/SuperWithArgsParentheses: # new in 1.58
446+
Enabled: true
447+
Style/YAMLFileRead: # new in 1.53
448+
Enabled: true
449+
Rails/DangerousColumnNames: # new in 2.21
450+
Enabled: true
451+
Rails/EnvLocal: # new in 2.22
452+
Enabled: true
453+
Rails/RedundantActiveRecordAllMethod: # new in 2.21
454+
Enabled: true
455+
Rails/ResponseParsedBody: # new in 2.18
456+
Enabled: true
457+
Rails/SelectMap: # new in 2.21
458+
Enabled: true
459+
Rails/ThreeStateBooleanColumn: # new in 2.19
460+
Enabled: true
461+
Rails/UnusedRenderContent: # new in 2.21
462+
Enabled: true
463+
Rails/WhereRange: # new in 2.25
464+
Enabled: true
465+
Performance/MapMethodChain: # new in 1.19
466+
Enabled: true
467+
Capybara/ClickLinkOrButtonStyle: # new in 2.19
468+
Enabled: true
469+
Capybara/MatchStyle: # new in 2.17
470+
Enabled: true
471+
Capybara/RedundantWithinFind: # new in 2.20
472+
Enabled: true
473+
Capybara/RSpec/HaveSelector: # new in 2.19
474+
Enabled: true
475+
FactoryBot/AssociationStyle: # new in 2.23
476+
Enabled: true
477+
FactoryBot/ExcessiveCreateList: # new in 2.25
478+
Enabled: true
479+
FactoryBot/FactoryAssociationWithStrategy: # new in 2.23
480+
Enabled: true
481+
FactoryBot/IdSequence: # new in 2.24
482+
Enabled: true
483+
FactoryBot/RedundantFactoryOption: # new in 2.23
484+
Enabled: true
485+
RSpecRails/MinitestAssertions: # new in 2.17
486+
Enabled: true
487+
RSpecRails/NegationBeValid: # new in 2.23
488+
Enabled: true
489+
RSpecRails/TravelAround: # new in 2.19
490+
Enabled: true

Diff for: app/jobs/generate_delta_dump_job.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def perform(organization)
4949
end
5050
end
5151
oai_writer.finalize
52-
delta_dump.public_send(:oai_xml).attach(io: File.open(oai_writer.oai_file),
53-
filename: human_readable_filename(base_name, :oai_xml, oai_file_counter))
52+
delta_dump.oai_xml.attach(io: File.open(oai_writer.oai_file),
53+
filename: human_readable_filename(base_name, :oai_xml, oai_file_counter))
5454

5555
oai_file_counter += 1
5656
# Save the dump once for every 100 oai files to free up file handles

Diff for: app/jobs/generate_full_dump_job.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ def perform(organization)
4848

4949
if oai_writer.bytes_written?
5050
oai_writer.finalize
51-
full_dump.public_send(:oai_xml).attach(io: File.open(oai_writer.oai_file),
52-
filename: human_readable_filename(
53-
base_name, :oai_xml, oai_file_counter
54-
))
51+
full_dump.oai_xml.attach(io: File.open(oai_writer.oai_file),
52+
filename: human_readable_filename(
53+
base_name, :oai_xml, oai_file_counter
54+
))
5555
end
5656

5757
oai_file_counter += 1

Diff for: app/jobs/generate_interstream_delta_job.rb

+3-5
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,9 @@ def perform(stream)
101101
# Attach Files
102102
current_stream_dump.create_interstream_delta unless current_stream_dump.interstream_delta
103103

104-
current_stream_dump.interstream_delta.public_send(:marc21).attach(io: File.open(mrc_tempfile), filename: "#{base_name}.mrc")
105-
current_stream_dump.interstream_delta.public_send(:marcxml).attach(io: File.open(xml_tempfile), filename: "#{base_name}.xml")
106-
# rubocop:disable Layout/LineLength
107-
current_stream_dump.interstream_delta.public_send(:deletes).attach(io: File.open(delete_tempfile), filename: "#{base_name}.del.txt")
108-
# rubocop:enable Layout/LineLength
104+
current_stream_dump.interstream_delta.marc21.attach(io: File.open(mrc_tempfile), filename: "#{base_name}.mrc")
105+
current_stream_dump.interstream_delta.marcxml.attach(io: File.open(xml_tempfile), filename: "#{base_name}.xml")
106+
current_stream_dump.interstream_delta.deletes.attach(io: File.open(delete_tempfile), filename: "#{base_name}.del.txt")
109107
end
110108
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
111109
end

Diff for: app/models/stream.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def current_dump_ids(from_date: nil, until_date: nil)
9090
.or(NormalizedDump.where(full_dump_id: full_dump_id))
9191
.published
9292
.order(created_at: :asc)
93-
dumps_query = dumps_query.where('created_at >= ?', Time.zone.parse(from_date).beginning_of_day) if from_date.present?
94-
dumps_query = dumps_query.where('created_at <= ?', Time.zone.parse(until_date).end_of_day) if until_date.present?
93+
dumps_query = dumps_query.where(created_at: Time.zone.parse(from_date).beginning_of_day..) if from_date.present?
94+
dumps_query = dumps_query.where(created_at: ..Time.zone.parse(until_date).end_of_day) if until_date.present?
9595

9696
dumps_query.pluck(:id)
9797
end
@@ -115,7 +115,7 @@ def previous_default_stream_history(datetime = nil)
115115

116116
organization.default_stream_histories
117117
.order(end_time: :desc)
118-
.where('end_time < ?', default_stream_history.start_time)
118+
.where(end_time: ...default_stream_history.start_time)
119119
.first
120120
end
121121

Diff for: spec/features/normalized_download_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
visit normalized_data_organization_stream_path(organization, stream)
3333

3434
# Note, this won't work in a driver other that Rack::Test w/o some other magic
35-
click_link "#{organization.slug}-2020-01-01-full-marc21.mrc.gz"
35+
click_on "#{organization.slug}-2020-01-01-full-marc21.mrc.gz"
3636
marc = MarcRecordService.marc_reader(StringIO.new(page.body), :marc21_gzip)
3737

3838
expect(page.response_headers['Content-Disposition']).to eq 'attachment'
@@ -43,7 +43,7 @@
4343
visit normalized_data_organization_stream_path(organization, stream)
4444

4545
# Note, this won't work in a driver other that Rack::Test w/o some other magic
46-
click_link "#{organization.slug}-2020-01-01-full-marc21.mrc.gz"
46+
click_on "#{organization.slug}-2020-01-01-full-marc21.mrc.gz"
4747
records = MarcRecordService.marc_reader(StringIO.new(page.body), :marc21_gzip)
4848

4949
records.each do |marc|
@@ -57,7 +57,7 @@
5757

5858
expect do
5959
# Note, this won't work in a driver other that Rack::Test w/o some other magic
60-
click_link "#{organization.slug}-2020-01-01-full-marc21.mrc.gz"
60+
click_on "#{organization.slug}-2020-01-01-full-marc21.mrc.gz"
6161
end.to change(Ahoy::Event, :count).by(1)
6262

6363
expect(Ahoy::Event.last.properties.with_indifferent_access).to include(

Diff for: spec/features/oai_spec.rb

+15-15
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@
4444

4545
it 'renders an error if no verb is supplied' do
4646
visit oai_url
47-
expect(page).to have_selector('error[code="badVerb"]')
47+
expect(page).to have_css('error[code="badVerb"]')
4848
end
4949

5050
it 'renders an error if an unknown verb is supplied' do
5151
visit oai_url(verb: 'Oops')
52-
expect(page).to have_selector('error[code="badVerb"]')
52+
expect(page).to have_css('error[code="badVerb"]')
5353
end
5454

5555
it 'renders the time the request was submitted in iso8601 format' do
@@ -60,7 +60,7 @@
6060

6161
it 'renders the request params and root url as an element' do
6262
visit oai_url(verb: 'ListSets')
63-
expect(page).to have_selector('request[verb="ListSets"]', text: oai_url)
63+
expect(page).to have_css('request[verb="ListSets"]', text: oai_url)
6464
end
6565

6666
context 'when the verb is ListSets' do
@@ -83,7 +83,7 @@
8383

8484
it 'renders an error if unknown params are supplied' do
8585
visit oai_url(verb: 'ListSets', foo: 'bar')
86-
expect(page).to have_selector('error[code="badArgument"]')
86+
expect(page).to have_css('error[code="badArgument"]')
8787
end
8888
end
8989

@@ -129,7 +129,7 @@
129129

130130
it 'renders an error if unknown params are supplied' do
131131
visit oai_url(verb: 'Identify', foo: 'bar')
132-
expect(page).to have_selector('error[code="badArgument"]')
132+
expect(page).to have_css('error[code="badArgument"]')
133133
end
134134
end
135135

@@ -151,12 +151,12 @@
151151
it 'renders an error if an unknown identifier is supplied' do
152152
pending 'single item requests are not yet implemented'
153153
visit oai_url(verb: 'ListMetadataFormats', identifier: 'fake')
154-
expect(page).to have_selector('error[code="idDoesNotExist"]')
154+
expect(page).to have_css('error[code="idDoesNotExist"]')
155155
end
156156

157157
it 'renders an error if unknown params are supplied' do
158158
visit oai_url(verb: 'ListMetadataFormats', foo: 'bar')
159-
expect(page).to have_selector('error[code="badArgument"]')
159+
expect(page).to have_css('error[code="badArgument"]')
160160
end
161161
end
162162

@@ -178,7 +178,7 @@
178178
it 'renders a header indicating records are deleted' do
179179
token = OaiConcern::ResumptionToken.new(set: organization.default_stream.id.to_s, page: '2')
180180
visit oai_url(verb: 'ListRecords', resumptionToken: token.encode)
181-
expect(page).to have_selector('header[status="deleted"]')
181+
expect(page).to have_css('header[status="deleted"]')
182182
end
183183

184184
it 'renders the set membership of each item' do
@@ -227,22 +227,22 @@
227227

228228
it 'renders an error if unknown params are supplied' do
229229
visit oai_url(verb: 'ListRecords', metadataPrefix: 'marc21', foo: 'bar')
230-
expect(page).to have_selector('error[code="badArgument"]')
230+
expect(page).to have_css('error[code="badArgument"]')
231231
end
232232

233233
it 'renders an error if no metadata prefix is supplied' do
234234
visit oai_url(verb: 'ListRecords')
235-
expect(page).to have_selector('error[code="badArgument"]')
235+
expect(page).to have_css('error[code="badArgument"]')
236236
end
237237

238238
it 'renders an error if an unsupported metadata prefix is supplied' do
239239
visit oai_url(verb: 'ListRecords', metadataPrefix: 'foo')
240-
expect(page).to have_selector('error[code="cannotDisseminateFormat"]')
240+
expect(page).to have_css('error[code="cannotDisseminateFormat"]')
241241
end
242242

243243
it 'renders an error if the request results in an empty result set' do
244244
visit oai_url(verb: 'ListRecords', metadataPrefix: 'marc21', set: '392487')
245-
expect(page).to have_selector('error[code="noRecordsMatch"]')
245+
expect(page).to have_css('error[code="noRecordsMatch"]')
246246
end
247247

248248
context 'when a resumption token is supplied' do
@@ -253,17 +253,17 @@
253253

254254
it 'renders an error if any other argument is also supplied' do
255255
visit oai_url(verb: 'ListRecords', resumptionToken: OaiConcern::ResumptionToken.new(set: '1').encode, from: '2020-01-01')
256-
expect(page).to have_selector('error[code="badArgument"]')
256+
expect(page).to have_css('error[code="badArgument"]')
257257
end
258258

259259
it 'renders an error if the resumption token is not valid' do
260260
visit oai_url(verb: 'ListRecords', resumptionToken: 'foo')
261-
expect(page).to have_selector('error[code="badResumptionToken"]')
261+
expect(page).to have_css('error[code="badResumptionToken"]')
262262
end
263263

264264
it 'renders an error if the requested page of records does not exist' do
265265
visit oai_url(verb: 'ListRecords', resumptionToken: OaiConcern::ResumptionToken.new(page: '999').encode)
266-
expect(page).to have_selector('error[code="badResumptionToken"]')
266+
expect(page).to have_css('error[code="badResumptionToken"]')
267267
end
268268
end
269269
end

Diff for: spec/jobs/generate_interstream_delta_job_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
# Deltas should contain one addition (we find two instances of 'record' in the xml for <record> and </record>)
4848
xml = stream.current_full_dump.interstream_delta.marcxml.open { |file| File.readlines(file) }.to_s
49-
expect(xml.scan(/record/).count).to be(2)
49+
expect(xml.scan('record').count).to be(2)
5050

5151
# Deltas should contain two deletions
5252
deletes = stream.current_full_dump.interstream_delta.deletes.open { |file| File.readlines(file) }

0 commit comments

Comments
 (0)