chore(rubocop): fix Rails/RootPathnameMethods and assimiled cops

This commit is contained in:
Colin Darie 2023-04-19 10:55:16 +02:00
parent 6a3fd8fc4d
commit b273e7b67e
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
8 changed files with 19 additions and 8 deletions

View file

@ -1152,6 +1152,12 @@ Style/EvenOdd:
Style/ExpandPathArguments: Style/ExpandPathArguments:
Enabled: true Enabled: true
Style/FileRead:
Enabled: true
Style/FileWrite:
Enabled: true
Style/For: Style/For:
Enabled: true Enabled: true

View file

@ -1,7 +1,7 @@
class PingController < ApplicationController class PingController < ApplicationController
def index def index
Rails.logger.silence do Rails.logger.silence do
status_code = if File.file?(Rails.root.join("maintenance")) status_code = if Rails.root.join("maintenance").file?
# See https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#4.2-http-check%20disable-on-404 # See https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#4.2-http-check%20disable-on-404
:not_found :not_found
elsif (ActiveRecord::Base.connection.execute('select 1 as test;').first['test'] == 1) elsif (ActiveRecord::Base.connection.execute('select 1 as test;').first['test'] == 1)

View file

@ -19,7 +19,7 @@ class ZxcvbnService
# #
# This is slow: loading and parsing the dictionary may take around 1s. # This is slow: loading and parsing the dictionary may take around 1s.
def build_tester def build_tester
dictionaries = YAML.safe_load(File.read(Rails.root.join("config", "initializers", "zxcvbn_dictionnaries.yaml"))) dictionaries = YAML.safe_load(Rails.root.join("config", "initializers", "zxcvbn_dictionnaries.yaml").read)
tester = Zxcvbn::Tester.new tester = Zxcvbn::Tester.new
tester.add_word_lists(dictionaries) tester.add_word_lists(dictionaries)

View file

@ -1,3 +1,3 @@
Dir[File.join(Rails.root, "lib", "core_ext", "*.rb")].each do |core_ext_file| Dir[Rails.root.join("lib", "core_ext", "*.rb")].each do |core_ext_file|
require core_ext_file require core_ext_file
end end

View file

@ -7,7 +7,7 @@ namespace :after_party do
coll_label = collectivite.labels.find_or_initialize_by(designated_on: Date.parse('1977-07-30')) coll_label = collectivite.labels.find_or_initialize_by(designated_on: Date.parse('1977-07-30'))
coll_label.update(name: 'Collectivité territoriale') coll_label.update(name: 'Collectivité territoriale')
config = Psych.safe_load(File.read(Rails.root.join("config", "zones.yml"))) config = Psych.safe_load(Rails.root.join("config", "zones.yml").read)
config["ministeres"].each do |ministere| config["ministeres"].each do |ministere|
acronym = ministere.keys.first acronym = ministere.keys.first
zone = Zone.find_or_create_by!(acronym: acronym) zone = Zone.find_or_create_by!(acronym: acronym)

View file

@ -13,8 +13,13 @@ describe PingController, type: :controller do
end end
context 'when a maintenance file is present' do context 'when a maintenance file is present' do
let(:filepath) { Rails.root.join('maintenance') }
before do before do
allow(File).to receive(:file?).and_return(true) filepath.write("")
end
after do
filepath.delete
end end
it 'tells HAProxy that the app is in maintenance, but will be available again soon' do it 'tells HAProxy that the app is in maintenance, but will be available again soon' do

View file

@ -6,7 +6,7 @@ describe WebhookController, type: :controller do
describe '#helpscout_support_dev' do describe '#helpscout_support_dev' do
subject(:response) { post :helpscout_support_dev, params: payload } subject(:response) { post :helpscout_support_dev, params: payload }
let(:payload) { JSON.parse(File.read(Rails.root.join('spec', 'fixtures', 'files', 'helpscout', 'tagged-dev.json'))) } let(:payload) { JSON.parse(Rails.root.join('spec', 'fixtures', 'files', 'helpscout', 'tagged-dev.json').read) }
let(:webhook_url) { "https://notification_url" } let(:webhook_url) { "https://notification_url" }
it 'works' do it 'works' do
allow(Rails.application.secrets).to receive(:dig).with(:mattermost, :support_webhook_url).and_return(webhook_url) allow(Rails.application.secrets).to receive(:dig).with(:mattermost, :support_webhook_url).and_return(webhook_url)
@ -68,7 +68,7 @@ describe WebhookController, type: :controller do
describe '#sendinblue' do describe '#sendinblue' do
subject(:response) { post :sendinblue, params: payload } subject(:response) { post :sendinblue, params: payload }
let(:payload) { JSON.parse(File.read(Rails.root.join('spec', 'fixtures', 'files', 'sendinblue', 'incident.json'))) } let(:payload) { JSON.parse(Rails.root.join('spec', 'fixtures', 'files', 'sendinblue', 'incident.json').read) }
it 'sends notification to mattermost' do it 'sends notification to mattermost' do
notification_url = "https://notification_url" notification_url = "https://notification_url"

View file

@ -1,6 +1,6 @@
describe 'graphql' do describe 'graphql' do
let(:current_defn) { API::V2::Schema.to_definition } let(:current_defn) { API::V2::Schema.to_definition }
let(:printout_defn) { File.read(Rails.root.join('app', 'graphql', 'schema.graphql')) } let(:printout_defn) { Rails.root.join('app', 'graphql', 'schema.graphql').read }
it "update the printed schema with `bin/rake graphql:schema:idl`" do it "update the printed schema with `bin/rake graphql:schema:idl`" do
result = GraphQL::SchemaComparator.compare(current_defn, printout_defn) result = GraphQL::SchemaComparator.compare(current_defn, printout_defn)