Skip to content

Commit

Permalink
feat: Upgrade rubocop for compatability with ruby 3.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniela Lemow authored and Daniela Lemow committed Apr 2, 2024
1 parent 57aad21 commit 047256c
Show file tree
Hide file tree
Showing 21 changed files with 55 additions and 51 deletions.
30 changes: 17 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ GEM
kaminari-mongoid (1.0.2)
kaminari-core (~> 1.0)
mongoid
language_server-protocol (3.17.0.3)
llhttp-ffi (0.4.0)
ffi-compiler (~> 1.0)
rake (~> 13.0)
Expand Down Expand Up @@ -301,10 +302,11 @@ GEM
optparse (0.4.0)
ougai (1.9.1)
oj (~> 3.10)
parallel (1.21.0)
parallel (1.24.0)
parse-cron (0.1.4)
parser (3.1.1.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
prometheus-client (4.0.0)
pry (0.14.2)
coderay (~> 1.1)
Expand Down Expand Up @@ -361,7 +363,7 @@ GEM
rainbow (3.1.1)
rake (13.2.0)
redis (4.8.1)
regexp_parser (2.2.1)
regexp_parser (2.9.0)
request_store (1.5.1)
rack (>= 1.4)
responders (3.0.1)
Expand All @@ -373,7 +375,7 @@ GEM
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
retriable (3.1.2)
rexml (3.2.5)
rexml (3.2.6)
rspec-activemodel-mocks (1.1.0)
activemodel (>= 3.0)
activesupport (>= 3.0)
Expand All @@ -398,17 +400,19 @@ GEM
rspec-core (~> 3.0, >= 3.0.0)
sidekiq (>= 2.4.0)
rspec-support (3.11.0)
rubocop (1.25.1)
rubocop (1.62.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.1.0.0)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.15.1, < 2.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.16.0)
parser (>= 3.1.1.0)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.2)
parser (>= 3.3.0.4)
rubocop-minitest (0.17.2)
rubocop (>= 0.90, < 2.0)
rubocop-packaging (0.5.1)
Expand All @@ -430,7 +434,7 @@ GEM
rubocop-rails (~> 2.0)
rubocop-rspec (2.9.0)
rubocop (~> 1.19)
ruby-progressbar (1.11.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
sanitize (6.1.0)
crass (~> 1.0.2)
Expand All @@ -453,7 +457,7 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.8.2)
unicode-display_width (2.1.0)
unicode-display_width (2.5.0)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand Down
2 changes: 1 addition & 1 deletion app/api/api/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.put(record_id, params)
def self.delete(id)
Api::Request.new(
'/harvester/records/delete',
{ id: id }
{ id: }
).put
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/api/api/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def execute(method)
end

RestClient::Request.execute(
method: method,
method:,
url: @url,
payload: payload,
payload:,
headers: {
'Authentication-Token': @token
}.merge(url_params)
Expand Down
4 changes: 2 additions & 2 deletions app/models/abstract_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def enqueue
def parser
return @parser if @parser.present?
if version_id.present?
@parser = ParserVersion.find(version_id, params: { parser_id: parser_id })
@parser = ParserVersion.find(version_id, params: { parser_id: })
elsif environment.present? && !preview?
version = ParserVersion.find(:one, from: :current, params: { parser_id: parser_id, environment: environment })
version = ParserVersion.find(:one, from: :current, params: { parser_id:, environment: })
version.parser_id = parser_id
self.version_id = version.id if version.present?
@parser = version
Expand Down
2 changes: 1 addition & 1 deletion app/models/collection_statistics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def add_record_item(record_id, status, landing_url)
send("#{status}_records=", []) if send("#{status}_records").nil?

records = send("#{status}_records")
record = { record_id: record_id, landing_url: landing_url }
record = { record_id:, landing_url: }
return if records.include?(record)

records << record
Expand Down
2 changes: 1 addition & 1 deletion app/models/enrichment_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def self.create_from_harvest_job(job, enrichment)
user_id: job.user_id,
environment: job.environment,
harvest_job_id: job.id,
enrichment: enrichment,
enrichment:,
parser_code: job.parser_code)
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/harvest_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def enqueue_enrichment_jobs
end

