Remove usage of strip_heredoc in the framework in favor of <<~

Some places we can't remove because Ruby still don't have a method
equivalent to strip_heredoc to be called in an already existent string.
上级 2c89d1dd
AllCops: AllCops:
TargetRubyVersion: 2.2 TargetRubyVersion: 2.3
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
# to ignore them, so only the ones explicitly set in this file are enabled. # to ignore them, so only the ones explicitly set in this file are enabled.
DisabledByDefault: true DisabledByDefault: true
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
require "rack/session/abstract/id" require "rack/session/abstract/id"
require "action_controller/metal/exceptions" require "action_controller/metal/exceptions"
require "active_support/security_utils" require "active_support/security_utils"
require "active_support/core_ext/string/strip"
module ActionController #:nodoc: module ActionController #:nodoc:
class InvalidAuthenticityToken < ActionControllerError #:nodoc: class InvalidAuthenticityToken < ActionControllerError #:nodoc:
...@@ -416,7 +415,7 @@ def protect_against_forgery? # :doc: ...@@ -416,7 +415,7 @@ def protect_against_forgery? # :doc:
allow_forgery_protection allow_forgery_protection
end end
NULL_ORIGIN_MESSAGE = <<-MSG.strip_heredoc NULL_ORIGIN_MESSAGE = <<~MSG
The browser returned a 'null' origin for a request with origin-based forgery protection turned on. This usually The browser returned a 'null' origin for a request with origin-based forgery protection turned on. This usually
means you have the 'no-referrer' Referrer-Policy header enabled, or that you the request came from a site that means you have the 'no-referrer' Referrer-Policy header enabled, or that you the request came from a site that
refused to give its origin. This makes it impossible for Rails to verify the source of the requests. Likely the refused to give its origin. This makes it impossible for Rails to verify the source of the requests. Likely the
......
# frozen_string_literal: true # frozen_string_literal: true
require "delegate" require "delegate"
require "active_support/core_ext/string/strip"
module ActionDispatch module ActionDispatch
module Routing module Routing
...@@ -150,10 +149,10 @@ def header(routes) ...@@ -150,10 +149,10 @@ def header(routes)
def no_routes(routes) def no_routes(routes)
@buffer << @buffer <<
if routes.none? if routes.none?
<<-MESSAGE.strip_heredoc <<~MESSAGE
You don't have any routes defined! You don't have any routes defined!
Please add some routes in config/routes.rb. Please add some routes in config/routes.rb.
MESSAGE MESSAGE
else else
"No routes were found for this controller" "No routes were found for this controller"
...@@ -203,7 +202,7 @@ def header(routes) ...@@ -203,7 +202,7 @@ def header(routes)
end end
def no_routes(*) def no_routes(*)
@buffer << <<-MESSAGE.strip_heredoc @buffer << <<~MESSAGE
<p>You don't have any routes defined!</p> <p>You don't have any routes defined!</p>
<ul> <ul>
<li>Please add some routes in <tt>config/routes.rb</tt>.</li> <li>Please add some routes in <tt>config/routes.rb</tt>.</li>
......
...@@ -611,7 +611,7 @@ def mount(app, options = nil) ...@@ -611,7 +611,7 @@ def mount(app, options = nil)
end end
raise ArgumentError, "A rack application must be specified" unless app.respond_to?(:call) raise ArgumentError, "A rack application must be specified" unless app.respond_to?(:call)
raise ArgumentError, <<-MSG.strip_heredoc unless path raise ArgumentError, <<~MSG unless path
Must be called with mount point Must be called with mount point
mount SomeRackApp, at: "some_route" mount SomeRackApp, at: "some_route"
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
require "abstract_unit" require "abstract_unit"
require "action_controller/metal/strong_parameters" require "action_controller/metal/strong_parameters"
require "active_support/core_ext/string/strip"
class ParametersSerializationTest < ActiveSupport::TestCase class ParametersSerializationTest < ActiveSupport::TestCase
setup do setup do
...@@ -31,7 +30,7 @@ class ParametersSerializationTest < ActiveSupport::TestCase ...@@ -31,7 +30,7 @@ class ParametersSerializationTest < ActiveSupport::TestCase
end end
test "yaml backwardscompatible with psych 2.0.8 format" do test "yaml backwardscompatible with psych 2.0.8 format" do
params = YAML.load <<-end_of_yaml.strip_heredoc params = YAML.load <<~end_of_yaml
--- !ruby/hash:ActionController::Parameters --- !ruby/hash:ActionController::Parameters
key: :value key: :value
end_of_yaml end_of_yaml
...@@ -41,7 +40,7 @@ class ParametersSerializationTest < ActiveSupport::TestCase ...@@ -41,7 +40,7 @@ class ParametersSerializationTest < ActiveSupport::TestCase
end end
test "yaml backwardscompatible with psych 2.0.9+ format" do test "yaml backwardscompatible with psych 2.0.9+ format" do
params = YAML.load(<<-end_of_yaml.strip_heredoc) params = YAML.load(<<~end_of_yaml)
--- !ruby/hash-with-ivars:ActionController::Parameters --- !ruby/hash-with-ivars:ActionController::Parameters
elements: elements:
key: :value key: :value
......
# frozen_string_literal: true # frozen_string_literal: true
require "cases/helper" require "cases/helper"
require "active_support/core_ext/string/strip"
require "yaml" require "yaml"
class ErrorsTest < ActiveModel::TestCase class ErrorsTest < ActiveModel::TestCase
...@@ -406,7 +405,7 @@ def test_no_key ...@@ -406,7 +405,7 @@ def test_no_key
end end
test "errors are backward compatible with the Rails 4.2 format" do test "errors are backward compatible with the Rails 4.2 format" do
yaml = <<-CODE.strip_heredoc yaml = <<~CODE
--- !ruby/object:ActiveModel::Errors --- !ruby/object:ActiveModel::Errors
base: &1 !ruby/object:ErrorsTest::Person base: &1 !ruby/object:ErrorsTest::Person
errors: !ruby/object:ActiveModel::Errors errors: !ruby/object:ActiveModel::Errors
......
...@@ -131,7 +131,7 @@ def primary_key=(value) ...@@ -131,7 +131,7 @@ def primary_key=(value)
def suppress_composite_primary_key(pk) def suppress_composite_primary_key(pk)
return pk unless pk.is_a?(Array) return pk unless pk.is_a?(Array)
warn <<-WARNING.strip_heredoc warn <<~WARNING
WARNING: Active Record does not support composite primary key. WARNING: Active Record does not support composite primary key.
#{table_name} has composite primary key. Composite primary key is ignored. #{table_name} has composite primary key. Composite primary key is ignored.
......
...@@ -7,7 +7,7 @@ module Serialization ...@@ -7,7 +7,7 @@ module Serialization
class ColumnNotSerializableError < StandardError class ColumnNotSerializableError < StandardError
def initialize(name, type) def initialize(name, type)
super <<-EOS.strip_heredoc super <<~EOS
Column `#{name}` of type #{type.class} does not support `serialize` feature. Column `#{name}` of type #{type.class} does not support `serialize` feature.
Usually it means that you are trying to use `serialize` Usually it means that you are trying to use `serialize`
on a column that already implements serialization natively. on a column that already implements serialization natively.
......
# frozen_string_literal: true # frozen_string_literal: true
require "active_support/core_ext/string/strip"
module ActiveRecord module ActiveRecord
module ConnectionAdapters module ConnectionAdapters
class AbstractAdapter class AbstractAdapter
...@@ -66,7 +64,7 @@ def visit_PrimaryKeyDefinition(o) ...@@ -66,7 +64,7 @@ def visit_PrimaryKeyDefinition(o)
end end
def visit_ForeignKeyDefinition(o) def visit_ForeignKeyDefinition(o)
sql = <<-SQL.strip_heredoc sql = <<~SQL
CONSTRAINT #{quote_column_name(o.name)} CONSTRAINT #{quote_column_name(o.name)}
FOREIGN KEY (#{quote_column_name(o.column)}) FOREIGN KEY (#{quote_column_name(o.column)})
REFERENCES #{quote_table_name(o.to_table)} (#{quote_column_name(o.primary_key)}) REFERENCES #{quote_table_name(o.to_table)} (#{quote_column_name(o.primary_key)})
...@@ -133,7 +131,7 @@ def action_sql(action, dependency) ...@@ -133,7 +131,7 @@ def action_sql(action, dependency)
when :cascade then "ON #{action} CASCADE" when :cascade then "ON #{action} CASCADE"
when :restrict then "ON #{action} RESTRICT" when :restrict then "ON #{action} RESTRICT"
else else
raise ArgumentError, <<-MSG.strip_heredoc raise ArgumentError, <<~MSG
'#{dependency}' is not supported for :on_update or :on_delete. '#{dependency}' is not supported for :on_update or :on_delete.
Supported values are: :nullify, :cascade, :restrict Supported values are: :nullify, :cascade, :restrict
MSG MSG
......
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
require "active_record/connection_adapters/mysql/schema_statements" require "active_record/connection_adapters/mysql/schema_statements"
require "active_record/connection_adapters/mysql/type_metadata" require "active_record/connection_adapters/mysql/type_metadata"
require "active_support/core_ext/string/strip"
module ActiveRecord module ActiveRecord
module ConnectionAdapters module ConnectionAdapters
class AbstractMysqlAdapter < AbstractAdapter class AbstractMysqlAdapter < AbstractAdapter
...@@ -284,7 +282,7 @@ def truncate(table_name, name = nil) ...@@ -284,7 +282,7 @@ def truncate(table_name, name = nil)
def table_comment(table_name) # :nodoc: def table_comment(table_name) # :nodoc:
scope = quoted_scope(table_name) scope = quoted_scope(table_name)
query_value(<<-SQL.strip_heredoc, "SCHEMA").presence query_value(<<~SQL, "SCHEMA").presence
SELECT table_comment SELECT table_comment
FROM information_schema.tables FROM information_schema.tables
WHERE table_schema = #{scope[:schema]} WHERE table_schema = #{scope[:schema]}
...@@ -392,7 +390,7 @@ def foreign_keys(table_name) ...@@ -392,7 +390,7 @@ def foreign_keys(table_name)
scope = quoted_scope(table_name) scope = quoted_scope(table_name)
fk_info = exec_query(<<-SQL.strip_heredoc, "SCHEMA") fk_info = exec_query(<<~SQL, "SCHEMA")
SELECT fk.referenced_table_name AS 'to_table', SELECT fk.referenced_table_name AS 'to_table',
fk.referenced_column_name AS 'primary_key', fk.referenced_column_name AS 'primary_key',
fk.column_name AS 'column', fk.column_name AS 'column',
...@@ -480,7 +478,7 @@ def primary_keys(table_name) # :nodoc: ...@@ -480,7 +478,7 @@ def primary_keys(table_name) # :nodoc:
scope = quoted_scope(table_name) scope = quoted_scope(table_name)
query_values(<<-SQL.strip_heredoc, "SCHEMA") query_values(<<~SQL, "SCHEMA")
SELECT column_name SELECT column_name
FROM information_schema.key_column_usage FROM information_schema.key_column_usage
WHERE constraint_name = 'PRIMARY' WHERE constraint_name = 'PRIMARY'
......
...@@ -115,7 +115,7 @@ def indexes(table_name) # :nodoc: ...@@ -115,7 +115,7 @@ def indexes(table_name) # :nodoc:
if indkey.include?(0) if indkey.include?(0)
columns = expressions columns = expressions
else else
columns = Hash[query(<<-SQL.strip_heredoc, "SCHEMA")].values_at(*indkey).compact columns = Hash[query(<<~SQL, "SCHEMA")].values_at(*indkey).compact
SELECT a.attnum, a.attname SELECT a.attnum, a.attname
FROM pg_attribute a FROM pg_attribute a
WHERE a.attrelid = #{oid} WHERE a.attrelid = #{oid}
...@@ -158,7 +158,7 @@ def table_options(table_name) # :nodoc: ...@@ -158,7 +158,7 @@ def table_options(table_name) # :nodoc:
def table_comment(table_name) # :nodoc: def table_comment(table_name) # :nodoc:
scope = quoted_scope(table_name, type: "BASE TABLE") scope = quoted_scope(table_name, type: "BASE TABLE")
if scope[:name] if scope[:name]
query_value(<<-SQL.strip_heredoc, "SCHEMA") query_value(<<~SQL, "SCHEMA")
SELECT pg_catalog.obj_description(c.oid, 'pg_class') SELECT pg_catalog.obj_description(c.oid, 'pg_class')
FROM pg_catalog.pg_class c FROM pg_catalog.pg_class c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
...@@ -353,7 +353,7 @@ def pk_and_sequence_for(table) #:nodoc: ...@@ -353,7 +353,7 @@ def pk_and_sequence_for(table) #:nodoc:
end end
def primary_keys(table_name) # :nodoc: def primary_keys(table_name) # :nodoc:
query_values(<<-SQL.strip_heredoc, "SCHEMA") query_values(<<~SQL, "SCHEMA")
SELECT a.attname SELECT a.attname
FROM ( FROM (
SELECT indrelid, indkey, generate_subscripts(indkey, 1) idx SELECT indrelid, indkey, generate_subscripts(indkey, 1) idx
...@@ -502,7 +502,7 @@ def rename_index(table_name, old_name, new_name) ...@@ -502,7 +502,7 @@ def rename_index(table_name, old_name, new_name)
def foreign_keys(table_name) def foreign_keys(table_name)
scope = quoted_scope(table_name) scope = quoted_scope(table_name)
fk_info = exec_query(<<-SQL.strip_heredoc, "SCHEMA") fk_info = exec_query(<<~SQL, "SCHEMA")
SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete, c.convalidated AS valid SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete, c.convalidated AS valid
FROM pg_constraint c FROM pg_constraint c
JOIN pg_class t1 ON c.conrelid = t1.oid JOIN pg_class t1 ON c.conrelid = t1.oid
......
...@@ -120,13 +120,13 @@ class MismatchedForeignKey < StatementInvalid ...@@ -120,13 +120,13 @@ class MismatchedForeignKey < StatementInvalid
def initialize(adapter = nil, message: nil, table: nil, foreign_key: nil, target_table: nil, primary_key: nil) def initialize(adapter = nil, message: nil, table: nil, foreign_key: nil, target_table: nil, primary_key: nil)
@adapter = adapter @adapter = adapter
if table if table
msg = <<-EOM.strip_heredoc msg = <<~EOM
Column `#{foreign_key}` on table `#{table}` has a type of `#{column_type(table, foreign_key)}`. Column `#{foreign_key}` on table `#{table}` has a type of `#{column_type(table, foreign_key)}`.
This does not match column `#{primary_key}` on `#{target_table}`, which has type `#{column_type(target_table, primary_key)}`. This does not match column `#{primary_key}` on `#{target_table}`, which has type `#{column_type(target_table, primary_key)}`.
To resolve this issue, change the type of the `#{foreign_key}` column on `#{table}` to be :integer. (For example `t.integer #{foreign_key}`). To resolve this issue, change the type of the `#{foreign_key}` column on `#{table}` to be :integer. (For example `t.integer #{foreign_key}`).
EOM EOM
else else
msg = <<-EOM msg = <<~EOM
There is a mismatch between the foreign key and primary key column types. There is a mismatch between the foreign key and primary key column types.
Verify that the foreign key column type and the primary key of the associated table match types. Verify that the foreign key column type and the primary key of the associated table match types.
EOM EOM
......
...@@ -85,7 +85,7 @@ def record(*command, &block) ...@@ -85,7 +85,7 @@ def record(*command, &block)
# invert the +command+. # invert the +command+.
def inverse_of(command, args, &block) def inverse_of(command, args, &block)
method = :"invert_#{command}" method = :"invert_#{command}"
raise IrreversibleMigration, <<-MSG.strip_heredoc unless respond_to?(method, true) raise IrreversibleMigration, <<~MSG unless respond_to?(method, true)
This migration uses #{command}, which is not automatically reversible. This migration uses #{command}, which is not automatically reversible.
To make the migration reversible you can either: To make the migration reversible you can either:
1. Define #up and #down methods in place of the #change method. 1. Define #up and #down methods in place of the #change method.
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
require "models/person" require "models/person"
require "models/topic" require "models/topic"
require "pp" require "pp"
require "active_support/core_ext/string/strip"
class NonExistentTable < ActiveRecord::Base; end class NonExistentTable < ActiveRecord::Base; end
...@@ -39,26 +38,26 @@ def test_pretty_print_new ...@@ -39,26 +38,26 @@ def test_pretty_print_new
topic = Topic.new topic = Topic.new
actual = "".dup actual = "".dup
PP.pp(topic, StringIO.new(actual)) PP.pp(topic, StringIO.new(actual))
expected = <<-PRETTY.strip_heredoc expected = <<~PRETTY
#<Topic:0xXXXXXX #<Topic:0xXXXXXX
id: nil, id: nil,
title: nil, title: nil,
author_name: nil, author_name: nil,
author_email_address: "test@test.com", author_email_address: "test@test.com",
written_on: nil, written_on: nil,
bonus_time: nil, bonus_time: nil,
last_read: nil, last_read: nil,
content: nil, content: nil,
important: nil, important: nil,
approved: true, approved: true,
replies_count: 0, replies_count: 0,
unique_replies_count: 0, unique_replies_count: 0,
parent_id: nil, parent_id: nil,
parent_title: nil, parent_title: nil,
type: nil, type: nil,
group: nil, group: nil,
created_at: nil, created_at: nil,
updated_at: nil> updated_at: nil>
PRETTY PRETTY
assert actual.start_with?(expected.split("XXXXXX").first) assert actual.start_with?(expected.split("XXXXXX").first)
assert actual.end_with?(expected.split("XXXXXX").last) assert actual.end_with?(expected.split("XXXXXX").last)
...@@ -68,26 +67,26 @@ def test_pretty_print_persisted ...@@ -68,26 +67,26 @@ def test_pretty_print_persisted
topic = topics(:first) topic = topics(:first)
actual = "".dup actual = "".dup
PP.pp(topic, StringIO.new(actual)) PP.pp(topic, StringIO.new(actual))
expected = <<-PRETTY.strip_heredoc expected = <<~PRETTY
#<Topic:0x\\w+ #<Topic:0x\\w+
id: 1, id: 1,
title: "The First Topic", title: "The First Topic",
author_name: "David", author_name: "David",
author_email_address: "david@loudthinking.com", author_email_address: "david@loudthinking.com",
written_on: 2003-07-16 14:28:11 UTC, written_on: 2003-07-16 14:28:11 UTC,
bonus_time: 2000-01-01 14:28:00 UTC, bonus_time: 2000-01-01 14:28:00 UTC,
last_read: Thu, 15 Apr 2004, last_read: Thu, 15 Apr 2004,
content: "Have a nice day", content: "Have a nice day",
important: nil, important: nil,
approved: false, approved: false,
replies_count: 1, replies_count: 1,
unique_replies_count: 0, unique_replies_count: 0,
parent_id: nil, parent_id: nil,
parent_title: nil, parent_title: nil,
type: nil, type: nil,
group: nil, group: nil,
created_at: [^,]+, created_at: [^,]+,
updated_at: [^,>]+> updated_at: [^,>]+>
PRETTY PRETTY
assert_match(/\A#{expected}\z/, actual) assert_match(/\A#{expected}\z/, actual)
end end
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
require "cases/helper" require "cases/helper"
require "models/car" require "models/car"
require "active_support/core_ext/string/strip"
if ActiveRecord::Base.connection.supports_explain? if ActiveRecord::Base.connection.supports_explain?
class ExplainTest < ActiveRecord::TestCase class ExplainTest < ActiveRecord::TestCase
...@@ -53,7 +52,7 @@ def test_exec_explain_with_binds ...@@ -53,7 +52,7 @@ def test_exec_explain_with_binds
queries = sqls.zip(binds) queries = sqls.zip(binds)
stub_explain_for_query_plans(["query plan foo\n", "query plan bar\n"]) do stub_explain_for_query_plans(["query plan foo\n", "query plan bar\n"]) do
expected = <<-SQL.strip_heredoc expected = <<~SQL
EXPLAIN for: #{sqls[0]} [["wadus", 1]] EXPLAIN for: #{sqls[0]} [["wadus", 1]]
query plan foo query plan foo
......
...@@ -86,7 +86,7 @@ def test_bulk_insert_multiple_table_with_a_multi_statement_query ...@@ -86,7 +86,7 @@ def test_bulk_insert_multiple_table_with_a_multi_statement_query
create_fixtures("bulbs", "authors", "computers") create_fixtures("bulbs", "authors", "computers")
expected_sql = <<-EOS.strip_heredoc.chop expected_sql = <<~EOS
INSERT INTO #{ActiveRecord::Base.connection.quote_table_name("bulbs")} .* INSERT INTO #{ActiveRecord::Base.connection.quote_table_name("bulbs")} .*
INSERT INTO #{ActiveRecord::Base.connection.quote_table_name("authors")} .* INSERT INTO #{ActiveRecord::Base.connection.quote_table_name("authors")} .*
INSERT INTO #{ActiveRecord::Base.connection.quote_table_name("computers")} .* INSERT INTO #{ActiveRecord::Base.connection.quote_table_name("computers")} .*
......
...@@ -88,7 +88,7 @@ def test_renaming_table_renames_primary_key ...@@ -88,7 +88,7 @@ def test_renaming_table_renames_primary_key
assert connection.table_exists? :felines assert connection.table_exists? :felines
assert_not connection.table_exists? :cats assert_not connection.table_exists? :cats
primary_key_name = connection.select_values(<<-SQL.strip_heredoc, "SCHEMA")[0] primary_key_name = connection.select_values(<<~SQL, "SCHEMA")[0]
SELECT c.relname SELECT c.relname
FROM pg_class c FROM pg_class c
JOIN pg_index i JOIN pg_index i
......
# frozen_string_literal: true # frozen_string_literal: true
require "active_support/core_ext/module/redefine_method" require "active_support/core_ext/module/redefine_method"
require "active_support/core_ext/string/strip" # for strip_heredoc
require "active_support/core_ext/time/calculations" require "active_support/core_ext/time/calculations"
require "concurrent/map" require "concurrent/map"
...@@ -112,7 +111,7 @@ def travel(duration, &block) ...@@ -112,7 +111,7 @@ def travel(duration, &block)
# Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
def travel_to(date_or_time) def travel_to(date_or_time)
if block_given? && simple_stubs.stubbing(Time, :now) if block_given? && simple_stubs.stubbing(Time, :now)
travel_to_nested_block_call = <<-MSG.strip_heredoc travel_to_nested_block_call = <<~MSG
Calling `travel_to` with a block, when we have previously already made a call to `travel_to`, can lead to confusing time stubbing. Calling `travel_to` with a block, when we have previously already made a call to `travel_to`, can lead to confusing time stubbing.
......
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
require "active_support/inflector" require "active_support/inflector"
require "active_support/core_ext/string" require "active_support/core_ext/string"
require "active_support/time" require "active_support/time"
require "active_support/core_ext/string/strip"
require "active_support/core_ext/string/output_safety" require "active_support/core_ext/string/output_safety"
require "active_support/core_ext/string/indent" require "active_support/core_ext/string/indent"
require "active_support/core_ext/string/strip"
require "time_zone_test_helpers" require "time_zone_test_helpers"
require "yaml" require "yaml"
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
require "abstract_unit" require "abstract_unit"
require "active_support/time" require "active_support/time"
require "time_zone_test_helpers" require "time_zone_test_helpers"
require "active_support/core_ext/string/strip"
require "yaml" require "yaml"
class TimeWithZoneTest < ActiveSupport::TestCase class TimeWithZoneTest < ActiveSupport::TestCase
...@@ -163,7 +162,7 @@ def test_rfc3339_with_fractional_seconds ...@@ -163,7 +162,7 @@ def test_rfc3339_with_fractional_seconds
end end
def test_to_yaml def test_to_yaml
yaml = <<-EOF.strip_heredoc yaml = <<~EOF
--- !ruby/object:ActiveSupport::TimeWithZone --- !ruby/object:ActiveSupport::TimeWithZone
utc: 2000-01-01 00:00:00.000000000 Z utc: 2000-01-01 00:00:00.000000000 Z
zone: !ruby/object:ActiveSupport::TimeZone zone: !ruby/object:ActiveSupport::TimeZone
...@@ -175,7 +174,7 @@ def test_to_yaml ...@@ -175,7 +174,7 @@ def test_to_yaml
end end
def test_ruby_to_yaml def test_ruby_to_yaml
yaml = <<-EOF.strip_heredoc yaml = <<~EOF
--- ---
twz: !ruby/object:ActiveSupport::TimeWithZone twz: !ruby/object:ActiveSupport::TimeWithZone
utc: 2000-01-01 00:00:00.000000000 Z utc: 2000-01-01 00:00:00.000000000 Z
...@@ -188,7 +187,7 @@ def test_ruby_to_yaml ...@@ -188,7 +187,7 @@ def test_ruby_to_yaml
end end
def test_yaml_load def test_yaml_load
yaml = <<-EOF.strip_heredoc yaml = <<~EOF
--- !ruby/object:ActiveSupport::TimeWithZone --- !ruby/object:ActiveSupport::TimeWithZone
utc: 2000-01-01 00:00:00.000000000 Z utc: 2000-01-01 00:00:00.000000000 Z
zone: !ruby/object:ActiveSupport::TimeZone zone: !ruby/object:ActiveSupport::TimeZone
...@@ -200,7 +199,7 @@ def test_yaml_load ...@@ -200,7 +199,7 @@ def test_yaml_load
end end
def test_ruby_yaml_load def test_ruby_yaml_load
yaml = <<-EOF.strip_heredoc yaml = <<~EOF
--- ---
twz: !ruby/object:ActiveSupport::TimeWithZone twz: !ruby/object:ActiveSupport::TimeWithZone
utc: 2000-01-01 00:00:00.000000000 Z utc: 2000-01-01 00:00:00.000000000 Z
......
# frozen_string_literal: true # frozen_string_literal: true
require "active_support/core_ext/string/strip"
module Rails module Rails
module Generators module Generators
module Actions module Actions
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
require "fileutils" require "fileutils"
require "digest/md5" require "digest/md5"
require "active_support/core_ext/string/strip"
require "rails/version" unless defined?(Rails::VERSION) require "rails/version" unless defined?(Rails::VERSION)
require "open-uri" require "open-uri"
require "uri" require "uri"
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
require "rails/generators/base" require "rails/generators/base"
require "rails/generators/rails/master_key/master_key_generator" require "rails/generators/rails/master_key/master_key_generator"
require "active_support/core_ext/string/strip"
require "active_support/encrypted_configuration" require "active_support/encrypted_configuration"
module Rails module Rails
...@@ -43,13 +42,13 @@ def credentials ...@@ -43,13 +42,13 @@ def credentials
end end
def credentials_template def credentials_template
<<-YAML.strip_heredoc <<~YAML
# aws: # aws:
# access_key_id: 123 # access_key_id: 123
# secret_access_key: 345 # secret_access_key: 345
# Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies. # Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
secret_key_base: #{SecureRandom.hex(64)} secret_key_base: #{SecureRandom.hex(64)}
YAML YAML
end end
end end
......
...@@ -16,10 +16,10 @@ def add_encrypted_file_silently(file_path, key_path, template = encrypted_file_t ...@@ -16,10 +16,10 @@ def add_encrypted_file_silently(file_path, key_path, template = encrypted_file_t
private private
def encrypted_file_template def encrypted_file_template
<<-YAML.strip_heredoc <<~YAML
# aws: # aws:
# access_key_id: 123 # access_key_id: 123
# secret_access_key: 345 # secret_access_key: 345
YAML YAML
end end
......
<%= wrap_in_modules <<-rb.strip_heredoc <%= wrap_in_modules <<~rb
class ApplicationController < ActionController::#{api? ? "API" : "Base"} class ApplicationController < ActionController::#{api? ? "API" : "Base"}
#{ api? ? '# ' : '' }protect_from_forgery with: :exception #{ api? ? '# ' : '' }protect_from_forgery with: :exception
end end
......
<%= wrap_in_modules <<-rb.strip_heredoc <%= wrap_in_modules <<~rb
module ApplicationHelper module ApplicationHelper
end end
rb rb
......
<%= wrap_in_modules <<-rb.strip_heredoc <%= wrap_in_modules <<~rb
class ApplicationJob < ActiveJob::Base class ApplicationJob < ActiveJob::Base
end end
rb rb
......
<%= wrap_in_modules <<-rb.strip_heredoc <%= wrap_in_modules <<~rb
class ApplicationMailer < ActionMailer::Base class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com' default from: 'from@example.com'
layout 'mailer' layout 'mailer'
......
<%= wrap_in_modules <<-rb.strip_heredoc <%= wrap_in_modules <<~rb
class ApplicationRecord < ActiveRecord::Base class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true self.abstract_class = true
end end
......
<%= wrap_in_modules <<-rb.strip_heredoc <%= wrap_in_modules <<~rb
class Engine < ::Rails::Engine class Engine < ::Rails::Engine
#{mountable? ? ' isolate_namespace ' + camelized_modules : ' '} #{mountable? ? ' isolate_namespace ' + camelized_modules : ' '}
#{api? ? " config.generators.api_only = true" : ' '} #{api? ? " config.generators.api_only = true" : ' '}
......
<%= wrap_in_modules <<-rb.strip_heredoc <%= wrap_in_modules <<~rb
class Railtie < ::Rails::Railtie class Railtie < ::Rails::Railtie
end end
rb rb
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
require "yaml" require "yaml"
require "active_support/message_encryptor" require "active_support/message_encryptor"
require "active_support/core_ext/string/strip"
module Rails module Rails
# Greatly inspired by Ara T. Howard's magnificent sekrets gem. 😘 # Greatly inspired by Ara T. Howard's magnificent sekrets gem. 😘
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
require "isolation/abstract_unit" require "isolation/abstract_unit"
require "env_helpers" require "env_helpers"
require "active_support/core_ext/string/strip"
module ApplicationTests module ApplicationTests
class RakeTest < ActiveSupport::TestCase class RakeTest < ActiveSupport::TestCase
...@@ -131,7 +130,7 @@ def test_rails_routes_calls_the_route_inspector ...@@ -131,7 +130,7 @@ def test_rails_routes_calls_the_route_inspector
RUBY RUBY
output = rails("routes") output = rails("routes")
assert_equal <<-MESSAGE.strip_heredoc, output assert_equal <<~MESSAGE, output
Prefix Verb URI Pattern Controller#Action Prefix Verb URI Pattern Controller#Action
cart GET /cart(.:format) cart#show cart GET /cart(.:format) cart#show
rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show
...@@ -173,7 +172,7 @@ def test_rails_routes_with_global_search_key ...@@ -173,7 +172,7 @@ def test_rails_routes_with_global_search_key
RUBY RUBY
output = rails("routes", "-g", "show") output = rails("routes", "-g", "show")
assert_equal <<-MESSAGE.strip_heredoc, output assert_equal <<~MESSAGE, output
Prefix Verb URI Pattern Controller#Action Prefix Verb URI Pattern Controller#Action
cart GET /cart(.:format) cart#show cart GET /cart(.:format) cart#show
rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show
...@@ -183,7 +182,7 @@ def test_rails_routes_with_global_search_key ...@@ -183,7 +182,7 @@ def test_rails_routes_with_global_search_key
MESSAGE MESSAGE
output = rails("routes", "-g", "POST") output = rails("routes", "-g", "POST")
assert_equal <<-MESSAGE.strip_heredoc, output assert_equal <<~MESSAGE, output
Prefix Verb URI Pattern Controller#Action Prefix Verb URI Pattern Controller#Action
POST /cart(.:format) cart#create POST /cart(.:format) cart#create
rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
...@@ -242,7 +241,7 @@ def test_rails_routes_displays_message_when_no_routes_are_defined ...@@ -242,7 +241,7 @@ def test_rails_routes_displays_message_when_no_routes_are_defined
end end
RUBY RUBY
assert_equal <<-MESSAGE.strip_heredoc, rails("routes") assert_equal <<~MESSAGE, rails("routes")
Prefix Verb URI Pattern Controller#Action Prefix Verb URI Pattern Controller#Action
rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show
rails_blob_variation GET /rails/active_storage/variants/:signed_blob_id/:variation_key/*filename(.:format) active_storage/variants#show rails_blob_variation GET /rails/active_storage/variants/:signed_blob_id/:variation_key/*filename(.:format) active_storage/variants#show
...@@ -262,7 +261,7 @@ def test_rake_routes_with_rake_options ...@@ -262,7 +261,7 @@ def test_rake_routes_with_rake_options
output = Dir.chdir(app_path) { `bin/rake --rakefile Rakefile routes` } output = Dir.chdir(app_path) { `bin/rake --rakefile Rakefile routes` }
assert_equal <<-MESSAGE.strip_heredoc, output assert_equal <<~MESSAGE, output
Prefix Verb URI Pattern Controller#Action Prefix Verb URI Pattern Controller#Action
cart GET /cart(.:format) cart#show cart GET /cart(.:format) cart#show
rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show
......
# frozen_string_literal: true # frozen_string_literal: true
require "isolation/abstract_unit" require "isolation/abstract_unit"
require "active_support/core_ext/string/strip"
require "env_helpers" require "env_helpers"
module ApplicationTests module ApplicationTests
...@@ -741,7 +740,7 @@ def run_test_command(arguments = "test/unit/test_test.rb", **opts) ...@@ -741,7 +740,7 @@ def run_test_command(arguments = "test/unit/test_test.rb", **opts)
def create_model_with_fixture def create_model_with_fixture
rails "generate", "model", "user", "name:string" rails "generate", "model", "user", "name:string"
app_file "test/fixtures/users.yml", <<-YAML.strip_heredoc app_file "test/fixtures/users.yml", <<~YAML
vampire: vampire:
id: 1 id: 1
name: Koyomi Araragi name: Koyomi Araragi
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
require "generators/generators_test_helper" require "generators/generators_test_helper"
require "rails/generators/rails/model/model_generator" require "rails/generators/rails/model/model_generator"
require "active_support/core_ext/string/strip"
class ModelGeneratorTest < Rails::Generators::TestCase class ModelGeneratorTest < Rails::Generators::TestCase
include GeneratorsTestHelper include GeneratorsTestHelper
...@@ -379,10 +378,10 @@ def test_add_uuid_to_create_table_migration ...@@ -379,10 +378,10 @@ def test_add_uuid_to_create_table_migration
def test_required_belongs_to_adds_required_association def test_required_belongs_to_adds_required_association
run_generator ["account", "supplier:references{required}"] run_generator ["account", "supplier:references{required}"]
expected_file = <<-FILE.strip_heredoc expected_file = <<~FILE
class Account < ApplicationRecord class Account < ApplicationRecord
belongs_to :supplier, required: true belongs_to :supplier, required: true
end end
FILE FILE
assert_file "app/models/account.rb", expected_file assert_file "app/models/account.rb", expected_file
end end
...@@ -390,10 +389,10 @@ class Account < ApplicationRecord ...@@ -390,10 +389,10 @@ class Account < ApplicationRecord
def test_required_polymorphic_belongs_to_generages_correct_model def test_required_polymorphic_belongs_to_generages_correct_model
run_generator ["account", "supplier:references{required,polymorphic}"] run_generator ["account", "supplier:references{required,polymorphic}"]
expected_file = <<-FILE.strip_heredoc expected_file = <<~FILE
class Account < ApplicationRecord class Account < ApplicationRecord
belongs_to :supplier, polymorphic: true, required: true belongs_to :supplier, polymorphic: true, required: true
end end
FILE FILE
assert_file "app/models/account.rb", expected_file assert_file "app/models/account.rb", expected_file
end end
...@@ -401,10 +400,10 @@ class Account < ApplicationRecord ...@@ -401,10 +400,10 @@ class Account < ApplicationRecord
def test_required_and_polymorphic_are_order_independent def test_required_and_polymorphic_are_order_independent
run_generator ["account", "supplier:references{polymorphic.required}"] run_generator ["account", "supplier:references{polymorphic.required}"]
expected_file = <<-FILE.strip_heredoc expected_file = <<~FILE
class Account < ApplicationRecord class Account < ApplicationRecord
belongs_to :supplier, polymorphic: true, required: true belongs_to :supplier, polymorphic: true, required: true
end end
FILE FILE
assert_file "app/models/account.rb", expected_file assert_file "app/models/account.rb", expected_file
end end
...@@ -452,11 +451,11 @@ def test_foreign_key_is_skipped_for_polymorphic_references ...@@ -452,11 +451,11 @@ def test_foreign_key_is_skipped_for_polymorphic_references
def test_token_option_adds_has_secure_token def test_token_option_adds_has_secure_token
run_generator ["user", "token:token", "auth_token:token"] run_generator ["user", "token:token", "auth_token:token"]
expected_file = <<-FILE.strip_heredoc expected_file = <<~FILE
class User < ApplicationRecord class User < ApplicationRecord
has_secure_token has_secure_token
has_secure_token :auth_token has_secure_token :auth_token
end end
FILE FILE
assert_file "app/models/user.rb", expected_file assert_file "app/models/user.rb", expected_file
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册