mirror of https://github.com/rails/rails
Upgrade Rubocop to 0.61.1 and fix offenses
This commit is contained in:
parent
cf71f31e2e
commit
3b7a4d3d75
|
@ -399,7 +399,7 @@ GEM
|
||||||
resque (~> 1.26)
|
resque (~> 1.26)
|
||||||
rufus-scheduler (~> 3.2)
|
rufus-scheduler (~> 3.2)
|
||||||
retriable (3.1.2)
|
retriable (3.1.2)
|
||||||
rubocop (0.60.0)
|
rubocop (0.61.1)
|
||||||
jaro_winkler (~> 1.5.1)
|
jaro_winkler (~> 1.5.1)
|
||||||
parallel (~> 1.10)
|
parallel (~> 1.10)
|
||||||
parser (>= 2.5, != 2.5.1.1)
|
parser (>= 2.5, != 2.5.1.1)
|
||||||
|
|
|
@ -79,108 +79,108 @@ module ActionDispatch
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def add_params(path, params)
|
def add_params(path, params)
|
||||||
params = { params: params } unless params.is_a?(Hash)
|
params = { params: params } unless params.is_a?(Hash)
|
||||||
params.reject! { |_, v| v.to_param.nil? }
|
params.reject! { |_, v| v.to_param.nil? }
|
||||||
query = params.to_query
|
query = params.to_query
|
||||||
path << "?#{query}" unless query.empty?
|
path << "?#{query}" unless query.empty?
|
||||||
end
|
|
||||||
|
|
||||||
def add_anchor(path, anchor)
|
|
||||||
if anchor
|
|
||||||
path << "##{Journey::Router::Utils.escape_fragment(anchor.to_param)}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def extract_domain_from(host, tld_length)
|
|
||||||
host.split(".").last(1 + tld_length).join(".")
|
|
||||||
end
|
|
||||||
|
|
||||||
def extract_subdomains_from(host, tld_length)
|
|
||||||
parts = host.split(".")
|
|
||||||
parts[0..-(tld_length + 2)]
|
|
||||||
end
|
|
||||||
|
|
||||||
def add_trailing_slash(path)
|
|
||||||
if path.include?("?")
|
|
||||||
path.sub!(/\?/, '/\&')
|
|
||||||
elsif !path.include?(".")
|
|
||||||
path.sub!(/[^\/]\z|\A\z/, '\&/')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def build_host_url(host, port, protocol, options, path)
|
|
||||||
if match = host.match(HOST_REGEXP)
|
|
||||||
protocol ||= match[1] unless protocol == false
|
|
||||||
host = match[2]
|
|
||||||
port = match[3] unless options.key? :port
|
|
||||||
end
|
end
|
||||||
|
|
||||||
protocol = normalize_protocol protocol
|
def add_anchor(path, anchor)
|
||||||
host = normalize_host(host, options)
|
if anchor
|
||||||
|
path << "##{Journey::Router::Utils.escape_fragment(anchor.to_param)}"
|
||||||
result = protocol.dup
|
end
|
||||||
|
|
||||||
if options[:user] && options[:password]
|
|
||||||
result << "#{Rack::Utils.escape(options[:user])}:#{Rack::Utils.escape(options[:password])}@"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
result << host
|
def extract_domain_from(host, tld_length)
|
||||||
normalize_port(port, protocol) { |normalized_port|
|
host.split(".").last(1 + tld_length).join(".")
|
||||||
result << ":#{normalized_port}"
|
|
||||||
}
|
|
||||||
|
|
||||||
result.concat path
|
|
||||||
end
|
|
||||||
|
|
||||||
def named_host?(host)
|
|
||||||
IP_HOST_REGEXP !~ host
|
|
||||||
end
|
|
||||||
|
|
||||||
def normalize_protocol(protocol)
|
|
||||||
case protocol
|
|
||||||
when nil
|
|
||||||
"http://"
|
|
||||||
when false, "//"
|
|
||||||
"//"
|
|
||||||
when PROTOCOL_REGEXP
|
|
||||||
"#{$1}://"
|
|
||||||
else
|
|
||||||
raise ArgumentError, "Invalid :protocol option: #{protocol.inspect}"
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def normalize_host(_host, options)
|
def extract_subdomains_from(host, tld_length)
|
||||||
return _host unless named_host?(_host)
|
parts = host.split(".")
|
||||||
|
parts[0..-(tld_length + 2)]
|
||||||
tld_length = options[:tld_length] || @@tld_length
|
|
||||||
subdomain = options.fetch :subdomain, true
|
|
||||||
domain = options[:domain]
|
|
||||||
|
|
||||||
host = +""
|
|
||||||
if subdomain == true
|
|
||||||
return _host if domain.nil?
|
|
||||||
|
|
||||||
host << extract_subdomains_from(_host, tld_length).join(".")
|
|
||||||
elsif subdomain
|
|
||||||
host << subdomain.to_param
|
|
||||||
end
|
end
|
||||||
host << "." unless host.empty?
|
|
||||||
host << (domain || extract_domain_from(_host, tld_length))
|
|
||||||
host
|
|
||||||
end
|
|
||||||
|
|
||||||
def normalize_port(port, protocol)
|
def add_trailing_slash(path)
|
||||||
return unless port
|
if path.include?("?")
|
||||||
|
path.sub!(/\?/, '/\&')
|
||||||
case protocol
|
elsif !path.include?(".")
|
||||||
when "//" then yield port
|
path.sub!(/[^\/]\z|\A\z/, '\&/')
|
||||||
when "https://"
|
end
|
||||||
yield port unless port.to_i == 443
|
end
|
||||||
else
|
|
||||||
yield port unless port.to_i == 80
|
def build_host_url(host, port, protocol, options, path)
|
||||||
|
if match = host.match(HOST_REGEXP)
|
||||||
|
protocol ||= match[1] unless protocol == false
|
||||||
|
host = match[2]
|
||||||
|
port = match[3] unless options.key? :port
|
||||||
|
end
|
||||||
|
|
||||||
|
protocol = normalize_protocol protocol
|
||||||
|
host = normalize_host(host, options)
|
||||||
|
|
||||||
|
result = protocol.dup
|
||||||
|
|
||||||
|
if options[:user] && options[:password]
|
||||||
|
result << "#{Rack::Utils.escape(options[:user])}:#{Rack::Utils.escape(options[:password])}@"
|
||||||
|
end
|
||||||
|
|
||||||
|
result << host
|
||||||
|
normalize_port(port, protocol) { |normalized_port|
|
||||||
|
result << ":#{normalized_port}"
|
||||||
|
}
|
||||||
|
|
||||||
|
result.concat path
|
||||||
|
end
|
||||||
|
|
||||||
|
def named_host?(host)
|
||||||
|
IP_HOST_REGEXP !~ host
|
||||||
|
end
|
||||||
|
|
||||||
|
def normalize_protocol(protocol)
|
||||||
|
case protocol
|
||||||
|
when nil
|
||||||
|
"http://"
|
||||||
|
when false, "//"
|
||||||
|
"//"
|
||||||
|
when PROTOCOL_REGEXP
|
||||||
|
"#{$1}://"
|
||||||
|
else
|
||||||
|
raise ArgumentError, "Invalid :protocol option: #{protocol.inspect}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def normalize_host(_host, options)
|
||||||
|
return _host unless named_host?(_host)
|
||||||
|
|
||||||
|
tld_length = options[:tld_length] || @@tld_length
|
||||||
|
subdomain = options.fetch :subdomain, true
|
||||||
|
domain = options[:domain]
|
||||||
|
|
||||||
|
host = +""
|
||||||
|
if subdomain == true
|
||||||
|
return _host if domain.nil?
|
||||||
|
|
||||||
|
host << extract_subdomains_from(_host, tld_length).join(".")
|
||||||
|
elsif subdomain
|
||||||
|
host << subdomain.to_param
|
||||||
|
end
|
||||||
|
host << "." unless host.empty?
|
||||||
|
host << (domain || extract_domain_from(_host, tld_length))
|
||||||
|
host
|
||||||
|
end
|
||||||
|
|
||||||
|
def normalize_port(port, protocol)
|
||||||
|
return unless port
|
||||||
|
|
||||||
|
case protocol
|
||||||
|
when "//" then yield port
|
||||||
|
when "https://"
|
||||||
|
yield port unless port.to_i == 443
|
||||||
|
else
|
||||||
|
yield port unless port.to_i == 80
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
|
|
|
@ -573,49 +573,49 @@ module ActiveRecord
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def read_and_insert(fixtures_directory, fixture_files, class_names, connection) # :nodoc:
|
def read_and_insert(fixtures_directory, fixture_files, class_names, connection) # :nodoc:
|
||||||
fixtures_map = {}
|
fixtures_map = {}
|
||||||
fixture_sets = fixture_files.map do |fixture_set_name|
|
fixture_sets = fixture_files.map do |fixture_set_name|
|
||||||
klass = class_names[fixture_set_name]
|
klass = class_names[fixture_set_name]
|
||||||
fixtures_map[fixture_set_name] = new( # ActiveRecord::FixtureSet.new
|
fixtures_map[fixture_set_name] = new( # ActiveRecord::FixtureSet.new
|
||||||
nil,
|
nil,
|
||||||
fixture_set_name,
|
fixture_set_name,
|
||||||
klass,
|
klass,
|
||||||
::File.join(fixtures_directory, fixture_set_name)
|
::File.join(fixtures_directory, fixture_set_name)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
update_all_loaded_fixtures(fixtures_map)
|
update_all_loaded_fixtures(fixtures_map)
|
||||||
|
|
||||||
insert(fixture_sets, connection)
|
insert(fixture_sets, connection)
|
||||||
|
|
||||||
fixtures_map
|
fixtures_map
|
||||||
end
|
|
||||||
|
|
||||||
def insert(fixture_sets, connection) # :nodoc:
|
|
||||||
fixture_sets_by_connection = fixture_sets.group_by do |fixture_set|
|
|
||||||
fixture_set.model_class&.connection || connection
|
|
||||||
end
|
end
|
||||||
|
|
||||||
fixture_sets_by_connection.each do |conn, set|
|
def insert(fixture_sets, connection) # :nodoc:
|
||||||
table_rows_for_connection = Hash.new { |h, k| h[k] = [] }
|
fixture_sets_by_connection = fixture_sets.group_by do |fixture_set|
|
||||||
|
fixture_set.model_class&.connection || connection
|
||||||
|
end
|
||||||
|
|
||||||
set.each do |fixture_set|
|
fixture_sets_by_connection.each do |conn, set|
|
||||||
fixture_set.table_rows.each do |table, rows|
|
table_rows_for_connection = Hash.new { |h, k| h[k] = [] }
|
||||||
table_rows_for_connection[table].unshift(*rows)
|
|
||||||
|
set.each do |fixture_set|
|
||||||
|
fixture_set.table_rows.each do |table, rows|
|
||||||
|
table_rows_for_connection[table].unshift(*rows)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
conn.insert_fixtures_set(table_rows_for_connection, table_rows_for_connection.keys)
|
||||||
|
|
||||||
|
# Cap primary key sequences to max(pk).
|
||||||
|
if conn.respond_to?(:reset_pk_sequence!)
|
||||||
|
set.each { |fs| conn.reset_pk_sequence!(fs.table_name) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
conn.insert_fixtures_set(table_rows_for_connection, table_rows_for_connection.keys)
|
|
||||||
|
|
||||||
# Cap primary key sequences to max(pk).
|
|
||||||
if conn.respond_to?(:reset_pk_sequence!)
|
|
||||||
set.each { |fs| conn.reset_pk_sequence!(fs.table_name) }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def update_all_loaded_fixtures(fixtures_map) # :nodoc:
|
def update_all_loaded_fixtures(fixtures_map) # :nodoc:
|
||||||
all_loaded_fixtures.update(fixtures_map)
|
all_loaded_fixtures.update(fixtures_map)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :table_name, :name, :fixtures, :model_class, :config
|
attr_reader :table_name, :name, :fixtures, :model_class, :config
|
||||||
|
|
|
@ -48,9 +48,9 @@ module ActiveRecord
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def current_adapter_name
|
def current_adapter_name
|
||||||
ActiveRecord::Base.connection.adapter_name.downcase.to_sym
|
ActiveRecord::Base.connection.adapter_name.downcase.to_sym
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
BigInteger = ActiveModel::Type::BigInteger
|
BigInteger = ActiveModel::Type::BigInteger
|
||||||
|
|
|
@ -13,34 +13,34 @@ module ARTest
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def config_file
|
def config_file
|
||||||
Pathname.new(ENV["ARCONFIG"] || TEST_ROOT + "/config.yml")
|
Pathname.new(ENV["ARCONFIG"] || TEST_ROOT + "/config.yml")
|
||||||
end
|
|
||||||
|
|
||||||
def read_config
|
|
||||||
unless config_file.exist?
|
|
||||||
FileUtils.cp TEST_ROOT + "/config.example.yml", config_file
|
|
||||||
end
|
end
|
||||||
|
|
||||||
erb = ERB.new(config_file.read)
|
def read_config
|
||||||
expand_config(YAML.parse(erb.result(binding)).transform)
|
unless config_file.exist?
|
||||||
end
|
FileUtils.cp TEST_ROOT + "/config.example.yml", config_file
|
||||||
|
|
||||||
def expand_config(config)
|
|
||||||
config["connections"].each do |adapter, connection|
|
|
||||||
dbs = [["arunit", "activerecord_unittest"], ["arunit2", "activerecord_unittest2"],
|
|
||||||
["arunit_without_prepared_statements", "activerecord_unittest"]]
|
|
||||||
dbs.each do |name, dbname|
|
|
||||||
unless connection[name].is_a?(Hash)
|
|
||||||
connection[name] = { "database" => connection[name] }
|
|
||||||
end
|
|
||||||
|
|
||||||
connection[name]["database"] ||= dbname
|
|
||||||
connection[name]["adapter"] ||= adapter
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
erb = ERB.new(config_file.read)
|
||||||
|
expand_config(YAML.parse(erb.result(binding)).transform)
|
||||||
end
|
end
|
||||||
|
|
||||||
config
|
def expand_config(config)
|
||||||
end
|
config["connections"].each do |adapter, connection|
|
||||||
|
dbs = [["arunit", "activerecord_unittest"], ["arunit2", "activerecord_unittest2"],
|
||||||
|
["arunit_without_prepared_statements", "activerecord_unittest"]]
|
||||||
|
dbs.each do |name, dbname|
|
||||||
|
unless connection[name].is_a?(Hash)
|
||||||
|
connection[name] = { "database" => connection[name] }
|
||||||
|
end
|
||||||
|
|
||||||
|
connection[name]["database"] ||= dbname
|
||||||
|
connection[name]["adapter"] ||= adapter
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
config
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,12 +38,13 @@ module ActiveSupport
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def accumulate_descendants(klass, acc)
|
|
||||||
if direct_descendants = @@direct_descendants[klass]
|
def accumulate_descendants(klass, acc)
|
||||||
acc.concat(direct_descendants)
|
if direct_descendants = @@direct_descendants[klass]
|
||||||
direct_descendants.each { |direct_descendant| accumulate_descendants(direct_descendant, acc) }
|
acc.concat(direct_descendants)
|
||||||
|
direct_descendants.each { |direct_descendant| accumulate_descendants(direct_descendant, acc) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def inherited(base)
|
def inherited(base)
|
||||||
|
|
|
@ -45,32 +45,32 @@ module ActiveSupport
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def convert_dates_from(data)
|
def convert_dates_from(data)
|
||||||
case data
|
case data
|
||||||
when nil
|
when nil
|
||||||
nil
|
nil
|
||||||
when DATE_REGEX
|
when DATE_REGEX
|
||||||
begin
|
begin
|
||||||
Date.parse(data)
|
Date.parse(data)
|
||||||
rescue ArgumentError
|
rescue ArgumentError
|
||||||
|
data
|
||||||
|
end
|
||||||
|
when DATETIME_REGEX
|
||||||
|
begin
|
||||||
|
Time.zone.parse(data)
|
||||||
|
rescue ArgumentError
|
||||||
|
data
|
||||||
|
end
|
||||||
|
when Array
|
||||||
|
data.map! { |d| convert_dates_from(d) }
|
||||||
|
when Hash
|
||||||
|
data.each do |key, value|
|
||||||
|
data[key] = convert_dates_from(value)
|
||||||
|
end
|
||||||
|
else
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
when DATETIME_REGEX
|
|
||||||
begin
|
|
||||||
Time.zone.parse(data)
|
|
||||||
rescue ArgumentError
|
|
||||||
data
|
|
||||||
end
|
|
||||||
when Array
|
|
||||||
data.map! { |d| convert_dates_from(d) }
|
|
||||||
when Hash
|
|
||||||
data.each do |key, value|
|
|
||||||
data[key] = convert_dates_from(value)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
data
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,23 +39,23 @@ module Rails
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# parse possible attribute options like :limit for string/text/binary/integer, :precision/:scale for decimals or :polymorphic for references/belongs_to
|
# parse possible attribute options like :limit for string/text/binary/integer, :precision/:scale for decimals or :polymorphic for references/belongs_to
|
||||||
# when declaring options curly brackets should be used
|
# when declaring options curly brackets should be used
|
||||||
def parse_type_and_options(type)
|
def parse_type_and_options(type)
|
||||||
case type
|
case type
|
||||||
when /(string|text|binary|integer)\{(\d+)\}/
|
when /(string|text|binary|integer)\{(\d+)\}/
|
||||||
return $1, limit: $2.to_i
|
return $1, limit: $2.to_i
|
||||||
when /decimal\{(\d+)[,.-](\d+)\}/
|
when /decimal\{(\d+)[,.-](\d+)\}/
|
||||||
return :decimal, precision: $1.to_i, scale: $2.to_i
|
return :decimal, precision: $1.to_i, scale: $2.to_i
|
||||||
when /(references|belongs_to)\{(.+)\}/
|
when /(references|belongs_to)\{(.+)\}/
|
||||||
type = $1
|
type = $1
|
||||||
provided_options = $2.split(/[,.-]/)
|
provided_options = $2.split(/[,.-]/)
|
||||||
options = Hash[provided_options.map { |opt| [opt.to_sym, true] }]
|
options = Hash[provided_options.map { |opt| [opt.to_sym, true] }]
|
||||||
return type, options
|
return type, options
|
||||||
else
|
else
|
||||||
return type, {}
|
return type, {}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(name, type = nil, index_type = false, attr_options = {})
|
def initialize(name, type = nil, index_type = false, attr_options = {})
|
||||||
|
|
Loading…
Reference in New Issue