def flush_old_records
Api::Record.flush({ source_id: source_id, job_id: id })
Api::Record.flush({ source_id:, job_id: id })
rescue RestClient::Exception => e
create_harvest_failure(exception_class: e.class,
message: "Flush old records failed with the following error mesage: #{e.message}",
Expand Down
6 changes: 3 additions & 3 deletions app/models/harvest_schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def generate_next_run_at

def create_job
if active?
harvest_jobs.create(parser_id: parser_id,
environment: environment,
mode: mode, enrichments: enrichments)
harvest_jobs.create(parser_id:,
environment:,
mode:, enrichments:)

self.last_run_at = Time.zone.now
self.status = 'inactive' unless recurrent
Expand Down
4 changes: 2 additions & 2 deletions app/models/link_check_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ def source

private
def already_checked?
previous_job = LinkCheckJob.where(record_id: record_id).last
previous_job = LinkCheckJob.where(record_id:).last

return unless previous_job

check_interval = ENV.fetch('LINK_CHECKING_INTERVAL', 6).to_i

errors.add(:record_id,
I18n.t('link_check_job.error', record_id: record_id, check_interval: check_interval)
I18n.t('link_check_job.error', record_id:, check_interval:)
) if (DateTime.now.in_time_zone - previous_job.created_at) / 1.hour < check_interval
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/parser_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ParserVersion < ActiveResource::Base

def last_harvested_at
HarvestJob.where(
parser_id: parser_id,
parser_id:,
status: 'finished',
environment: { '$ne': 'preview' }
).max(:start_time)
Expand Down
4 changes: 2 additions & 2 deletions app/models/snippet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Snippet < ActiveResource::Base
headers['Authorization'] = "Token token=#{ENV['WORKER_KEY']}"

def self.find_by_name(name, environment)
find(:one, from: :current_version, params: { name: name,
environment: environment })
find(:one, from: :current_version, params: { name:,
environment: })
rescue StandardError => e
Rails.logger.error "Snippet with name: #{name} was not found"
ElasticAPM.report(e)
Expand Down
2 changes: 1 addition & 1 deletion app/workers/concerns/validates_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module ValidatesResource

def link_check_rule(source_id)
@link_check_rule ||= begin
LinkCheckRule.find_by(source_id: source_id)
LinkCheckRule.find_by(source_id:)
rescue StandardError
nil
end
Expand Down
4 changes: 2 additions & 2 deletions app/workers/enrichment_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ def fetch_records(page = 0)
{ 'fragments.source_id' => job.parser.source.source_id }
end

SupplejackApi::Record.find(query.merge(ENRICH_STATUS), page: page)
SupplejackApi::Record.find(query.merge(ENRICH_STATUS), page:)
else
klass = job.preview? ? SupplejackApi::PreviewRecord : SupplejackApi::Record
klass.find({ record_id: job.record_id }.merge(ENRICH_STATUS), page: page)
klass.find({ record_id: job.record_id }.merge(ENRICH_STATUS), page:)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/workers/link_check_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def suppress_record(job_id, record_id, strike)
end

def set_record_status(record_id, status)
Api::Record.put(record_id, { record: { status: status } })
Api::Record.put(record_id, { record: { status: } })
add_record_stats(record_id, status)
rescue StandardError
Sidekiq.logger.warn("LinkCheckWorker[#{record_id}]: Record not found when updating status = #{status} in LinkChecking. Ignoring.")
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/link_check_rules_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
it 'performs a where if link_check_rule is defined' do
params = { link_check_rule: { collection_title: 'link_check_rule' } }
expect(LinkCheckRule).to receive(:where).with(params[:link_check_rule].stringify_keys)
get :index, params: params, format: 'json'
get :index, params:, format: 'json'
end
end

Expand Down
16 changes: 8 additions & 8 deletions spec/factories/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ module SupplejackApi
factory :record_with_fragment do
fragments do
[FactoryBot.build(:record_fragment,
display_collection: display_collection,
copyright: copyright,
category: category,
tag: tag)]
display_collection:,
copyright:,
category:,
tag:)]
end

