mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
revises most Lint/EndAlignment offenses
Some case expressions remain, need to think about those ones.
This commit is contained in:
parent
f90ee8ce27
commit
b45c9ca9b6
13 changed files with 58 additions and 55 deletions
|
@ -17,11 +17,11 @@ module ActiveModel
|
||||||
def include?(record, value)
|
def include?(record, value)
|
||||||
members = if delimiter.respond_to?(:call)
|
members = if delimiter.respond_to?(:call)
|
||||||
delimiter.call(record)
|
delimiter.call(record)
|
||||||
elsif delimiter.respond_to?(:to_sym)
|
elsif delimiter.respond_to?(:to_sym)
|
||||||
record.send(delimiter)
|
record.send(delimiter)
|
||||||
else
|
else
|
||||||
delimiter
|
delimiter
|
||||||
end
|
end
|
||||||
|
|
||||||
members.send(inclusion_method(members), value)
|
members.send(inclusion_method(members), value)
|
||||||
end
|
end
|
||||||
|
|
|
@ -221,11 +221,11 @@ module ActiveRecord
|
||||||
|
|
||||||
dependent = if dependent
|
dependent = if dependent
|
||||||
dependent
|
dependent
|
||||||
elsif options[:dependent] == :destroy
|
elsif options[:dependent] == :destroy
|
||||||
:delete_all
|
:delete_all
|
||||||
else
|
else
|
||||||
options[:dependent]
|
options[:dependent]
|
||||||
end
|
end
|
||||||
|
|
||||||
delete_or_nullify_all_records(dependent).tap do
|
delete_or_nullify_all_records(dependent).tap do
|
||||||
reset
|
reset
|
||||||
|
|
|
@ -162,9 +162,9 @@ module ActiveRecord
|
||||||
def attribute_names
|
def attribute_names
|
||||||
@attribute_names ||= if !abstract_class? && table_exists?
|
@attribute_names ||= if !abstract_class? && table_exists?
|
||||||
attribute_types.keys
|
attribute_types.keys
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if the given attribute exists, otherwise false.
|
# Returns true if the given attribute exists, otherwise false.
|
||||||
|
|
|
@ -51,11 +51,11 @@ module ActiveRecord
|
||||||
# using the #as_json hook.
|
# using the #as_json hook.
|
||||||
coder = if class_name_or_coder == ::JSON
|
coder = if class_name_or_coder == ::JSON
|
||||||
Coders::JSON
|
Coders::JSON
|
||||||
elsif [:load, :dump].all? { |x| class_name_or_coder.respond_to?(x) }
|
elsif [:load, :dump].all? { |x| class_name_or_coder.respond_to?(x) }
|
||||||
class_name_or_coder
|
class_name_or_coder
|
||||||
else
|
else
|
||||||
Coders::YAMLColumn.new(class_name_or_coder)
|
Coders::YAMLColumn.new(class_name_or_coder)
|
||||||
end
|
end
|
||||||
|
|
||||||
decorate_attribute_type(attr_name, :serialize) do |type|
|
decorate_attribute_type(attr_name, :serialize) do |type|
|
||||||
Type::Serialized.new(type, coder)
|
Type::Serialized.new(type, coder)
|
||||||
|
|
|
@ -498,14 +498,15 @@ module ActiveRecord
|
||||||
# We check defined?(@attributes) not to issue warnings if the object is
|
# We check defined?(@attributes) not to issue warnings if the object is
|
||||||
# allocated but not initialized.
|
# allocated but not initialized.
|
||||||
inspection = if defined?(@attributes) && @attributes
|
inspection = if defined?(@attributes) && @attributes
|
||||||
self.class.column_names.collect { |name|
|
self.class.column_names.collect do |name|
|
||||||
if has_attribute?(name)
|
if has_attribute?(name)
|
||||||
"#{name}: #{attribute_for_inspect(name)}"
|
"#{name}: #{attribute_for_inspect(name)}"
|
||||||
end
|
end
|
||||||
}.compact.join(", ")
|
end.compact.join(", ")
|
||||||
else
|
else
|
||||||
"not initialized"
|
"not initialized"
|
||||||
end
|
end
|
||||||
|
|
||||||
"#<#{self.class} #{inspection}>"
|
"#<#{self.class} #{inspection}>"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -205,16 +205,16 @@ db_namespace = namespace :db do
|
||||||
|
|
||||||
fixtures_dir = if ENV["FIXTURES_DIR"]
|
fixtures_dir = if ENV["FIXTURES_DIR"]
|
||||||
File.join base_dir, ENV["FIXTURES_DIR"]
|
File.join base_dir, ENV["FIXTURES_DIR"]
|
||||||
else
|
else
|
||||||
base_dir
|
base_dir
|
||||||
end
|
end
|
||||||
|
|
||||||
fixture_files = if ENV["FIXTURES"]
|
fixture_files = if ENV["FIXTURES"]
|
||||||
ENV["FIXTURES"].split(",")
|
ENV["FIXTURES"].split(",")
|
||||||
else
|
else
|
||||||
# The use of String#[] here is to support namespaced fixtures
|
# The use of String#[] here is to support namespaced fixtures.
|
||||||
Dir["#{fixtures_dir}/**/*.yml"].map {|f| f[(fixtures_dir.size + 1)..-5] }
|
Dir["#{fixtures_dir}/**/*.yml"].map {|f| f[(fixtures_dir.size + 1)..-5] }
|
||||||
end
|
end
|
||||||
|
|
||||||
ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, fixture_files)
|
ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, fixture_files)
|
||||||
end
|
end
|
||||||
|
|
|
@ -544,12 +544,12 @@ module ActiveRecord
|
||||||
|
|
||||||
def find_nth_with_limit(index, limit)
|
def find_nth_with_limit(index, limit)
|
||||||
# TODO: once the offset argument is removed from find_nth,
|
# TODO: once the offset argument is removed from find_nth,
|
||||||
# find_nth_with_limit_and_offset can be merged into this method
|
# find_nth_with_limit_and_offset can be merged into this method.
|
||||||
relation = if order_values.empty? && primary_key
|
relation = if order_values.empty? && primary_key
|
||||||
order(arel_attribute(primary_key).asc)
|
order(arel_attribute(primary_key).asc)
|
||||||
else
|
else
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
relation = relation.offset(index) unless index.zero?
|
relation = relation.offset(index) unless index.zero?
|
||||||
relation.limit(limit).to_a
|
relation.limit(limit).to_a
|
||||||
|
@ -561,9 +561,9 @@ module ActiveRecord
|
||||||
else
|
else
|
||||||
relation = if order_values.empty? && primary_key
|
relation = if order_values.empty? && primary_key
|
||||||
order(arel_attribute(primary_key).asc)
|
order(arel_attribute(primary_key).asc)
|
||||||
else
|
else
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
relation.to_a[-index]
|
relation.to_a[-index]
|
||||||
# TODO: can be made more performant on large result sets by
|
# TODO: can be made more performant on large result sets by
|
||||||
|
|
|
@ -78,9 +78,9 @@ module ActiveRecord
|
||||||
def fixtures_path
|
def fixtures_path
|
||||||
@fixtures_path ||= if ENV["FIXTURES_PATH"]
|
@fixtures_path ||= if ENV["FIXTURES_PATH"]
|
||||||
File.join(root, ENV["FIXTURES_PATH"])
|
File.join(root, ENV["FIXTURES_PATH"])
|
||||||
else
|
else
|
||||||
File.join(root, "test", "fixtures")
|
File.join(root, "test", "fixtures")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def root
|
def root
|
||||||
|
|
|
@ -6,9 +6,9 @@ class TestColumnAlias < ActiveRecord::TestCase
|
||||||
|
|
||||||
QUERY = if "Oracle" == ActiveRecord::Base.connection.adapter_name
|
QUERY = if "Oracle" == ActiveRecord::Base.connection.adapter_name
|
||||||
"SELECT id AS pk FROM topics WHERE ROWNUM < 2"
|
"SELECT id AS pk FROM topics WHERE ROWNUM < 2"
|
||||||
else
|
else
|
||||||
"SELECT id AS pk FROM topics"
|
"SELECT id AS pk FROM topics"
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_column_alias
|
def test_column_alias
|
||||||
records = Topic.connection.select_all(QUERY)
|
records = Topic.connection.select_all(QUERY)
|
||||||
|
|
|
@ -75,9 +75,10 @@ module ActiveRecord
|
||||||
def test_rename_nonexistent_column
|
def test_rename_nonexistent_column
|
||||||
exception = if current_adapter?(:PostgreSQLAdapter, :OracleAdapter)
|
exception = if current_adapter?(:PostgreSQLAdapter, :OracleAdapter)
|
||||||
ActiveRecord::StatementInvalid
|
ActiveRecord::StatementInvalid
|
||||||
else
|
else
|
||||||
ActiveRecord::ActiveRecordError
|
ActiveRecord::ActiveRecordError
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_raise(exception) do
|
assert_raise(exception) do
|
||||||
rename_column "test_models", "nonexistent", "should_fail"
|
rename_column "test_models", "nonexistent", "should_fail"
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,9 +6,10 @@ else
|
||||||
customrc = ARGV.index{ |x| x.include?("--rc=") }
|
customrc = ARGV.index{ |x| x.include?("--rc=") }
|
||||||
railsrc = if customrc
|
railsrc = if customrc
|
||||||
File.expand_path(ARGV.delete_at(customrc).gsub(/--rc=/, ""))
|
File.expand_path(ARGV.delete_at(customrc).gsub(/--rc=/, ""))
|
||||||
else
|
else
|
||||||
File.join(File.expand_path("~"), ".railsrc")
|
File.join(File.expand_path("~"), ".railsrc")
|
||||||
end
|
end
|
||||||
|
|
||||||
if File.exist?(railsrc)
|
if File.exist?(railsrc)
|
||||||
extra_args_string = File.read(railsrc)
|
extra_args_string = File.read(railsrc)
|
||||||
extra_args = extra_args_string.split(/\n+/).flat_map(&:split)
|
extra_args = extra_args_string.split(/\n+/).flat_map(&:split)
|
||||||
|
|
|
@ -43,9 +43,9 @@ module Rails
|
||||||
table << %(<tr><td class="name">#{CGI.escapeHTML(name.to_s)}</td>)
|
table << %(<tr><td class="name">#{CGI.escapeHTML(name.to_s)}</td>)
|
||||||
formatted_value = if value.kind_of?(Array)
|
formatted_value = if value.kind_of?(Array)
|
||||||
"<ul>" + value.map { |v| "<li>#{CGI.escapeHTML(v.to_s)}</li>" }.join + "</ul>"
|
"<ul>" + value.map { |v| "<li>#{CGI.escapeHTML(v.to_s)}</li>" }.join + "</ul>"
|
||||||
else
|
else
|
||||||
CGI.escapeHTML(value.to_s)
|
CGI.escapeHTML(value.to_s)
|
||||||
end
|
end
|
||||||
table << %(<td class="value">#{formatted_value}</td></tr>)
|
table << %(<td class="value">#{formatted_value}</td></tr>)
|
||||||
end
|
end
|
||||||
table << "</table>"
|
table << "</table>"
|
||||||
|
|
|
@ -9,9 +9,9 @@ task :test do
|
||||||
$: << "test"
|
$: << "test"
|
||||||
pattern = if ENV.key?("TEST")
|
pattern = if ENV.key?("TEST")
|
||||||
ENV["TEST"]
|
ENV["TEST"]
|
||||||
else
|
else
|
||||||
"test"
|
"test"
|
||||||
end
|
end
|
||||||
Minitest.rake_run([pattern])
|
Minitest.rake_run([pattern])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue