From: Tom Hughes Date: Fri, 9 Sep 2022 21:36:39 +0000 (+0100) Subject: Fix new rubocop warnings X-Git-Tag: live~1561 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/9cd96bd452415918be77d6d2094c021b652c9048?ds=sidebyside Fix new rubocop warnings --- diff --git a/app/controllers/preferences_controller.rb b/app/controllers/preferences_controller.rb index e098a8acc..dcf0d8b64 100644 --- a/app/controllers/preferences_controller.rb +++ b/app/controllers/preferences_controller.rb @@ -26,7 +26,7 @@ class PreferencesController < ApplicationController flash[:notice] = { :partial => "preferences/update_success_flash" } redirect_to preferences_path else - flash[:error] = t ".failure" + flash.now[:error] = t ".failure" render :edit end end diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index b48d08ad2..4005176ce 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -36,7 +36,7 @@ class ProfilesController < ApplicationController flash[:notice] = t ".success" redirect_to user_path(current_user) else - flash[:error] = t ".failure" + flash.now[:error] = t ".failure" render :edit end end diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 30cb9da7c..6d05e6a57 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -28,7 +28,7 @@ class ReportsController < ApplicationController redirect_to helpers.reportable_url(@report.issue.reportable), :notice => t(".successful_report") else - flash[:notice] = t(".provide_details") + flash.now[:notice] = t(".provide_details") render :action => "new" end end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 7bbe65ec5..33fcc7465 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -183,7 +183,7 @@ class UserMailer < ApplicationMailer end def attach_project_logo - attachments.inline["logo.png"] = File.read(Rails.root.join("app/assets/images/osm_logo_30.png")) + attachments.inline["logo.png"] = Rails.root.join("app/assets/images/osm_logo_30.png").read end def attach_user_avatar(user) @@ -199,7 +199,7 @@ class UserMailer < ApplicationMailer avatar.blob.download end else - File.read(Rails.root.join("app/assets/images/avatar_small.png")) + Rails.root.join("app/assets/images/avatar_small.png").read end end diff --git a/config/initializers/config.rb b/config/initializers/config.rb index e51281e11..7fc488635 100644 --- a/config/initializers/config.rb +++ b/config/initializers/config.rb @@ -2,7 +2,7 @@ # Otherwise, admins might not be aware that they are now silently ignored # and major problems could occur # rubocop:disable Rails/Output, Rails/Exit -if File.exist?(Rails.root.join("config/application.yml")) +if Rails.root.join("config/application.yml").exist? puts "The config/application.yml file is no longer supported." puts "" puts "Default settings are now found in config/settings.yml and you" diff --git a/lib/country.rb b/lib/country.rb index f6f679125..ca547a972 100644 --- a/lib/country.rb +++ b/lib/country.rb @@ -19,7 +19,7 @@ class Country def self.load_countries countries = {} - xml = REXML::Document.new(File.read(Rails.root.join("config/countries.xml"))) + xml = REXML::Document.new(Rails.root.join("config/countries.xml").read) xml.elements.each("geonames/country") do |ele| code = ele.get_text("countryCode").to_s diff --git a/test/models/trace_test.rb b/test/models/trace_test.rb index 8fa09f4d7..762df6648 100644 --- a/test/models/trace_test.rb +++ b/test/models/trace_test.rb @@ -166,14 +166,14 @@ class TraceTest < ActiveSupport::TestCase end def test_large_picture - picture = File.read(Rails.root.join("test/gpx/fixtures/a.gif"), :mode => "rb") + picture = Rails.root.join("test/gpx/fixtures/a.gif").read(:mode => "rb") trace = create(:trace, :fixture => "a") assert_equal picture, trace.large_picture end def test_icon_picture - picture = File.read(Rails.root.join("test/gpx/fixtures/a_icon.gif"), :mode => "rb") + picture = Rails.root.join("test/gpx/fixtures/a_icon.gif").read(:mode => "rb") trace = create(:trace, :fixture => "a") assert_equal picture, trace.icon_picture