after(:build) do |record_with_fragment|
Expand All @@ -35,10 +35,10 @@ module SupplejackApi
[
FactoryBot.build(
:record_fragment,
display_collection: display_collection,
copyright: copyright,
category: category,
tag: tag,
display_collection:,
copyright:,
category:,
tag:,
large_thumbnail_url: nil
)
]
Expand Down
2 changes: 1 addition & 1 deletion spec/models/abstract_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@
describe '#job_states' do
let(:stateful_job) { create(:harvest_job, :stateful) }
let(:states) { build_list(:state, 5) }
let(:full_job) { create(:harvest_job, states: states) }
let(:full_job) { create(:harvest_job, states:) }

it 'can have an embedded history of the job state' do
expect(stateful_job.states.count).not_to eq(0)
Expand Down
2 changes: 1 addition & 1 deletion spec/models/harvest_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

%w[normal full_and_flush incremental].each do |mode|
it "is valid with mode of '#{mode}'" do
job1 = build(:harvest_job, parser_id: '333', mode: mode)
job1 = build(:harvest_job, parser_id: '333', mode:)
expect(job1).to be_valid
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/parser_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'rails_helper'

describe ParserVersion do
let(:parser) { Parser.new(name: 'Europeana', id: '123', data_type: 'Record', source: source) }
let(:parser) { Parser.new(name: 'Europeana', id: '123', data_type: 'Record', source:) }
let(:parser_version) { ParserVersion.new(parser_id: '123') }
let(:parser_version_no_job) { ParserVersion.new(parser_id: '1') }
let(:job) { mock_model(HarvestJob).as_null_object }
Expand Down
8 changes: 4 additions & 4 deletions spec/workers/enrichment_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,21 +300,21 @@ def self.get_source_id
let(:block) { proc { 'Hi' } }

before(:each) do
allow(parser).to receive(:enrichment_definitions) { { ndha_rights: { block: block } } }
allow(parser).to receive(:enrichment_definitions) { { ndha_rights: { block: } } }
end

it 'should fetch the enrichment definition options' do
job.enrichment = 'ndha_rights'
worker.send(:setup_parser)
expect(worker.send(:enrichment_options)).to eq(block: block)
expect(worker.send(:enrichment_options)).to eq(block:)
end
end

describe '#enrichment_class' do
let(:block) { proc { 'Hi' } }

before(:each) do
allow(parser).to receive(:enrichment_definitions) { { ndha_rights: { block: block } } }
allow(parser).to receive(:enrichment_definitions) { { ndha_rights: { block: } } }
job.enrichment = 'ndha_rights'
worker.send(:setup_parser)
end
Expand All @@ -326,7 +326,7 @@ def self.get_source_id

describe '#post_to_api' do
let(:record) { double(:record, id: 123) }
let(:enrichment) { double(:enrichment, record: record, record_attributes: { '1' => { title: 'foo' }, '2' => { category: 'books' } }) }
let(:enrichment) { double(:enrichment, record:, record_attributes: { '1' => { title: 'foo' }, '2' => { category: 'books' } }) }

it 'enqueues an ApiUpdate job with record_id, attributes (including job_id) and enrichment_job_id for each enriched record' do
worker.send(:post_to_api, enrichment)
Expand Down
4 changes: 2 additions & 2 deletions spec/workers/harvest_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
describe '#process_record' do
let(:errors) { double(:errors, full_messages: []) }
let(:record) {
double(:record, attributes: { title: 'Hi', internal_identifier: ['record123'] }, valid?: true, raw_data: '</record>', errors: errors,
double(:record, attributes: { title: 'Hi', internal_identifier: ['record123'] }, valid?: true, raw_data: '</record>', errors:,
full_raw_data: '</record>') }

context 'record' do
Expand Down Expand Up @@ -148,7 +148,7 @@
context 'concept' do
let(:record) {
double(:record, attributes: { label: ['Colin John McCahon'], internal_identifier: ['record123'], match_concepts: :create_or_match }, valid?: true,
errors: errors).as_null_object }
errors:).as_null_object }
let(:parser) { double(:parser, data_type: 'concept', concept?: true, record?: false).as_null_object }

before do
Expand Down

0 comments on commit 047256c

Please sign in to comment.