From bfffe7ed96e1aba434ca40b488264c43d8f679ff Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 13 Nov 2020 11:32:28 +0000 Subject: [PATCH] Prefer string interpolation to concatenation --- .rubocop_todo.yml | 12 ---------- app/helpers/browse_tags_helper.rb | 4 ++-- app/helpers/user_roles_helper.rb | 2 +- app/jobs/trace_importer_job.rb | 2 +- app/models/client_application.rb | 2 +- app/views/changesets/index.atom.builder | 2 +- lib/migrate.rb | 22 ++++++++++++++----- lib/potlatch.rb | 2 +- script/cleanup | 2 +- script/deliver-message | 2 +- script/statistics | 2 +- script/update-spam-blocks | 2 +- .../api/relations_controller_test.rb | 4 ++-- 13 files changed, 30 insertions(+), 30 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2a960db7a..406a13265 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -177,16 +177,4 @@ Style/NumericLiterals: # Cop supports --auto-correct. Style/StringConcatenation: Exclude: - - 'app/helpers/browse_tags_helper.rb' - - 'app/helpers/user_roles_helper.rb' - - 'app/jobs/trace_importer_job.rb' - - 'app/models/client_application.rb' - - 'app/views/changesets/index.atom.builder' - - 'lib/migrate.rb' - - 'lib/potlatch.rb' - - 'script/cleanup' - - 'script/deliver-message' - - 'script/statistics' - - 'script/update-spam-blocks' - - 'test/controllers/api/relations_controller_test.rb' - 'test/helpers/user_roles_helper_test.rb' diff --git a/app/helpers/browse_tags_helper.rb b/app/helpers/browse_tags_helper.rb index 1c36743f8..146664914 100644 --- a/app/helpers/browse_tags_helper.rb +++ b/app/helpers/browse_tags_helper.rb @@ -84,8 +84,8 @@ module BrowseTagsHelper # Contains a reference to a section of the wikipedia article # Must break it up to correctly build the url value = Regexp.last_match(1) - section = "#" + Regexp.last_match(2) - encoded_section = "#" + CGI.escape(Regexp.last_match(2).gsub(/ +/, "_")).tr("%", ".") + section = "##{Regexp.last_match(2)}" + encoded_section = "##{CGI.escape(Regexp.last_match(2).gsub(/ +/, '_')).tr('%', '.')}" else section = "" encoded_section = "" diff --git a/app/helpers/user_roles_helper.rb b/app/helpers/user_roles_helper.rb index 438076592..384fb7280 100644 --- a/app/helpers/user_roles_helper.rb +++ b/app/helpers/user_roles_helper.rb @@ -1,7 +1,7 @@ module UserRolesHelper def role_icons(user) UserRole::ALL_ROLES.reduce("".html_safe) do |acc, elem| - acc + " " + role_icon(user, elem) + "#{acc} #{role_icon(user, elem)}" end end diff --git a/app/jobs/trace_importer_job.rb b/app/jobs/trace_importer_job.rb index 1eddcb6f8..940dd6c79 100644 --- a/app/jobs/trace_importer_job.rb +++ b/app/jobs/trace_importer_job.rb @@ -13,7 +13,7 @@ class TraceImporterJob < ApplicationJob rescue StandardError => e logger.info e.to_s e.backtrace.each { |l| logger.info l } - UserMailer.gpx_failure(trace, e.to_s + "\n" + e.backtrace.join("\n")).deliver + UserMailer.gpx_failure(trace, "#{e}\n#{e.backtrace.join("\n")}").deliver trace.destroy end end diff --git a/app/models/client_application.rb b/app/models/client_application.rb index b3abb82be..ee39c294b 100644 --- a/app/models/client_application.rb +++ b/app/models/client_application.rb @@ -66,7 +66,7 @@ class ClientApplication < ApplicationRecord end def oauth_server - @oauth_server ||= OAuth::Server.new("https://" + Settings.server_url) + @oauth_server ||= OAuth::Server.new("https://#{Settings.server_url}") end def credentials diff --git a/app/views/changesets/index.atom.builder b/app/views/changesets/index.atom.builder index 2bbae2cc2..7fd9b5dd2 100644 --- a/app/views/changesets/index.atom.builder +++ b/app/views/changesets/index.atom.builder @@ -79,7 +79,7 @@ atom_feed(:language => I18n.locale, :schema_date => 2009, lower_corner = "#{bbox.min_lat} #{bbox.min_lon}" upper_corner = "#{bbox.max_lat} #{bbox.max_lon}" - feed.georss :box, lower_corner + " " + upper_corner + feed.georss :box, "#{lower_corner} #{upper_corner}" end end end diff --git a/lib/migrate.rb b/lib/migrate.rb index 182a2a086..d87d14bbb 100644 --- a/lib/migrate.rb +++ b/lib/migrate.rb @@ -14,16 +14,25 @@ module OpenStreetMap end def add_primary_key(table_name, column_name, _options = {}) - execute "ALTER TABLE #{quote_table_name(table_name)} ADD PRIMARY KEY (#{quote_column_name(column_name)})" + table_name = quote_table_name(table_name) + column_name = quote_column_name(column_name) + + execute "ALTER TABLE #{table_name} ADD PRIMARY KEY (#{column_name})" end def remove_primary_key(table_name) - execute "ALTER TABLE #{quote_table_name(table_name)} DROP PRIMARY KEY" + table_name = quote_table_name(table_name) + + execute "ALTER TABLE #{table_name} DROP PRIMARY KEY" end def alter_primary_key(table_name, new_columns) - execute "ALTER TABLE #{quote_table_name(table_name)} DROP CONSTRAINT #{quote_table_name(table_name + '_pkey')}" - execute "ALTER TABLE #{quote_table_name(table_name)} ADD PRIMARY KEY (#{quote_column_name(new_columns)})" + constraint_name = quote_table_name("#{table_name}_pkey") + table_name = quote_table_name(table_name) + new_columns = quote_column_name(new_columns) + + execute "ALTER TABLE #{table_name} DROP CONSTRAINT #{constraint_name}" + execute "ALTER TABLE #{table_name} ADD PRIMARY KEY (#{new_columns})" end def create_enumeration(enumeration_name, values) @@ -35,7 +44,10 @@ module OpenStreetMap end def rename_enumeration(old_name, new_name) - execute "ALTER TYPE #{quote_table_name(old_name)} RENAME TO #{quote_table_name(new_name)}" + old_name = quote_table_name(old_name) + new_name = quote_table_name(new_name) + + execute "ALTER TYPE #{old_name} RENAME TO #{new_name}" end end end diff --git a/lib/potlatch.rb b/lib/potlatch.rb index 4d9fd1c23..605d69db3 100644 --- a/lib/potlatch.rb +++ b/lib/potlatch.rb @@ -62,7 +62,7 @@ module Potlatch # Envelope data into AMF writeable form def self.putdata(index, n) - d = encodestring(index + "/onResult") + d = encodestring("#{index}/onResult") d += encodestring("null") d += [-1].pack("N") d += encodevalue(n) diff --git a/script/cleanup b/script/cleanup index 983a3d458..67cc0705e 100755 --- a/script/cleanup +++ b/script/cleanup @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + "/../config/environment" +require File.join(File.dirname(__FILE__), "..", "config", "environment") UserToken.where("expiry < NOW()").delete_all OauthNonce.where("timestamp < EXTRACT(EPOCH FROM NOW() - INTERVAL '1 day')").delete_all diff --git a/script/deliver-message b/script/deliver-message index 047969532..71fa4f2f1 100755 --- a/script/deliver-message +++ b/script/deliver-message @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + "/../config/environment" +require File.join(File.dirname(__FILE__), "..", "config", "environment") if recipient = ARGV[0].match(/^c-(\d+)-(\d+)-(.*)$/) comment = DiaryComment.find(recipient[1]) diff --git a/script/statistics b/script/statistics index 8b79523b7..33205fe62 100755 --- a/script/statistics +++ b/script/statistics @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + "/../config/environment" +require File.join(File.dirname(__FILE__), "..", "config", "environment") start_time = Time.now diff --git a/script/update-spam-blocks b/script/update-spam-blocks index 86e853cfc..40f2cb03c 100755 --- a/script/update-spam-blocks +++ b/script/update-spam-blocks @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + "/../config/environment" +require File.join(File.dirname(__FILE__), "..", "config", "environment") require "generator" addresses = User.count( diff --git a/test/controllers/api/relations_controller_test.rb b/test/controllers/api/relations_controller_test.rb index de24c087d..44c6cd4ee 100644 --- a/test/controllers/api/relations_controller_test.rb +++ b/test/controllers/api/relations_controller_test.rb @@ -245,7 +245,7 @@ module Api # create an relation with a node as member, this time test that we don't # need a role attribute to be included xml = "" \ - "" + "" + "" put relation_create_path, :params => xml, :headers => auth_header # hope for forbidden due to user assert_response :forbidden, @@ -322,7 +322,7 @@ module Api # create an relation with a node as member, this time test that we don't # need a role attribute to be included xml = "" \ - "" + "" + "" put relation_create_path, :params => xml, :headers => auth_header # hope for success assert_response :success, -- 2.39.5