From ca63e41f761ce1d626130939a550af9e5e262e94 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Mon, 1 Aug 2022 16:26:47 +1000 Subject: [PATCH] Add latest rubocop tests and fix --- .rubocop.yml | 34 +++++++++++++++++++++++-- app/controllers/api_controller.rb | 4 +-- app/lib/morph/backup.rb | 8 +++--- app/lib/morph/database.rb | 2 +- lib/tasks/app.rake | 8 +++--- spec/controllers/api_controller_spec.rb | 4 +-- spec/lib/morph/database_spec.rb | 9 ------- spec/models/scraper_spec.rb | 2 +- 8 files changed, 46 insertions(+), 25 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 8f57e2b45..790479357 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -77,8 +77,6 @@ Metrics/PerceivedComplexity: Style/SlicingWithRange: Enabled: false -Gemspec/DateAssignment: # (new in 1.10) - Enabled: true Layout/SpaceBeforeBrackets: # (new in 1.7) Enabled: true Lint/AmbiguousAssignment: # (new in 1.7) @@ -279,3 +277,35 @@ RSpec/FactoryBot/SyntaxMethods: # new in 2.7 Enabled: true RSpec/Rails/AvoidSetupHook: # new in 2.4 Enabled: true +Gemspec/DeprecatedAttributeAssignment: # new in 1.30 + Enabled: true +Layout/LineContinuationLeadingSpace: # new in 1.31 + Enabled: true +Layout/LineContinuationSpacing: # new in 1.31 + Enabled: true +Lint/ConstantOverwrittenInRescue: # new in 1.31 + Enabled: true +Lint/NonAtomicFileOperation: # new in 1.31 + Enabled: true +Lint/RequireRangeParentheses: # new in 1.32 + Enabled: true +Style/EmptyHeredoc: # new in 1.32 + Enabled: true +Style/EnvHome: # new in 1.29 + Enabled: true +Style/MapCompactWithConditionalBlock: # new in 1.30 + Enabled: true +Rails/DotSeparatedKeys: # new in 2.15 + Enabled: true +Rails/RootPublicPath: # new in 2.15 + Enabled: true +Rails/StripHeredoc: # new in 2.15 + Enabled: true +Rails/ToFormattedS: # new in 2.15 + Enabled: true +RSpec/ChangeByZero: # new in 2.11.0 + Enabled: true +RSpec/Capybara/SpecificMatcher: # new in 2.12 + Enabled: true +RSpec/Rails/HaveHttpStatus: # new in 2.12 + Enabled: true diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index a079e9b5b..f045f6924 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -266,8 +266,8 @@ def can_run render json: { stream: "internalerr", - text: "You currently can't start a scraper run." \ - " See https://morph.io for more details" + text: "You currently can't start a scraper run. " \ + "See https://morph.io for more details" } end diff --git a/app/lib/morph/backup.rb b/app/lib/morph/backup.rb index f72d3d5af..a490461bc 100644 --- a/app/lib/morph/backup.rb +++ b/app/lib/morph/backup.rb @@ -33,8 +33,8 @@ def self.backup_mysql FileUtils.rm_f "db/backups/mysql_backup.sql.bz2" FileUtils.mkdir_p "db/backups" Rails.logger.info "Backing up MySQL..." - system "mysqldump #{mysql_auth} #{mysql_database}" \ - " > db/backups/mysql_backup.sql" + system "mysqldump #{mysql_auth} #{mysql_database} " \ + "> db/backups/mysql_backup.sql" Rails.logger.info "Compressing MySQL backup..." system "bzip2 db/backups/mysql_backup.sql" end @@ -43,8 +43,8 @@ def self.restore_mysql Rails.logger.info "Uncompressing MySQL backup..." system "bunzip2 -k db/backups/mysql_backup.sql.bz2" Rails.logger.info "Restoring from MySQL backup..." - system "mysql #{mysql_auth} #{mysql_database}" \ - " < db/backups/mysql_backup.sql" + system "mysql #{mysql_auth} #{mysql_database} " \ + "< db/backups/mysql_backup.sql" FileUtils.rm_f "db/backups/mysql_backup.sql" end diff --git a/app/lib/morph/database.rb b/app/lib/morph/database.rb index c947ccf13..4b74e36e7 100644 --- a/app/lib/morph/database.rb +++ b/app/lib/morph/database.rb @@ -181,7 +181,7 @@ def sqlite_total_rows end def clear - FileUtils.rm sqlite_db_path if File.exist?(sqlite_db_path) + FileUtils.rm_f sqlite_db_path end def write_sqlite_database(content) diff --git a/lib/tasks/app.rake b/lib/tasks/app.rake index f225bcca6..5c220475b 100644 --- a/lib/tasks/app.rake +++ b/lib/tasks/app.rake @@ -24,8 +24,8 @@ namespace :app do end end - desc "Run scrapers that need to run once per day" \ - " (this task should be called from a cron job)" + desc "Run scrapers that need to run once per day " \ + "(this task should be called from a cron job)" task auto_run_scrapers: :environment do # All the scrapers that need running in a random order scraper_ids = Scraper.where(auto_run: true).map(&:id).shuffle @@ -96,8 +96,8 @@ namespace :app do desc "Restore databases from db/backups" task restore: :environment do - if confirm "Are you sure?" \ - " This will overwrite the databases and Redis needs to be shutdown." + if confirm "Are you sure? " \ + "This will overwrite the databases and Redis needs to be shutdown." Morph::Backup.restore end end diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb index d4fe5c179..ba54d2983 100644 --- a/spec/controllers/api_controller_spec.rb +++ b/spec/controllers/api_controller_spec.rb @@ -42,8 +42,8 @@ parsed = response.body.split("\n").map { |l| JSON.parse(l) } expect(parsed).to eq [{ "stream" => "internalerr", - "text" => "You currently can't start a scraper run." \ - " See https://morph.io for more details" + "text" => "You currently can't start a scraper run. " \ + "See https://morph.io for more details" }] end diff --git a/spec/lib/morph/database_spec.rb b/spec/lib/morph/database_spec.rb index 68ee31d83..40a57e961 100644 --- a/spec/lib/morph/database_spec.rb +++ b/spec/lib/morph/database_spec.rb @@ -17,15 +17,6 @@ end end - describe "#clear" do - it "does not attempt to remove the file if it's not there" do - expect(FileUtils).not_to receive(:rm) - VCR.use_cassette("scraper_validations", allow_playback_repeats: true) do - described_class.new(create(:scraper).data_path).clear - end - end - end - describe "#backup" do it "backups the database file" do # Create a fake database file diff --git a/spec/models/scraper_spec.rb b/spec/models/scraper_spec.rb index 04fcc0844..a2c8f573d 100644 --- a/spec/models/scraper_spec.rb +++ b/spec/models/scraper_spec.rb @@ -246,7 +246,7 @@ scraper = create(:scraper) expect do scraper.deliver_webhooks(run) - end.to change(DeliverWebhookWorker.jobs, :size).by(0) + end.not_to change(DeliverWebhookWorker.jobs, :size) end end end