Rubocop fixes for ruby 2.5
This commit is contained in:
parent
3eb6d15db1
commit
773ef195d4
8 changed files with 41 additions and 53 deletions
|
@ -1,7 +1,7 @@
|
||||||
inherit_from: .rubocop_todo.yml
|
inherit_from: .rubocop_todo.yml
|
||||||
|
|
||||||
AllCops:
|
AllCops:
|
||||||
TargetRubyVersion: 2.3
|
TargetRubyVersion: 2.5
|
||||||
|
|
||||||
Rails:
|
Rails:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
|
@ -17,11 +17,11 @@ class GeocoderController < ApplicationController
|
||||||
@sources.push "osm_nominatim_reverse"
|
@sources.push "osm_nominatim_reverse"
|
||||||
@sources.push "geonames_reverse" if Settings.key?(:geonames_username)
|
@sources.push "geonames_reverse" if Settings.key?(:geonames_username)
|
||||||
elsif @params[:query]
|
elsif @params[:query]
|
||||||
if @params[:query] =~ /^\d{5}(-\d{4})?$/
|
if /^\d{5}(-\d{4})?$/.match?(@params[:query])
|
||||||
@sources.push "osm_nominatim"
|
@sources.push "osm_nominatim"
|
||||||
elsif @params[:query] =~ /^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i
|
elsif /^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i.match?(@params[:query])
|
||||||
@sources.push "osm_nominatim"
|
@sources.push "osm_nominatim"
|
||||||
elsif @params[:query] =~ /^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i
|
elsif /^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i.match?(@params[:query])
|
||||||
@sources.push "ca_postcode"
|
@sources.push "ca_postcode"
|
||||||
@sources.push "osm_nominatim"
|
@sources.push "osm_nominatim"
|
||||||
else
|
else
|
||||||
|
|
|
@ -120,7 +120,7 @@ module BrowseTagsHelper
|
||||||
#
|
#
|
||||||
# Also accepting / as a visual separator although not given in RFC 3966,
|
# Also accepting / as a visual separator although not given in RFC 3966,
|
||||||
# because it is used as a visual separator in OSM data in some countries.
|
# because it is used as a visual separator in OSM data in some countries.
|
||||||
if value =~ %r{^\s*\+[\d\s\(\)/\.-]{6,25}\s*(;\s*\+[\d\s\(\)/\.-]{6,25}\s*)*$}
|
if %r{^\s*\+[\d\s\(\)/\.-]{6,25}\s*(;\s*\+[\d\s\(\)/\.-]{6,25}\s*)*$}.match?(value)
|
||||||
return value.split(";").map do |phone_number|
|
return value.split(";").map do |phone_number|
|
||||||
# for display, remove leading and trailing whitespace
|
# for display, remove leading and trailing whitespace
|
||||||
phone_number = phone_number.strip
|
phone_number = phone_number.strip
|
||||||
|
|
|
@ -15,14 +15,12 @@ class Language < ActiveRecord::Base
|
||||||
def self.load(file)
|
def self.load(file)
|
||||||
Language.transaction do
|
Language.transaction do
|
||||||
YAML.safe_load(File.read(file)).each do |k, v|
|
YAML.safe_load(File.read(file)).each do |k, v|
|
||||||
begin
|
Language.update(k, :english_name => v["english"], :native_name => v["native"])
|
||||||
Language.update(k, :english_name => v["english"], :native_name => v["native"])
|
rescue ActiveRecord::RecordNotFound
|
||||||
rescue ActiveRecord::RecordNotFound
|
Language.create do |l|
|
||||||
Language.create do |l|
|
l.code = k
|
||||||
l.code = k
|
l.english_name = v["english"]
|
||||||
l.english_name = v["english"]
|
l.native_name = v["native"]
|
||||||
l.native_name = v["native"]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
12
bin/yarn
12
bin/yarn
|
@ -1,11 +1,9 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
APP_ROOT = File.expand_path("..", __dir__)
|
APP_ROOT = File.expand_path("..", __dir__)
|
||||||
Dir.chdir(APP_ROOT) do
|
Dir.chdir(APP_ROOT) do
|
||||||
begin
|
exec "yarnpkg", *ARGV
|
||||||
exec "yarnpkg", *ARGV
|
rescue Errno::ENOENT
|
||||||
rescue Errno::ENOENT
|
warn "Yarn executable was not detected in the system."
|
||||||
warn "Yarn executable was not detected in the system."
|
warn "Download Yarn at https://yarnpkg.com/en/docs/install"
|
||||||
warn "Download Yarn at https://yarnpkg.com/en/docs/install"
|
exit 1
|
||||||
exit 1
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,7 @@ module PasswordHash
|
||||||
def self.check(hash, salt, candidate)
|
def self.check(hash, salt, candidate)
|
||||||
if salt.nil?
|
if salt.nil?
|
||||||
candidate = Digest::MD5.hexdigest(candidate)
|
candidate = Digest::MD5.hexdigest(candidate)
|
||||||
elsif salt =~ /!/
|
elsif /!/.match?(salt)
|
||||||
algorithm, iterations, salt = salt.split("!")
|
algorithm, iterations, salt = salt.split("!")
|
||||||
size = Base64.strict_decode64(hash).length
|
size = Base64.strict_decode64(hash).length
|
||||||
candidate = self.hash(candidate, salt, iterations.to_i, size, algorithm)
|
candidate = self.hash(candidate, salt, iterations.to_i, size, algorithm)
|
||||||
|
@ -32,7 +32,7 @@ module PasswordHash
|
||||||
def self.upgrade?(hash, salt)
|
def self.upgrade?(hash, salt)
|
||||||
if salt.nil?
|
if salt.nil?
|
||||||
return true
|
return true
|
||||||
elsif salt =~ /!/
|
elsif /!/.match?(salt)
|
||||||
algorithm, iterations, salt = salt.split("!")
|
algorithm, iterations, salt = salt.split("!")
|
||||||
return true if Base64.strict_decode64(salt).length != SALT_BYTE_SIZE
|
return true if Base64.strict_decode64(salt).length != SALT_BYTE_SIZE
|
||||||
return true if Base64.strict_decode64(hash).length != HASH_BYTE_SIZE
|
return true if Base64.strict_decode64(hash).length != HASH_BYTE_SIZE
|
||||||
|
|
|
@ -165,12 +165,10 @@ module Api
|
||||||
# check that a changeset that doesn't exist returns an appropriate message
|
# check that a changeset that doesn't exist returns an appropriate message
|
||||||
def test_show_not_found
|
def test_show_not_found
|
||||||
[0, -32, 233455644, "afg", "213"].each do |id|
|
[0, -32, 233455644, "afg", "213"].each do |id|
|
||||||
begin
|
get :show, :params => { :id => id }
|
||||||
get :show, :params => { :id => id }
|
assert_response :not_found, "should get a not found"
|
||||||
assert_response :not_found, "should get a not found"
|
rescue ActionController::UrlGenerationError => ex
|
||||||
rescue ActionController::UrlGenerationError => ex
|
assert_match(/No route matches/, ex.to_s)
|
||||||
assert_match(/No route matches/, ex.to_s)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -239,23 +237,19 @@ module Api
|
||||||
|
|
||||||
# First try to do it with no auth
|
# First try to do it with no auth
|
||||||
cs_ids.each do |id|
|
cs_ids.each do |id|
|
||||||
begin
|
put :close, :params => { :id => id }
|
||||||
put :close, :params => { :id => id }
|
assert_response :unauthorized, "Shouldn't be able close the non-existant changeset #{id}, when not authorized"
|
||||||
assert_response :unauthorized, "Shouldn't be able close the non-existant changeset #{id}, when not authorized"
|
rescue ActionController::UrlGenerationError => ex
|
||||||
rescue ActionController::UrlGenerationError => ex
|
assert_match(/No route matches/, ex.to_s)
|
||||||
assert_match(/No route matches/, ex.to_s)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Now try with auth
|
# Now try with auth
|
||||||
basic_authorization create(:user).email, "test"
|
basic_authorization create(:user).email, "test"
|
||||||
cs_ids.each do |id|
|
cs_ids.each do |id|
|
||||||
begin
|
put :close, :params => { :id => id }
|
||||||
put :close, :params => { :id => id }
|
assert_response :not_found, "The changeset #{id} doesn't exist, so can't be closed"
|
||||||
assert_response :not_found, "The changeset #{id} doesn't exist, so can't be closed"
|
rescue ActionController::UrlGenerationError => ex
|
||||||
rescue ActionController::UrlGenerationError => ex
|
assert_match(/No route matches/, ex.to_s)
|
||||||
assert_match(/No route matches/, ex.to_s)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -53,20 +53,18 @@ class MessageTest < ActiveSupport::TestCase
|
||||||
"\x82\x82", # multibyte continuations without multibyte identifier
|
"\x82\x82", # multibyte continuations without multibyte identifier
|
||||||
"\xe1\x82\x4a"] # three-byte identifier, contination and (incorrectly) plain ASCII
|
"\xe1\x82\x4a"] # three-byte identifier, contination and (incorrectly) plain ASCII
|
||||||
invalid_sequences.each do |char|
|
invalid_sequences.each do |char|
|
||||||
begin
|
# create a message and save to the database
|
||||||
# create a message and save to the database
|
msg = make_message(char, 1)
|
||||||
msg = make_message(char, 1)
|
# if the save throws, thats fine and the test should pass, as we're
|
||||||
# if the save throws, thats fine and the test should pass, as we're
|
# only testing invalid sequences anyway.
|
||||||
# only testing invalid sequences anyway.
|
msg.save!
|
||||||
msg.save!
|
|
||||||
|
|
||||||
# get the saved message back and check that it is identical - i.e:
|
# get the saved message back and check that it is identical - i.e:
|
||||||
# its OK to accept invalid UTF-8 as long as we return it unmodified.
|
# its OK to accept invalid UTF-8 as long as we return it unmodified.
|
||||||
db_msg = msg.class.find(msg.id)
|
db_msg = msg.class.find(msg.id)
|
||||||
assert_equal char, db_msg.title, "Database silently truncated message title"
|
assert_equal char, db_msg.title, "Database silently truncated message title"
|
||||||
rescue ArgumentError => ex
|
rescue ArgumentError => ex
|
||||||
assert_equal ex.to_s, "invalid byte sequence in UTF-8"
|
assert_equal ex.to_s, "invalid byte sequence in UTF-8"
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue