Enable Performance/UnfreezeString
cop
In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`. ```ruby # frozen_string_literal: true require "bundler/inline" gemfile(true) do source "https://rubygems.org" gem "benchmark-ips" end Benchmark.ips do |x| x.report('+@') { +"" } x.report('dup') { "".dup } x.compare! end ``` ``` $ ruby -v benchmark.rb ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] Warming up -------------------------------------- +@ 282.289k i/100ms dup 187.638k i/100ms Calculating ------------------------------------- +@ 6.775M (± 3.6%) i/s - 33.875M in 5.006253s dup 3.320M (± 2.2%) i/s - 16.700M in 5.032125s Comparison: +@: 6775299.3 i/s dup: 3320400.7 i/s - 2.04x slower ```
This commit is contained in:
parent
d3b952184d
commit
1b86d90136
@ -208,3 +208,6 @@ Performance/EndWith:
|
||||
|
||||
Performance/RegexpMatch:
|
||||
Enabled: true
|
||||
|
||||
Performance/UnfreezeString:
|
||||
Enabled: true
|
||||
|
@ -270,7 +270,7 @@ def dispatch_action(action, data)
|
||||
end
|
||||
|
||||
def action_signature(action, data)
|
||||
"#{self.class.name}##{action}".dup.tap do |signature|
|
||||
(+"#{self.class.name}##{action}").tap do |signature|
|
||||
if (arguments = data.except("action")).any?
|
||||
signature << "(#{arguments.inspect})"
|
||||
end
|
||||
|
@ -122,7 +122,7 @@ class BaseTest < ActiveSupport::TestCase
|
||||
email = BaseMailer.attachment_with_hash
|
||||
assert_equal(1, email.attachments.length)
|
||||
assert_equal("invoice.jpg", email.attachments[0].filename)
|
||||
expected = "\312\213\254\232)b".dup
|
||||
expected = +"\312\213\254\232)b"
|
||||
expected.force_encoding(Encoding::BINARY)
|
||||
assert_equal expected, email.attachments["invoice.jpg"].decoded
|
||||
end
|
||||
@ -131,7 +131,7 @@ class BaseTest < ActiveSupport::TestCase
|
||||
email = BaseMailer.attachment_with_hash_default_encoding
|
||||
assert_equal(1, email.attachments.length)
|
||||
assert_equal("invoice.jpg", email.attachments[0].filename)
|
||||
expected = "\312\213\254\232)b".dup
|
||||
expected = +"\312\213\254\232)b"
|
||||
expected.force_encoding(Encoding::BINARY)
|
||||
assert_equal expected, email.attachments["invoice.jpg"].decoded
|
||||
end
|
||||
|
@ -26,7 +26,7 @@ def process_action(event)
|
||||
exception_class_name = payload[:exception].first
|
||||
status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
|
||||
end
|
||||
message = "Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in #{event.duration.round}ms".dup
|
||||
message = +"Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in #{event.duration.round}ms"
|
||||
message << " (#{additions.join(" | ".freeze)})" unless additions.empty?
|
||||
message << "\n\n" if defined?(Rails.env) && Rails.env.development?
|
||||
|
||||
|
@ -474,7 +474,7 @@ def params_array_from(raw_params)
|
||||
|
||||
# This removes the <tt>"</tt> characters wrapping the value.
|
||||
def rewrite_param_values(array_params)
|
||||
array_params.each { |param| (param[1] || "".dup).gsub! %r/^"|"$/, "" }
|
||||
array_params.each { |param| (param[1] || +"").gsub! %r/^"|"$/, "" }
|
||||
end
|
||||
|
||||
# This method takes an authorization body and splits up the key-value
|
||||
|
@ -297,7 +297,7 @@ def log_error(exception)
|
||||
return unless logger
|
||||
|
||||
logger.fatal do
|
||||
message = "\n#{exception.class} (#{exception.message}):\n".dup
|
||||
message = +"\n#{exception.class} (#{exception.message}):\n"
|
||||
message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code)
|
||||
message << " " << exception.backtrace.join("\n ")
|
||||
"#{message}\n\n"
|
||||
|
@ -40,7 +40,7 @@ def render(*args) #:nodoc:
|
||||
def render_to_string(*)
|
||||
result = super
|
||||
if result.respond_to?(:each)
|
||||
string = "".dup
|
||||
string = +""
|
||||
result.each { |r| string << r }
|
||||
string
|
||||
else
|
||||
|
@ -105,7 +105,7 @@ def initialize(response, buf)
|
||||
|
||||
def body
|
||||
@str_body ||= begin
|
||||
buf = "".dup
|
||||
buf = +""
|
||||
each { |chunk| buf << chunk }
|
||||
buf
|
||||
end
|
||||
|
@ -157,7 +157,7 @@ def normalize_host(_host, options)
|
||||
subdomain = options.fetch :subdomain, true
|
||||
domain = options[:domain]
|
||||
|
||||
host = "".dup
|
||||
host = +""
|
||||
if subdomain == true
|
||||
return _host if domain.nil?
|
||||
|
||||
|
@ -50,7 +50,7 @@ def generate(name, options, path_parameters, parameterize = nil)
|
||||
unmatched_keys = (missing_keys || []) & constraints.keys
|
||||
missing_keys = (missing_keys || []) - unmatched_keys
|
||||
|
||||
message = "No route matches #{Hash[constraints.sort_by { |k, v| k.to_s }].inspect}".dup
|
||||
message = +"No route matches #{Hash[constraints.sort_by { |k, v| k.to_s }].inspect}"
|
||||
message << ", missing required keys: #{missing_keys.sort.inspect}" if missing_keys && !missing_keys.empty?
|
||||
message << ", possible unmatched constraints: #{unmatched_keys.sort.inspect}" if unmatched_keys && !unmatched_keys.empty?
|
||||
|
||||
|
@ -17,11 +17,11 @@ class Utils # :nodoc:
|
||||
def self.normalize_path(path)
|
||||
path ||= ""
|
||||
encoding = path.encoding
|
||||
path = "/#{path}".dup
|
||||
path = +"/#{path}"
|
||||
path.squeeze!("/".freeze)
|
||||
path.sub!(%r{/+\Z}, "".freeze)
|
||||
path.gsub!(/(%[a-f0-9]{2})/) { $1.upcase }
|
||||
path = "/".dup if path == "".freeze
|
||||
path = +"/" if path == "".freeze
|
||||
path.force_encoding(encoding)
|
||||
path
|
||||
end
|
||||
@ -32,7 +32,7 @@ class UriEncoder # :nodoc:
|
||||
ENCODE = "%%%02X".freeze
|
||||
US_ASCII = Encoding::US_ASCII
|
||||
UTF_8 = Encoding::UTF_8
|
||||
EMPTY = "".dup.force_encoding(US_ASCII).freeze
|
||||
EMPTY = (+"").force_encoding(US_ASCII).freeze
|
||||
DEC2HEX = (0..255).to_a.map { |i| ENCODE % i }.map { |s| s.force_encoding(US_ASCII) }
|
||||
|
||||
ALPHA = "a-zA-Z".freeze
|
||||
|
@ -23,7 +23,7 @@ def debug_params(params)
|
||||
if clean_params.empty?
|
||||
"None"
|
||||
else
|
||||
PP.pp(clean_params, "".dup, 200)
|
||||
PP.pp(clean_params, +"", 200)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -63,19 +63,19 @@ def render_details(req)
|
||||
|
||||
str = threads.map do |thread, info|
|
||||
if info[:exclusive]
|
||||
lock_state = "Exclusive".dup
|
||||
lock_state = +"Exclusive"
|
||||
elsif info[:sharing] > 0
|
||||
lock_state = "Sharing".dup
|
||||
lock_state = +"Sharing"
|
||||
lock_state << " x#{info[:sharing]}" if info[:sharing] > 1
|
||||
else
|
||||
lock_state = "No lock".dup
|
||||
lock_state = +"No lock"
|
||||
end
|
||||
|
||||
if info[:waiting]
|
||||
lock_state << " (yielded share)"
|
||||
end
|
||||
|
||||
msg = "Thread #{info[:index]} [0x#{thread.__id__.to_s(16)} #{thread.status || 'dead'}] #{lock_state}\n".dup
|
||||
msg = +"Thread #{info[:index]} [0x#{thread.__id__.to_s(16)} #{thread.status || 'dead'}] #{lock_state}\n"
|
||||
|
||||
if info[:sleeper]
|
||||
msg << " Waiting in #{info[:sleeper]}"
|
||||
|
@ -102,7 +102,7 @@ def normalize_hsts_options(options)
|
||||
|
||||
# https://tools.ietf.org/html/rfc6797#section-6.1
|
||||
def build_hsts_header(hsts)
|
||||
value = "max-age=#{hsts[:expires].to_i}".dup
|
||||
value = +"max-age=#{hsts[:expires].to_i}"
|
||||
value << "; includeSubDomains" if hsts[:subdomains]
|
||||
value << "; preload" if hsts[:preload]
|
||||
value
|
||||
@ -141,7 +141,7 @@ def https_location_for(request)
|
||||
host = @redirect[:host] || request.host
|
||||
port = @redirect[:port] || request.port
|
||||
|
||||
location = "https://#{host}".dup
|
||||
location = +"https://#{host}"
|
||||
location << ":#{port}" if port != 80 && port != 443
|
||||
location << request.fullpath
|
||||
location
|
||||
|
@ -308,7 +308,7 @@ def app(blocks)
|
||||
def check_controller_and_action(path_params, controller, action)
|
||||
hash = check_part(:controller, controller, path_params, {}) do |part|
|
||||
translate_controller(part) {
|
||||
message = "'#{part}' is not a supported controller name. This can lead to potential routing problems.".dup
|
||||
message = +"'#{part}' is not a supported controller name. This can lead to potential routing problems."
|
||||
message << " See https://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use"
|
||||
|
||||
raise ArgumentError, message
|
||||
|
@ -245,7 +245,7 @@ def raise_generation_error(args)
|
||||
missing_keys << missing_key
|
||||
}
|
||||
constraints = Hash[@route.requirements.merge(params).sort_by { |k, v| k.to_s }]
|
||||
message = "No route matches #{constraints.inspect}".dup
|
||||
message = +"No route matches #{constraints.inspect}"
|
||||
message << ", missing required keys: #{missing_keys.sort.inspect}"
|
||||
|
||||
raise ActionController::UrlGenerationError, message
|
||||
|
@ -65,7 +65,7 @@ def output_type
|
||||
end
|
||||
|
||||
def display_image
|
||||
message = "[Screenshot]: #{image_path}\n".dup
|
||||
message = +"[Screenshot]: #{image_path}\n"
|
||||
|
||||
case output_type
|
||||
when "artifact"
|
||||
|
@ -79,9 +79,8 @@ def normalize_argument_to_redirection(fragment)
|
||||
end
|
||||
|
||||
def generate_response_message(expected, actual = @response.response_code)
|
||||
"Expected response to be a <#{code_with_name(expected)}>,"\
|
||||
" but was a <#{code_with_name(actual)}>"
|
||||
.dup.concat(location_if_redirected).concat(response_body_if_short)
|
||||
(+"Expected response to be a <#{code_with_name(expected)}>,"\
|
||||
" but was a <#{code_with_name(actual)}>").concat(location_if_redirected).concat(response_body_if_short)
|
||||
end
|
||||
|
||||
def response_body_if_short
|
||||
|
@ -150,7 +150,7 @@ def authenticate_long_credentials
|
||||
end
|
||||
|
||||
test "token_and_options returns empty string with empty token" do
|
||||
token = "".dup
|
||||
token = +""
|
||||
actual = ActionController::HttpAuthentication::Token.token_and_options(sample_request(token)).first
|
||||
expected = token
|
||||
assert_equal(expected, actual)
|
||||
|
@ -13,7 +13,7 @@ class BareTest < ActiveSupport::TestCase
|
||||
test "response body is a Rack-compatible response" do
|
||||
status, headers, body = BareController.action(:index).call(Rack::MockRequest.env_for("/"))
|
||||
assert_equal 200, status
|
||||
string = "".dup
|
||||
string = +""
|
||||
|
||||
body.each do |part|
|
||||
assert part.is_a?(String), "Each part of the body must be a String"
|
||||
|
@ -674,7 +674,7 @@ def test_route_with_text_default
|
||||
assert_equal "/page/foo", url_for(rs, controller: "content", action: "show_page", id: "foo")
|
||||
assert_equal({ controller: "content", action: "show_page", id: "foo" }, rs.recognize_path("/page/foo"))
|
||||
|
||||
token = "\321\202\320\265\320\272\321\201\321\202".dup # 'text' in Russian
|
||||
token = +"\321\202\320\265\320\272\321\201\321\202" # 'text' in Russian
|
||||
token.force_encoding(Encoding::BINARY)
|
||||
escaped_token = CGI.escape(token)
|
||||
|
||||
|
@ -368,7 +368,7 @@ def call(env)
|
||||
})
|
||||
assert_response 500
|
||||
|
||||
assert_includes(body, CGI.escapeHTML(PP.pp(params, "".dup, 200)))
|
||||
assert_includes(body, CGI.escapeHTML(PP.pp(params, +"", 200)))
|
||||
end
|
||||
|
||||
test "sets the HTTP charset parameter" do
|
||||
|
@ -13,7 +13,7 @@ def to_param
|
||||
end
|
||||
|
||||
def self.model_name
|
||||
klass = "Post".dup
|
||||
klass = +"Post"
|
||||
def klass.name; self end
|
||||
|
||||
ActiveModel::Name.new(klass)
|
||||
|
@ -31,7 +31,7 @@ def test_handles_urls_with_bad_encoding
|
||||
end
|
||||
|
||||
def test_handles_urls_with_ascii_8bit
|
||||
assert_equal "Hello, World!", get("/doorkeeper%E3E4".dup.force_encoding("ASCII-8BIT")).body
|
||||
assert_equal "Hello, World!", get((+"/doorkeeper%E3E4").force_encoding("ASCII-8BIT")).body
|
||||
end
|
||||
|
||||
def test_handles_urls_with_ascii_8bit_on_win_31j
|
||||
@ -39,7 +39,7 @@ def test_handles_urls_with_ascii_8bit_on_win_31j
|
||||
Encoding.default_internal = "Windows-31J"
|
||||
Encoding.default_external = "Windows-31J"
|
||||
end
|
||||
assert_equal "Hello, World!", get("/doorkeeper%E3E4".dup.force_encoding("ASCII-8BIT")).body
|
||||
assert_equal "Hello, World!", get((+"/doorkeeper%E3E4").force_encoding("ASCII-8BIT")).body
|
||||
end
|
||||
|
||||
def test_handles_urls_with_null_byte
|
||||
|
@ -23,7 +23,7 @@ def test_uri_unescape
|
||||
end
|
||||
|
||||
def test_uri_unescape_with_utf8_string
|
||||
assert_equal "Šašinková", Utils.unescape_uri("%C5%A0a%C5%A1inkov%C3%A1".dup.force_encoding(Encoding::US_ASCII))
|
||||
assert_equal "Šašinková", Utils.unescape_uri((+"%C5%A0a%C5%A1inkov%C3%A1").force_encoding(Encoding::US_ASCII))
|
||||
end
|
||||
|
||||
def test_normalize_path_not_greedy
|
||||
|
@ -1053,7 +1053,7 @@ def build_select(type, select_options_as_html)
|
||||
select_options[:disabled] = "disabled" if @options[:disabled]
|
||||
select_options[:class] = css_class_attribute(type, select_options[:class], @options[:with_css_classes]) if @options[:with_css_classes]
|
||||
|
||||
select_html = "\n".dup
|
||||
select_html = +"\n"
|
||||
select_html << content_tag("option".freeze, "", value: "") + "\n" if @options[:include_blank]
|
||||
select_html << prompt_option_tag(type, @options[:prompt]) + "\n" if @options[:prompt]
|
||||
select_html << select_options_as_html
|
||||
@ -1135,7 +1135,7 @@ def input_id_from_type(type)
|
||||
# Given an ordering of datetime components, create the selection HTML
|
||||
# and join them with their appropriate separators.
|
||||
def build_selects_from_types(order)
|
||||
select = "".dup
|
||||
select = +""
|
||||
first_visible = order.find { |type| !@options[:"discard_#{type}"] }
|
||||
order.reverse_each do |type|
|
||||
separator = separator(type) unless type == first_visible # don't add before first visible field
|
||||
|
@ -15,8 +15,8 @@ module JavaScriptHelper
|
||||
"'" => "\\'"
|
||||
}
|
||||
|
||||
JS_ESCAPE_MAP["\342\200\250".dup.force_encoding(Encoding::UTF_8).encode!] = "
"
|
||||
JS_ESCAPE_MAP["\342\200\251".dup.force_encoding(Encoding::UTF_8).encode!] = "
"
|
||||
JS_ESCAPE_MAP[(+"\342\200\250").force_encoding(Encoding::UTF_8).encode!] = "
"
|
||||
JS_ESCAPE_MAP[(+"\342\200\251").force_encoding(Encoding::UTF_8).encode!] = "
"
|
||||
|
||||
# Escapes carriage returns and single and double quotes for JavaScript segments.
|
||||
#
|
||||
|
@ -58,7 +58,7 @@ def content_tag_string(name, content, options, escape = true)
|
||||
|
||||
def tag_options(options, escape = true)
|
||||
return if options.blank?
|
||||
output = "".dup
|
||||
output = +""
|
||||
sep = " "
|
||||
options.each_pair do |key, value|
|
||||
if TAG_PREFIXES.include?(key) && value.is_a?(Hash)
|
||||
|
@ -98,7 +98,7 @@ def translate(key, options = {})
|
||||
raise e if raise_error
|
||||
|
||||
keys = I18n.normalize_keys(e.locale, e.key, e.options[:scope])
|
||||
title = "translation missing: #{keys.join('.')}".dup
|
||||
title = +"translation missing: #{keys.join('.')}"
|
||||
|
||||
interpolations = options.except(:default, :scope)
|
||||
if interpolations.any?
|
||||
|
@ -16,7 +16,7 @@ def initialize
|
||||
|
||||
def render_template(event)
|
||||
info do
|
||||
message = " Rendered #{from_rails_root(event.payload[:identifier])}".dup
|
||||
message = +" Rendered #{from_rails_root(event.payload[:identifier])}"
|
||||
message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
|
||||
message << " (#{event.duration.round(1)}ms)"
|
||||
end
|
||||
@ -24,7 +24,7 @@ def render_template(event)
|
||||
|
||||
def render_partial(event)
|
||||
info do
|
||||
message = " Rendered #{from_rails_root(event.payload[:identifier])}".dup
|
||||
message = +" Rendered #{from_rails_root(event.payload[:identifier])}"
|
||||
message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
|
||||
message << " (#{event.duration.round(1)}ms)"
|
||||
message << " #{cache_message(event.payload)}" unless event.payload[:cache_hit].nil?
|
||||
@ -85,7 +85,7 @@ def cache_message(payload) # :doc:
|
||||
|
||||
def log_rendering_start(payload)
|
||||
info do
|
||||
message = " Rendering #{from_rails_root(payload[:identifier])}".dup
|
||||
message = +" Rendering #{from_rails_root(payload[:identifier])}"
|
||||
message << " within #{from_rails_root(payload[:layout])}" if payload[:layout]
|
||||
message
|
||||
end
|
||||
|
@ -33,7 +33,7 @@ def log_error(exception)
|
||||
logger = ActionView::Base.logger
|
||||
return unless logger
|
||||
|
||||
message = "\n#{exception.class} (#{exception.message}):\n".dup
|
||||
message = +"\n#{exception.class} (#{exception.message}):\n"
|
||||
message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code)
|
||||
message << " " << exception.backtrace.join("\n ")
|
||||
logger.fatal("#{message}\n\n")
|
||||
|
@ -286,7 +286,7 @@ def compile(mod)
|
||||
|
||||
# Make sure that the resulting String to be eval'd is in the
|
||||
# encoding of the code
|
||||
source = <<-end_src.dup
|
||||
source = +<<-end_src
|
||||
def #{method_name}(local_assigns, output_buffer)
|
||||
_old_virtual_path, @virtual_path = @virtual_path, #{@virtual_path.inspect};_old_output_buffer = @output_buffer;#{locals_code};#{code}
|
||||
ensure
|
||||
@ -335,12 +335,12 @@ def locals_code
|
||||
locals = locals.grep(/\A@?(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/)
|
||||
|
||||
# Assign for the same variable is to suppress unused variable warning
|
||||
locals.each_with_object("".dup) { |key, code| code << "#{key} = local_assigns[:#{key}]; #{key} = #{key};" }
|
||||
locals.each_with_object(+"") { |key, code| code << "#{key} = local_assigns[:#{key}]; #{key} = #{key};" }
|
||||
end
|
||||
|
||||
def method_name
|
||||
@method_name ||= begin
|
||||
m = "_#{identifier_method_name}__#{@identifier.hash}_#{__id__}".dup
|
||||
m = +"_#{identifier_method_name}__#{@identifier.hash}_#{__id__}"
|
||||
m.tr!("-".freeze, "_".freeze)
|
||||
m
|
||||
end
|
||||
|
@ -16,7 +16,7 @@ class Path
|
||||
alias_method :partial?, :partial
|
||||
|
||||
def self.build(name, prefix, partial)
|
||||
virtual = "".dup
|
||||
virtual = +""
|
||||
virtual << "#{prefix}/" unless prefix.empty?
|
||||
virtual << (partial ? "_#{name}" : name)
|
||||
new name, prefix, partial, virtual
|
||||
|
@ -107,7 +107,7 @@ def setup_with_controller
|
||||
# empty string ensures buffer has UTF-8 encoding as
|
||||
# new without arguments returns ASCII-8BIT encoded buffer like String#new
|
||||
@output_buffer = ActiveSupport::SafeBuffer.new ""
|
||||
@rendered = "".dup
|
||||
@rendered = +""
|
||||
|
||||
make_test_case_available_to_view!
|
||||
say_no_to_protect_against_forgery!
|
||||
|
@ -22,7 +22,7 @@ def to_s
|
||||
private
|
||||
|
||||
def query(path, exts, _, _)
|
||||
query = "".dup
|
||||
query = +""
|
||||
EXTENSIONS.each_key do |ext|
|
||||
query << "(" << exts[ext].map { |e| e && Regexp.escape(".#{e}") }.join("|") << "|)"
|
||||
end
|
||||
|
@ -57,7 +57,7 @@ def test_nested_fields_for_with_child_index_option_override_on_a_nested_attribut
|
||||
private
|
||||
|
||||
def hidden_fields(method = nil)
|
||||
txt = %{<input name="utf8" type="hidden" value="✓" />}.dup
|
||||
txt = +%{<input name="utf8" type="hidden" value="✓" />}
|
||||
|
||||
if method && !%w(get post).include?(method.to_s)
|
||||
txt << %{<input name="_method" type="hidden" value="#{method}" />}
|
||||
@ -67,7 +67,7 @@ def hidden_fields(method = nil)
|
||||
end
|
||||
|
||||
def form_text(action = "/", id = nil, html_class = nil, remote = nil, multipart = nil, method = nil)
|
||||
txt = %{<form accept-charset="UTF-8" action="#{action}"}.dup
|
||||
txt = +%{<form accept-charset="UTF-8" action="#{action}"}
|
||||
txt << %{ enctype="multipart/form-data"} if multipart
|
||||
txt << %{ data-remote="true"} if remote
|
||||
txt << %{ class="#{html_class}"} if html_class
|
||||
|
2
actionview/test/fixtures/ruby_template.ruby
vendored
2
actionview/test/fixtures/ruby_template.ruby
vendored
@ -1,2 +1,2 @@
|
||||
body = "".dup
|
||||
body = +""
|
||||
body << ["Hello", "from", "Ruby", "code"].join(" ")
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -37,7 +37,7 @@ def hidden_fields(options = {})
|
||||
method = options[:method]
|
||||
skip_enforcing_utf8 = options.fetch(:skip_enforcing_utf8, false)
|
||||
|
||||
"".dup.tap do |txt|
|
||||
(+"").tap do |txt|
|
||||
unless skip_enforcing_utf8
|
||||
txt << %{<input name="utf8" type="hidden" value="✓" />}
|
||||
end
|
||||
@ -53,7 +53,7 @@ def form_text(action = "http://www.example.com", local: false, **options)
|
||||
|
||||
method = method.to_s == "get" ? "get" : "post"
|
||||
|
||||
txt = %{<form accept-charset="UTF-8" action="#{action}"}.dup
|
||||
txt = +%{<form accept-charset="UTF-8" action="#{action}"}
|
||||
txt << %{ enctype="multipart/form-data"} if enctype
|
||||
txt << %{ data-remote="true"} unless local
|
||||
txt << %{ class="#{html_class}"} if html_class
|
||||
@ -2325,9 +2325,9 @@ def hidden_fields(options = {})
|
||||
method = options[:method]
|
||||
|
||||
if options.fetch(:skip_enforcing_utf8, false)
|
||||
txt = "".dup
|
||||
txt = +""
|
||||
else
|
||||
txt = %{<input name="utf8" type="hidden" value="✓" />}.dup
|
||||
txt = +%{<input name="utf8" type="hidden" value="✓" />}
|
||||
end
|
||||
|
||||
if method && !%w(get post).include?(method.to_s)
|
||||
@ -2338,7 +2338,7 @@ def hidden_fields(options = {})
|
||||
end
|
||||
|
||||
def form_text(action = "/", id = nil, html_class = nil, local = nil, multipart = nil, method = nil)
|
||||
txt = %{<form accept-charset="UTF-8" action="#{action}"}.dup
|
||||
txt = +%{<form accept-charset="UTF-8" action="#{action}"}
|
||||
txt << %{ enctype="multipart/form-data"} if multipart
|
||||
txt << %{ data-remote="true"} unless local
|
||||
txt << %{ class="#{html_class}"} if html_class
|
||||
|
@ -3558,9 +3558,9 @@ def hidden_fields(options = {})
|
||||
method = options[:method]
|
||||
|
||||
if options.fetch(:enforce_utf8, true)
|
||||
txt = %{<input name="utf8" type="hidden" value="✓" />}.dup
|
||||
txt = +%{<input name="utf8" type="hidden" value="✓" />}
|
||||
else
|
||||
txt = "".dup
|
||||
txt = +""
|
||||
end
|
||||
|
||||
if method && !%w(get post).include?(method.to_s)
|
||||
@ -3571,7 +3571,7 @@ def hidden_fields(options = {})
|
||||
end
|
||||
|
||||
def form_text(action = "/", id = nil, html_class = nil, remote = nil, multipart = nil, method = nil)
|
||||
txt = %{<form accept-charset="UTF-8" action="#{action}"}.dup
|
||||
txt = +%{<form accept-charset="UTF-8" action="#{action}"}
|
||||
txt << %{ enctype="multipart/form-data"} if multipart
|
||||
txt << %{ data-remote="true"} if remote
|
||||
txt << %{ class="#{html_class}"} if html_class
|
||||
|
@ -26,7 +26,7 @@ def hidden_fields(options = {})
|
||||
method = options[:method]
|
||||
enforce_utf8 = options.fetch(:enforce_utf8, true)
|
||||
|
||||
"".dup.tap do |txt|
|
||||
(+"").tap do |txt|
|
||||
if enforce_utf8
|
||||
txt << %{<input name="utf8" type="hidden" value="✓" />}
|
||||
end
|
||||
@ -42,7 +42,7 @@ def form_text(action = "http://www.example.com", options = {})
|
||||
|
||||
method = method.to_s == "get" ? "get" : "post"
|
||||
|
||||
txt = %{<form accept-charset="UTF-8" action="#{action}"}.dup
|
||||
txt = +%{<form accept-charset="UTF-8" action="#{action}"}
|
||||
txt << %{ enctype="multipart/form-data"} if enctype
|
||||
txt << %{ data-remote="true"} if remote
|
||||
txt << %{ class="#{html_class}"} if html_class
|
||||
|
@ -30,8 +30,8 @@ def test_escape_javascript
|
||||
assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos'))
|
||||
assert_equal %(backslash\\\\test), escape_javascript(%(backslash\\test))
|
||||
assert_equal %(dont <\\/close> tags), escape_javascript(%(dont </close> tags))
|
||||
assert_equal %(unicode 
 newline), escape_javascript(%(unicode \342\200\250 newline).dup.force_encoding(Encoding::UTF_8).encode!)
|
||||
assert_equal %(unicode 
 newline), escape_javascript(%(unicode \342\200\251 newline).dup.force_encoding(Encoding::UTF_8).encode!)
|
||||
assert_equal %(unicode 
 newline), escape_javascript((+%(unicode \342\200\250 newline)).force_encoding(Encoding::UTF_8).encode!)
|
||||
assert_equal %(unicode 
 newline), escape_javascript((+%(unicode \342\200\251 newline)).force_encoding(Encoding::UTF_8).encode!)
|
||||
|
||||
assert_equal %(dont <\\/close> tags), j(%(dont </close> tags))
|
||||
end
|
||||
|
@ -585,7 +585,7 @@ def test_render_layout_with_object
|
||||
|
||||
def test_render_with_passing_couple_extensions_to_one_register_template_handler_function_call
|
||||
ActionView::Template.register_template_handler :foo1, :foo2, CustomHandler
|
||||
assert_equal @view.render(inline: "Hello, World!".dup, type: :foo1), @view.render(inline: "Hello, World!".dup, type: :foo2)
|
||||
assert_equal @view.render(inline: +"Hello, World!", type: :foo1), @view.render(inline: +"Hello, World!", type: :foo2)
|
||||
ensure
|
||||
ActionView::Template.unregister_template_handler :foo1, :foo2
|
||||
end
|
||||
|
@ -19,7 +19,7 @@ def render_body(options)
|
||||
|
||||
def buffered_render(options)
|
||||
body = render_body(options)
|
||||
string = "".dup
|
||||
string = +""
|
||||
body.each do |piece|
|
||||
string << piece
|
||||
end
|
||||
|
@ -13,7 +13,7 @@ def setup
|
||||
end
|
||||
|
||||
def test_concat
|
||||
self.output_buffer = "foo".dup
|
||||
self.output_buffer = +"foo"
|
||||
assert_equal "foobar", concat("bar")
|
||||
assert_equal "foobar", output_buffer
|
||||
end
|
||||
@ -106,8 +106,8 @@ def test_truncate_with_options_hash
|
||||
end
|
||||
|
||||
def test_truncate_multibyte
|
||||
assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".dup.force_encoding(Encoding::UTF_8),
|
||||
truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".dup.force_encoding(Encoding::UTF_8), length: 10)
|
||||
assert_equal (+"\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...").force_encoding(Encoding::UTF_8),
|
||||
truncate((+"\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244").force_encoding(Encoding::UTF_8), length: 10)
|
||||
end
|
||||
|
||||
def test_truncate_does_not_modify_the_options_hash
|
||||
@ -327,7 +327,7 @@ def test_excerpt_with_omission
|
||||
end
|
||||
|
||||
def test_excerpt_with_utf8
|
||||
assert_equal("...\357\254\203ciency could not be...".dup.force_encoding(Encoding::UTF_8), excerpt("That's why e\357\254\203ciency could not be helped".dup.force_encoding(Encoding::UTF_8), "could", radius: 8))
|
||||
assert_equal((+"...\357\254\203ciency could not be...").force_encoding(Encoding::UTF_8), excerpt((+"That's why e\357\254\203ciency could not be helped").force_encoding(Encoding::UTF_8), "could", radius: 8))
|
||||
end
|
||||
|
||||
def test_excerpt_does_not_modify_the_options_hash
|
||||
|
@ -548,7 +548,7 @@ def test_current_page_with_escaped_params
|
||||
|
||||
def test_current_page_with_escaped_params_with_different_encoding
|
||||
@request = request_for_url("/")
|
||||
@request.stub(:path, "/category/administra%c3%a7%c3%a3o".dup.force_encoding(Encoding::ASCII_8BIT)) do
|
||||
@request.stub(:path, (+"/category/administra%c3%a7%c3%a3o").force_encoding(Encoding::ASCII_8BIT)) do
|
||||
assert current_page?(controller: "foo", action: "category", category: "administração")
|
||||
assert current_page?("http://www.example.com/category/administra%c3%a7%c3%a3o")
|
||||
end
|
||||
|
@ -78,7 +78,7 @@ class AttributeTest < ActiveModel::TestCase
|
||||
end
|
||||
|
||||
test "duping dups the value" do
|
||||
@type.expect(:deserialize, "type cast".dup, ["a value"])
|
||||
@type.expect(:deserialize, +"type cast", ["a value"])
|
||||
attribute = Attribute.from_database(nil, "a value", @type)
|
||||
|
||||
value_from_orig = attribute.value
|
||||
@ -246,7 +246,7 @@ def assert_valid_value(*)
|
||||
end
|
||||
|
||||
test "with_type preserves mutations" do
|
||||
attribute = Attribute.from_database(:foo, "".dup, Type::Value.new)
|
||||
attribute = Attribute.from_database(:foo, +"", Type::Value.new)
|
||||
attribute.value << "1"
|
||||
|
||||
assert_equal 1, attribute.with_type(Type::Integer.new).value
|
||||
|
@ -94,7 +94,7 @@ def reload
|
||||
end
|
||||
|
||||
test "attribute mutation" do
|
||||
@model.instance_variable_set("@name", "Yam".dup)
|
||||
@model.instance_variable_set("@name", +"Yam")
|
||||
assert_not_predicate @model, :name_changed?
|
||||
@model.name.replace("Hadad")
|
||||
assert_not_predicate @model, :name_changed?
|
||||
|
@ -15,7 +15,7 @@ class StringTest < ActiveModel::TestCase
|
||||
test "cast strings are mutable" do
|
||||
type = Type::String.new
|
||||
|
||||
s = "foo".dup
|
||||
s = +"foo"
|
||||
assert_equal false, type.cast(s).frozen?
|
||||
assert_equal false, s.frozen?
|
||||
|
||||
|
@ -731,7 +731,7 @@ def checkout_for_exclusive_access(checkout_timeout)
|
||||
# this block can't be easily moved into attempt_to_checkout_all_existing_connections's
|
||||
# rescue block, because doing so would put it outside of synchronize section, without
|
||||
# being in a critical section thread_report might become inaccurate
|
||||
msg = "could not obtain ownership of all database connections in #{checkout_timeout} seconds".dup
|
||||
msg = +"could not obtain ownership of all database connections in #{checkout_timeout} seconds"
|
||||
|
||||
thread_report = []
|
||||
@connections.each do |conn|
|
||||
|
@ -379,7 +379,7 @@ def insert_fixtures_set(fixture_set, tables_to_delete = [])
|
||||
build_fixture_sql(fixtures, table_name)
|
||||
end.compact
|
||||
|
||||
table_deletes = tables_to_delete.map { |table| "DELETE FROM #{quote_table_name table}".dup }
|
||||
table_deletes = tables_to_delete.map { |table| +"DELETE FROM #{quote_table_name table}" }
|
||||
total_sql = Array.wrap(combine_multi_statements(table_deletes + fixture_inserts))
|
||||
|
||||
disable_referential_integrity do
|
||||
|
@ -21,7 +21,7 @@ def accept(o)
|
||||
private
|
||||
|
||||
def visit_AlterTable(o)
|
||||
sql = "ALTER TABLE #{quote_table_name(o.name)} ".dup
|
||||
sql = +"ALTER TABLE #{quote_table_name(o.name)} "
|
||||
sql << o.adds.map { |col| accept col }.join(" ")
|
||||
sql << o.foreign_key_adds.map { |fk| visit_AddForeignKey fk }.join(" ")
|
||||
sql << o.foreign_key_drops.map { |fk| visit_DropForeignKey fk }.join(" ")
|
||||
@ -29,17 +29,17 @@ def visit_AlterTable(o)
|
||||
|
||||
def visit_ColumnDefinition(o)
|
||||
o.sql_type = type_to_sql(o.type, o.options)
|
||||
column_sql = "#{quote_column_name(o.name)} #{o.sql_type}".dup
|
||||
column_sql = +"#{quote_column_name(o.name)} #{o.sql_type}"
|
||||
add_column_options!(column_sql, column_options(o)) unless o.type == :primary_key
|
||||
column_sql
|
||||
end
|
||||
|
||||
def visit_AddColumnDefinition(o)
|
||||
"ADD #{accept(o.column)}".dup
|
||||
+"ADD #{accept(o.column)}"
|
||||
end
|
||||
|
||||
def visit_TableDefinition(o)
|
||||
create_sql = "CREATE#{' TEMPORARY' if o.temporary} TABLE #{quote_table_name(o.name)} ".dup
|
||||
create_sql = +"CREATE#{' TEMPORARY' if o.temporary} TABLE #{quote_table_name(o.name)} "
|
||||
|
||||
statements = o.columns.map { |c| accept c }
|
||||
statements << accept(o.primary_keys) if o.primary_keys
|
||||
|
@ -1380,7 +1380,7 @@ def insert_versions_sql(versions)
|
||||
sm_table = quote_table_name(ActiveRecord::SchemaMigration.table_name)
|
||||
|
||||
if versions.is_a?(Array)
|
||||
sql = "INSERT INTO #{sm_table} (version) VALUES\n".dup
|
||||
sql = +"INSERT INTO #{sm_table} (version) VALUES\n"
|
||||
sql << versions.map { |v| "(#{quote(v)})" }.join(",\n")
|
||||
sql << ";\n\n"
|
||||
sql
|
||||
|
@ -162,7 +162,7 @@ def valid_type?(type) # :nodoc:
|
||||
# this method must only be called while holding connection pool's mutex
|
||||
def lease
|
||||
if in_use?
|
||||
msg = "Cannot lease connection, ".dup
|
||||
msg = +"Cannot lease connection, "
|
||||
if @owner == Thread.current
|
||||
msg << "it is already leased by the current thread."
|
||||
else
|
||||
|
@ -137,7 +137,7 @@ def native_database_types
|
||||
end
|
||||
|
||||
def index_algorithms
|
||||
{ default: "ALGORITHM = DEFAULT".dup, copy: "ALGORITHM = COPY".dup, inplace: "ALGORITHM = INPLACE".dup }
|
||||
{ default: +"ALGORITHM = DEFAULT", copy: +"ALGORITHM = COPY", inplace: +"ALGORITHM = INPLACE" }
|
||||
end
|
||||
|
||||
# HELPER METHODS ===========================================
|
||||
@ -392,7 +392,7 @@ def rename_column(table_name, column_name, new_column_name) #:nodoc:
|
||||
|
||||
def add_index(table_name, column_name, options = {}) #:nodoc:
|
||||
index_name, index_type, index_columns, _, index_algorithm, index_using, comment = add_index_options(table_name, column_name, options)
|
||||
sql = "CREATE #{index_type} INDEX #{quote_column_name(index_name)} #{index_using} ON #{quote_table_name(table_name)} (#{index_columns}) #{index_algorithm}".dup
|
||||
sql = +"CREATE #{index_type} INDEX #{quote_column_name(index_name)} #{index_using} ON #{quote_table_name(table_name)} (#{index_columns}) #{index_algorithm}"
|
||||
execute add_sql_comment!(sql, comment)
|
||||
end
|
||||
|
||||
@ -785,7 +785,7 @@ def configure_connection
|
||||
# https://dev.mysql.com/doc/refman/5.7/en/set-names.html
|
||||
# (trailing comma because variable_assignments will always have content)
|
||||
if @config[:encoding]
|
||||
encoding = "NAMES #{@config[:encoding]}".dup
|
||||
encoding = +"NAMES #{@config[:encoding]}"
|
||||
encoding << " COLLATE #{@config[:collation]}" if @config[:collation]
|
||||
encoding << ", "
|
||||
end
|
||||
|
@ -17,7 +17,7 @@ def visit_AddColumnDefinition(o)
|
||||
end
|
||||
|
||||
def visit_ChangeColumnDefinition(o)
|
||||
change_column_sql = "CHANGE #{quote_column_name(o.name)} #{accept(o.column)}".dup
|
||||
change_column_sql = +"CHANGE #{quote_column_name(o.name)} #{accept(o.column)}"
|
||||
add_column_position!(change_column_sql, column_options(o.column))
|
||||
end
|
||||
|
||||
@ -64,7 +64,7 @@ def add_column_position!(sql, options)
|
||||
|
||||
def index_in_create(table_name, column_name, options)
|
||||
index_name, index_type, index_columns, _, _, index_using, comment = @conn.add_index_options(table_name, column_name, options)
|
||||
add_sql_comment!("#{index_type} INDEX #{quote_column_name(index_name)} #{index_using} (#{index_columns})".dup, comment)
|
||||
add_sql_comment!((+"#{index_type} INDEX #{quote_column_name(index_name)} #{index_using} (#{index_columns})"), comment)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -121,7 +121,7 @@ def add_options_for_index_columns(quoted_columns, **options)
|
||||
def data_source_sql(name = nil, type: nil)
|
||||
scope = quoted_scope(name, type: type)
|
||||
|
||||
sql = "SELECT table_name FROM information_schema.tables".dup
|
||||
sql = +"SELECT table_name FROM information_schema.tables"
|
||||
sql << " WHERE table_schema = #{scope[:schema]}"
|
||||
sql << " AND table_name = #{scope[:name]}" if scope[:name]
|
||||
sql << " AND table_type = #{scope[:type]}" if scope[:type]
|
||||
|
@ -686,7 +686,7 @@ def extract_foreign_key_action(specifier)
|
||||
def change_column_sql(table_name, column_name, type, options = {})
|
||||
quoted_column_name = quote_column_name(column_name)
|
||||
sql_type = type_to_sql(type, options)
|
||||
sql = "ALTER COLUMN #{quoted_column_name} TYPE #{sql_type}".dup
|
||||
sql = +"ALTER COLUMN #{quoted_column_name} TYPE #{sql_type}"
|
||||
if options[:collation]
|
||||
sql << " COLLATE \"#{options[:collation]}\""
|
||||
end
|
||||
@ -757,7 +757,7 @@ def data_source_sql(name = nil, type: nil)
|
||||
scope = quoted_scope(name, type: type)
|
||||
scope[:type] ||= "'r','v','m','p','f'" # (r)elation/table, (v)iew, (m)aterialized view, (p)artitioned table, (f)oreign table
|
||||
|
||||
sql = "SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace".dup
|
||||
sql = +"SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace"
|
||||
sql << " WHERE n.nspname = #{scope[:schema]}"
|
||||
sql << " AND c.relname = #{scope[:name]}" if scope[:name]
|
||||
sql << " AND c.relkind IN (#{scope[:type]})"
|
||||
|
@ -86,7 +86,7 @@ def data_source_sql(name = nil, type: nil)
|
||||
scope = quoted_scope(name, type: type)
|
||||
scope[:type] ||= "'table','view'"
|
||||
|
||||
sql = "SELECT name FROM sqlite_master WHERE name <> 'sqlite_sequence'".dup
|
||||
sql = +"SELECT name FROM sqlite_master WHERE name <> 'sqlite_sequence'"
|
||||
sql << " AND name = #{scope[:name]}" if scope[:name]
|
||||
sql << " AND type IN (#{scope[:type]})"
|
||||
sql
|
||||
|
@ -18,7 +18,7 @@ def collecting_queries_for_explain # :nodoc:
|
||||
# Returns a formatted string ready to be logged.
|
||||
def exec_explain(queries) # :nodoc:
|
||||
str = queries.map do |sql, binds|
|
||||
msg = "EXPLAIN for: #{sql}".dup
|
||||
msg = +"EXPLAIN for: #{sql}"
|
||||
unless binds.empty?
|
||||
msg << " "
|
||||
msg << binds.map { |attr| render_bind(attr) }.inspect
|
||||
|
@ -161,7 +161,7 @@ def initialize
|
||||
|
||||
class ProtectedEnvironmentError < ActiveRecordError #:nodoc:
|
||||
def initialize(env = "production")
|
||||
msg = "You are attempting to run a destructive action against your '#{env}' database.\n".dup
|
||||
msg = +"You are attempting to run a destructive action against your '#{env}' database.\n"
|
||||
msg << "If you are sure you want to continue, run the same command with the environment variable:\n"
|
||||
msg << "DISABLE_DATABASE_ENVIRONMENT_CHECK=1"
|
||||
super(msg)
|
||||
@ -170,7 +170,7 @@ def initialize(env = "production")
|
||||
|
||||
class EnvironmentMismatchError < ActiveRecordError
|
||||
def initialize(current: nil, stored: nil)
|
||||
msg = "You are attempting to modify a database that was last run in `#{ stored }` environment.\n".dup
|
||||
msg = +"You are attempting to modify a database that was last run in `#{ stored }` environment.\n"
|
||||
msg << "You are running in `#{ current }` environment. "
|
||||
msg << "If you are sure you want to continue, first set the environment using:\n\n"
|
||||
msg << " rails db:environment:set"
|
||||
@ -891,7 +891,7 @@ def copy(destination, sources, options = {})
|
||||
source_migrations.each do |migration|
|
||||
source = File.binread(migration.filename)
|
||||
inserted_comment = "# This migration comes from #{scope} (originally #{migration.version})\n"
|
||||
magic_comments = "".dup
|
||||
magic_comments = +""
|
||||
loop do
|
||||
# If we have a magic comment in the original migration,
|
||||
# insert our comment after the first newline(end of the magic comment line)
|
||||
@ -1299,7 +1299,7 @@ def execute_migration_in_transaction(migration, direction)
|
||||
record_version_state_after_migrating(migration.version)
|
||||
end
|
||||
rescue => e
|
||||
msg = "An error has occurred, ".dup
|
||||
msg = +"An error has occurred, "
|
||||
msg << "this and " if use_transaction?(migration)
|
||||
msg << "all later migrations canceled:\n\n#{e}"
|
||||
raise StandardError, msg, e.backtrace
|
||||
|
@ -338,14 +338,14 @@ def raise_record_not_found_exception!(ids = nil, result_size = nil, expected_siz
|
||||
name = @klass.name
|
||||
|
||||
if ids.nil?
|
||||
error = "Couldn't find #{name}".dup
|
||||
error = +"Couldn't find #{name}"
|
||||
error << " with#{conditions}" if conditions
|
||||
raise RecordNotFound.new(error, name, key)
|
||||
elsif Array(ids).size == 1
|
||||
error = "Couldn't find #{name} with '#{key}'=#{ids}#{conditions}"
|
||||
raise RecordNotFound.new(error, name, key, ids)
|
||||
else
|
||||
error = "Couldn't find all #{name.pluralize} with '#{key}': ".dup
|
||||
error = +"Couldn't find all #{name.pluralize} with '#{key}': "
|
||||
error << "(#{ids.join(", ")})#{conditions} (found #{result_size} results, but was looking for #{expected_size})."
|
||||
error << " Couldn't find #{name.pluralize(not_found_ids.size)} with #{key.to_s.pluralize(not_found_ids.size)} #{not_found_ids.join(', ')}." if not_found_ids
|
||||
raise RecordNotFound.new(error, name, key, ids)
|
||||
|
@ -307,7 +307,7 @@ def load_schema_current(format = ActiveRecord::Base.schema_format, file = nil, e
|
||||
|
||||
def check_schema_file(filename)
|
||||
unless File.exist?(filename)
|
||||
message = %{#{filename} doesn't exist yet. Run `rails db:migrate` to create it, then try again.}.dup
|
||||
message = +%{#{filename} doesn't exist yet. Run `rails db:migrate` to create it, then try again.}
|
||||
message << %{ If you do not intend to use a database, you should instead alter #{Rails.root}/config/application.rb to limit the frameworks that will be loaded.} if defined?(::Rails.root)
|
||||
Kernel.abort message
|
||||
end
|
||||
|
@ -104,7 +104,7 @@ def run_cmd(cmd, args, action)
|
||||
end
|
||||
|
||||
def run_cmd_error(cmd, args, action)
|
||||
msg = "failed to execute: `#{cmd}`\n".dup
|
||||
msg = +"failed to execute: `#{cmd}`\n"
|
||||
msg << "Please check the output above for any errors and make sure that `#{cmd}` is installed in your PATH and has proper permissions.\n\n"
|
||||
msg
|
||||
end
|
||||
|
@ -115,7 +115,7 @@ def run_cmd(cmd, args, action)
|
||||
end
|
||||
|
||||
def run_cmd_error(cmd, args, action)
|
||||
msg = "failed to execute:\n".dup
|
||||
msg = +"failed to execute:\n"
|
||||
msg << "#{cmd} #{args.join(' ')}\n\n"
|
||||
msg << "Please check the output above for any errors and make sure that `#{cmd}` is installed in your PATH and has proper permissions.\n\n"
|
||||
msg
|
||||
|
@ -67,7 +67,7 @@ def run_cmd(cmd, args, out)
|
||||
end
|
||||
|
||||
def run_cmd_error(cmd, args)
|
||||
msg = "failed to execute:\n".dup
|
||||
msg = +"failed to execute:\n"
|
||||
msg << "#{cmd} #{args.join(' ')}\n\n"
|
||||
msg << "Please check the output above for any errors and make sure that `#{cmd}` is installed in your PATH and has proper permissions.\n\n"
|
||||
msg
|
||||
|
@ -4,7 +4,7 @@ module Arel # :nodoc: all
|
||||
module Collectors
|
||||
class PlainString
|
||||
def initialize
|
||||
@str = "".dup
|
||||
@str = +""
|
||||
end
|
||||
|
||||
def value
|
||||
|
@ -290,7 +290,7 @@ def test_select_methods_passing_a_relation
|
||||
def test_log_invalid_encoding
|
||||
error = assert_raises RuntimeError do
|
||||
@connection.send :log, "SELECT 'ы' FROM DUAL" do
|
||||
raise "ы".dup.force_encoding(Encoding::ASCII_8BIT)
|
||||
raise (+"ы").force_encoding(Encoding::ASCII_8BIT)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -49,7 +49,7 @@ def test_type_cast_binary_converts_the_encoding
|
||||
end
|
||||
|
||||
def test_type_cast_binary_value
|
||||
data = "\u001F\x8B".dup.force_encoding("BINARY")
|
||||
data = (+"\u001F\x8B").force_encoding("BINARY")
|
||||
assert_equal(data, @type.deserialize(data))
|
||||
end
|
||||
|
||||
|
@ -52,10 +52,10 @@ def test_money_values
|
||||
|
||||
def test_money_type_cast
|
||||
type = PostgresqlMoney.type_for_attribute("wealth")
|
||||
assert_equal(12345678.12, type.cast("$12,345,678.12".dup))
|
||||
assert_equal(12345678.12, type.cast("$12.345.678,12".dup))
|
||||
assert_equal(-1.15, type.cast("-$1.15".dup))
|
||||
assert_equal(-2.25, type.cast("($2.25)".dup))
|
||||
assert_equal(12345678.12, type.cast(+"$12,345,678.12"))
|
||||
assert_equal(12345678.12, type.cast(+"$12.345.678,12"))
|
||||
assert_equal(-1.15, type.cast(+"-$1.15"))
|
||||
assert_equal(-2.25, type.cast(+"($2.25)"))
|
||||
end
|
||||
|
||||
def test_schema_dumping
|
||||
@ -65,7 +65,7 @@ def test_schema_dumping
|
||||
end
|
||||
|
||||
def test_create_and_update_money
|
||||
money = PostgresqlMoney.create(wealth: "987.65".dup)
|
||||
money = PostgresqlMoney.create(wealth: +"987.65")
|
||||
assert_equal 987.65, money.wealth
|
||||
|
||||
new_value = BigDecimal("123.45")
|
||||
|
@ -167,7 +167,7 @@ def test_quote_binary_column_escapes_it
|
||||
data binary
|
||||
)
|
||||
eosql
|
||||
str = "\x80".dup.force_encoding("ASCII-8BIT")
|
||||
str = (+"\x80").force_encoding("ASCII-8BIT")
|
||||
binary = DualEncoding.new name: "いただきます!", data: str
|
||||
binary.save!
|
||||
assert_equal str, binary.data
|
||||
@ -176,7 +176,7 @@ def test_quote_binary_column_escapes_it
|
||||
end
|
||||
|
||||
def test_type_cast_should_not_mutate_encoding
|
||||
name = "hello".dup.force_encoding(Encoding::ASCII_8BIT)
|
||||
name = (+"hello").force_encoding(Encoding::ASCII_8BIT)
|
||||
Owner.create(name: name)
|
||||
assert_equal Encoding::ASCII_8BIT, name.encoding
|
||||
ensure
|
||||
|
@ -155,7 +155,7 @@ def test_find_in_batches_should_quote_batch_order
|
||||
end
|
||||
|
||||
def test_find_in_batches_should_not_use_records_after_yielding_them_in_case_original_array_is_modified
|
||||
not_a_post = "not a post".dup
|
||||
not_a_post = +"not a post"
|
||||
def not_a_post.id; end
|
||||
not_a_post.stub(:id, -> { raise StandardError.new("not_a_post had #id called on it") }) do
|
||||
assert_nothing_raised do
|
||||
@ -420,7 +420,7 @@ def test_in_batches_should_quote_batch_order
|
||||
end
|
||||
|
||||
def test_in_batches_should_not_use_records_after_yielding_them_in_case_original_array_is_modified
|
||||
not_a_post = "not a post".dup
|
||||
not_a_post = +"not a post"
|
||||
def not_a_post.id
|
||||
raise StandardError.new("not_a_post had #id called on it")
|
||||
end
|
||||
|
@ -12,7 +12,7 @@ class BinaryTest < ActiveRecord::TestCase
|
||||
FIXTURES = %w(flowers.jpg example.log test.txt)
|
||||
|
||||
def test_mixed_encoding
|
||||
str = "\x80".dup
|
||||
str = +"\x80"
|
||||
str.force_encoding("ASCII-8BIT")
|
||||
|
||||
binary = Binary.new name: "いただきます!", data: str
|
||||
|
@ -36,7 +36,7 @@ def test_inspect_class_without_table
|
||||
|
||||
def test_pretty_print_new
|
||||
topic = Topic.new
|
||||
actual = "".dup
|
||||
actual = +""
|
||||
PP.pp(topic, StringIO.new(actual))
|
||||
expected = <<~PRETTY
|
||||
#<Topic:0xXXXXXX
|
||||
@ -65,7 +65,7 @@ def test_pretty_print_new
|
||||
|
||||
def test_pretty_print_persisted
|
||||
topic = topics(:first)
|
||||
actual = "".dup
|
||||
actual = +""
|
||||
PP.pp(topic, StringIO.new(actual))
|
||||
expected = <<~PRETTY
|
||||
#<Topic:0x\\w+
|
||||
@ -93,7 +93,7 @@ def test_pretty_print_persisted
|
||||
|
||||
def test_pretty_print_uninitialized
|
||||
topic = Topic.allocate
|
||||
actual = "".dup
|
||||
actual = +""
|
||||
PP.pp(topic, StringIO.new(actual))
|
||||
expected = "#<Topic:XXXXXX not initialized>\n"
|
||||
assert actual.start_with?(expected.split("XXXXXX").first)
|
||||
@ -106,7 +106,7 @@ def inspect
|
||||
"inspecting topic"
|
||||
end
|
||||
end
|
||||
actual = "".dup
|
||||
actual = +""
|
||||
PP.pp(subtopic.new, StringIO.new(actual))
|
||||
assert_equal "inspecting topic\n", actual
|
||||
end
|
||||
|
@ -32,7 +32,7 @@ def test_overriding_registered_types
|
||||
end
|
||||
|
||||
def test_fuzzy_lookup
|
||||
string = String.new
|
||||
string = +""
|
||||
mapping = TypeMap.new
|
||||
|
||||
mapping.register_type(/varchar/i, string)
|
||||
@ -41,7 +41,7 @@ def test_fuzzy_lookup
|
||||
end
|
||||
|
||||
def test_aliasing_types
|
||||
string = String.new
|
||||
string = +""
|
||||
mapping = TypeMap.new
|
||||
|
||||
mapping.register_type(/string/i, string)
|
||||
@ -73,7 +73,7 @@ def test_aliases_keep_metadata
|
||||
end
|
||||
|
||||
def test_register_proc
|
||||
string = String.new
|
||||
string = +""
|
||||
binary = Binary.new
|
||||
mapping = TypeMap.new
|
||||
|
||||
|
@ -30,8 +30,8 @@ class ActiveStorage::FilenameTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "sanitize transcodes to valid UTF-8" do
|
||||
{ "\xF6".dup.force_encoding(Encoding::ISO8859_1) => "ö",
|
||||
"\xC3".dup.force_encoding(Encoding::ISO8859_1) => "Ã",
|
||||
{ (+"\xF6").force_encoding(Encoding::ISO8859_1) => "ö",
|
||||
(+"\xC3").force_encoding(Encoding::ISO8859_1) => "Ã",
|
||||
"\xAD" => "<EFBFBD>",
|
||||
"\xCF" => "<EFBFBD>",
|
||||
"\x00" => "",
|
||||
|
@ -6,7 +6,7 @@
|
||||
module ActiveStorage::Service::SharedServiceTests
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
FIXTURE_DATA = "\211PNG\r\n\032\n\000\000\000\rIHDR\000\000\000\020\000\000\000\020\001\003\000\000\000%=m\"\000\000\000\006PLTE\000\000\000\377\377\377\245\331\237\335\000\000\0003IDATx\234c\370\377\237\341\377_\206\377\237\031\016\2603\334?\314p\1772\303\315\315\f7\215\031\356\024\203\320\275\317\f\367\201R\314\f\017\300\350\377\177\000Q\206\027(\316]\233P\000\000\000\000IEND\256B`\202".dup.force_encoding(Encoding::BINARY)
|
||||
FIXTURE_DATA = (+"\211PNG\r\n\032\n\000\000\000\rIHDR\000\000\000\020\000\000\000\020\001\003\000\000\000%=m\"\000\000\000\006PLTE\000\000\000\377\377\377\245\331\237\335\000\000\0003IDATx\234c\370\377\237\341\377_\206\377\237\031\016\2603\334?\314p\1772\303\315\315\f7\215\031\356\024\203\320\275\317\f\367\201R\314\f\017\300\350\377\177\000Q\206\027(\316]\233P\000\000\000\000IEND\256B`\202").force_encoding(Encoding::BINARY)
|
||||
|
||||
included do
|
||||
setup do
|
||||
|
@ -16,12 +16,12 @@ def serialize
|
||||
parts, sign = normalize
|
||||
return "PT0S".freeze if parts.empty?
|
||||
|
||||
output = "P".dup
|
||||
output = +"P"
|
||||
output << "#{parts[:years]}Y" if parts.key?(:years)
|
||||
output << "#{parts[:months]}M" if parts.key?(:months)
|
||||
output << "#{parts[:weeks]}W" if parts.key?(:weeks)
|
||||
output << "#{parts[:days]}D" if parts.key?(:days)
|
||||
time = "".dup
|
||||
time = +""
|
||||
time << "#{parts[:hours]}H" if parts.key?(:hours)
|
||||
time << "#{parts[:minutes]}M" if parts.key?(:minutes)
|
||||
if parts.key?(:seconds)
|
||||
|
@ -169,7 +169,7 @@ def texts(element)
|
||||
# element::
|
||||
# XML element to be checked.
|
||||
def empty_content?(element)
|
||||
text = "".dup
|
||||
text = +""
|
||||
child_nodes = element.child_nodes
|
||||
(0...child_nodes.length).each do |i|
|
||||
item = child_nodes.item(i)
|
||||
|
@ -55,7 +55,7 @@ def to_hash(hash = {})
|
||||
if c.element?
|
||||
c.to_hash(node_hash)
|
||||
elsif c.text? || c.cdata?
|
||||
node_hash[CONTENT_ROOT] ||= "".dup
|
||||
node_hash[CONTENT_ROOT] ||= +""
|
||||
node_hash[CONTENT_ROOT] << c.content
|
||||
end
|
||||
end
|
||||
|
@ -23,7 +23,7 @@ def current_hash
|
||||
end
|
||||
|
||||
def on_start_document
|
||||
@hash = { CONTENT_KEY => "".dup }
|
||||
@hash = { CONTENT_KEY => +"" }
|
||||
@hash_stack = [@hash]
|
||||
end
|
||||
|
||||
@ -33,7 +33,7 @@ def on_end_document
|
||||
end
|
||||
|
||||
def on_start_element(name, attrs = {})
|
||||
new_hash = { CONTENT_KEY => "".dup }.merge!(attrs)
|
||||
new_hash = { CONTENT_KEY => +"" }.merge!(attrs)
|
||||
new_hash[HASH_SIZE_KEY] = new_hash.size + 1
|
||||
|
||||
case current_hash[name]
|
||||
|
@ -59,7 +59,7 @@ def to_hash(hash = {})
|
||||
if c.element?
|
||||
c.to_hash(node_hash)
|
||||
elsif c.text? || c.cdata?
|
||||
node_hash[CONTENT_ROOT] ||= "".dup
|
||||
node_hash[CONTENT_ROOT] ||= +""
|
||||
node_hash[CONTENT_ROOT] << c.content
|
||||
end
|
||||
end
|
||||
|
@ -39,7 +39,7 @@ def error(error_message)
|
||||
end
|
||||
|
||||
def start_element(name, attrs = [])
|
||||
new_hash = { CONTENT_KEY => "".dup }.merge!(Hash[attrs])
|
||||
new_hash = { CONTENT_KEY => +"" }.merge!(Hash[attrs])
|
||||
new_hash[HASH_SIZE_KEY] = new_hash.size + 1
|
||||
|
||||
case current_hash[name]
|
||||
|
@ -76,7 +76,7 @@ def merge_texts!(hash, element)
|
||||
hash
|
||||
else
|
||||
# must use value to prevent double-escaping
|
||||
texts = "".dup
|
||||
texts = +""
|
||||
element.texts.each { |t| texts << t.value }
|
||||
merge!(hash, CONTENT_KEY, texts)
|
||||
end
|
||||
|
@ -319,7 +319,7 @@ def test_delete
|
||||
end
|
||||
|
||||
def test_original_store_objects_should_not_be_immutable
|
||||
bar = "bar".dup
|
||||
bar = +"bar"
|
||||
@cache.write("foo", bar)
|
||||
assert_nothing_raised { bar.gsub!(/.*/, "baz") }
|
||||
end
|
||||
|
@ -6,7 +6,7 @@
|
||||
module EncodedKeyCacheBehavior
|
||||
Encoding.list.each do |encoding|
|
||||
define_method "test_#{encoding.name.underscore}_encoded_values" do
|
||||
key = "foo".dup.force_encoding(encoding)
|
||||
key = (+"foo").force_encoding(encoding)
|
||||
assert @cache.write(key, "1", raw: true)
|
||||
assert_equal "1", @cache.read(key)
|
||||
assert_equal "1", @cache.fetch(key)
|
||||
@ -18,7 +18,7 @@ module EncodedKeyCacheBehavior
|
||||
end
|
||||
|
||||
def test_common_utf8_values
|
||||
key = "\xC3\xBCmlaut".dup.force_encoding(Encoding::UTF_8)
|
||||
key = (+"\xC3\xBCmlaut").force_encoding(Encoding::UTF_8)
|
||||
assert @cache.write(key, "1", raw: true)
|
||||
assert_equal "1", @cache.read(key)
|
||||
assert_equal "1", @cache.fetch(key)
|
||||
@ -29,7 +29,7 @@ def test_common_utf8_values
|
||||
end
|
||||
|
||||
def test_retains_encoding
|
||||
key = "\xC3\xBCmlaut".dup.force_encoding(Encoding::UTF_8)
|
||||
key = (+"\xC3\xBCmlaut").force_encoding(Encoding::UTF_8)
|
||||
assert @cache.write(key, "1", raw: true)
|
||||
assert_equal Encoding::UTF_8, key.encoding
|
||||
end
|
||||
|
4
activesupport/test/cache/cache_key_test.rb
vendored
4
activesupport/test/cache/cache_key_test.rb
vendored
@ -47,7 +47,7 @@ def test_expand_cache_key_rails_cache_id_should_win_over_rails_app_version
|
||||
end
|
||||
|
||||
def test_expand_cache_key_respond_to_cache_key
|
||||
key = "foo".dup
|
||||
key = +"foo"
|
||||
def key.cache_key
|
||||
:foo_key
|
||||
end
|
||||
@ -55,7 +55,7 @@ def key.cache_key
|
||||
end
|
||||
|
||||
def test_expand_cache_key_array_with_something_that_responds_to_cache_key
|
||||
key = "foo".dup
|
||||
key = +"foo"
|
||||
def key.cache_key
|
||||
:foo_key
|
||||
end
|
||||
|
@ -19,7 +19,7 @@ def test_instance_values
|
||||
end
|
||||
|
||||
def test_instance_exec_passes_arguments_to_block
|
||||
assert_equal %w(hello goodbye), "hello".dup.instance_exec("goodbye") { |v| [self, v] }
|
||||
assert_equal %w(hello goodbye), (+"hello").instance_exec("goodbye") { |v| [self, v] }
|
||||
end
|
||||
|
||||
def test_instance_exec_with_frozen_obj
|
||||
@ -27,7 +27,7 @@ def test_instance_exec_with_frozen_obj
|
||||
end
|
||||
|
||||
def test_instance_exec_nested
|
||||
assert_equal %w(goodbye olleh bar), "hello".dup.instance_exec("goodbye") { |arg|
|
||||
assert_equal %w(goodbye olleh bar), (+"hello").instance_exec("goodbye") { |arg|
|
||||
[arg] + instance_exec("bar") { |v| [reverse, v] } }
|
||||
end
|
||||
end
|
||||
|
@ -245,8 +245,8 @@ def test_starts_ends_with_alias
|
||||
end
|
||||
|
||||
def test_string_squish
|
||||
original = %{\u205f\u3000 A string surrounded by various unicode spaces,
|
||||
with tabs(\t\t), newlines(\n\n), unicode nextlines(\u0085\u0085) and many spaces( ). \u00a0\u2007}.dup
|
||||
original = +%{\u205f\u3000 A string surrounded by various unicode spaces,
|
||||
with tabs(\t\t), newlines(\n\n), unicode nextlines(\u0085\u0085) and many spaces( ). \u00a0\u2007}
|
||||
|
||||
expected = "A string surrounded by various unicode spaces, " \
|
||||
"with tabs( ), newlines( ), unicode nextlines( ) and many spaces( )."
|
||||
@ -378,8 +378,8 @@ def test_truncate_words_with_complex_string
|
||||
end
|
||||
|
||||
def test_truncate_multibyte
|
||||
assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".dup.force_encoding(Encoding::UTF_8),
|
||||
"\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".dup.force_encoding(Encoding::UTF_8).truncate(10)
|
||||
assert_equal (+"\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...").force_encoding(Encoding::UTF_8),
|
||||
(+"\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244").force_encoding(Encoding::UTF_8).truncate(10)
|
||||
end
|
||||
|
||||
def test_truncate_should_not_be_html_safe
|
||||
@ -400,7 +400,7 @@ def test_remove_for_multiple_occurrences
|
||||
end
|
||||
|
||||
def test_remove!
|
||||
original = "This is a very good day to die".dup
|
||||
original = +"This is a very good day to die"
|
||||
assert_equal "This is a good day to die", original.remove!(" very")
|
||||
assert_equal "This is a good day to die", original
|
||||
assert_equal "This is a good day", original.remove!(" to ", /die/)
|
||||
@ -733,7 +733,7 @@ def test_mb_chars_returns_instance_of_proxy_class
|
||||
|
||||
class OutputSafetyTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@string = "hello".dup
|
||||
@string = +"hello"
|
||||
@object = Class.new(Object) do
|
||||
def to_s
|
||||
"other"
|
||||
@ -809,7 +809,7 @@ def to_s
|
||||
end
|
||||
|
||||
test "Concatting safe onto unsafe yields unsafe" do
|
||||
@other_string = "other".dup
|
||||
@other_string = +"other"
|
||||
|
||||
string = @string.html_safe
|
||||
@other_string.concat(string)
|
||||
@ -832,7 +832,7 @@ def to_s
|
||||
end
|
||||
|
||||
test "Concatting safe onto unsafe with << yields unsafe" do
|
||||
@other_string = "other".dup
|
||||
@other_string = +"other"
|
||||
string = @string.html_safe
|
||||
|
||||
@other_string << string
|
||||
@ -888,7 +888,7 @@ def to_s
|
||||
test "Concatting an integer to safe always yields safe" do
|
||||
string = @string.html_safe
|
||||
string = string.concat(13)
|
||||
assert_equal "hello".dup.concat(13), string
|
||||
assert_equal (+"hello").concat(13), string
|
||||
assert_predicate string, :html_safe?
|
||||
end
|
||||
|
||||
|
@ -40,7 +40,7 @@ def test_write_binary_data_to_existing_file
|
||||
logger = Logger.new f
|
||||
logger.level = Logger::DEBUG
|
||||
|
||||
str = "\x80".dup
|
||||
str = +"\x80"
|
||||
str.force_encoding("ASCII-8BIT")
|
||||
|
||||
logger.add Logger::DEBUG, str
|
||||
@ -58,7 +58,7 @@ def test_write_binary_data_create_file
|
||||
logger = Logger.new f
|
||||
logger.level = Logger::DEBUG
|
||||
|
||||
str = "\x80".dup
|
||||
str = +"\x80"
|
||||
str.force_encoding("ASCII-8BIT")
|
||||
|
||||
logger.add Logger::DEBUG, str
|
||||
|
@ -53,7 +53,7 @@ def test_methods_are_forwarded_to_wrapped_string_for_byte_strings
|
||||
end
|
||||
|
||||
def test_forwarded_method_with_non_string_result_should_be_returned_verbatim
|
||||
str = "".dup
|
||||
str = +""
|
||||
str.singleton_class.class_eval { def __method_for_multibyte_testing_with_integer_result; 1; end }
|
||||
@chars.wrapped_string.singleton_class.class_eval { def __method_for_multibyte_testing_with_integer_result; 1; end }
|
||||
|
||||
@ -61,14 +61,14 @@ def test_forwarded_method_with_non_string_result_should_be_returned_verbatim
|
||||
end
|
||||
|
||||
def test_should_concatenate
|
||||
mb_a = "a".dup.mb_chars
|
||||
mb_b = "b".dup.mb_chars
|
||||
mb_a = (+"a").mb_chars
|
||||
mb_b = (+"b").mb_chars
|
||||
assert_equal "ab", mb_a + "b"
|
||||
assert_equal "ab", "a" + mb_b
|
||||
assert_equal "ab", mb_a + mb_b
|
||||
|
||||
assert_equal "ab", mb_a << "b"
|
||||
assert_equal "ab", "a".dup << mb_b
|
||||
assert_equal "ab", (+"a") << mb_b
|
||||
assert_equal "abb", mb_a << mb_b
|
||||
end
|
||||
|
||||
@ -80,7 +80,7 @@ def test_consumes_utf8_strings
|
||||
|
||||
def test_concatenation_should_return_a_proxy_class_instance
|
||||
assert_equal ActiveSupport::Multibyte.proxy_class, ("a".mb_chars + "b").class
|
||||
assert_equal ActiveSupport::Multibyte.proxy_class, ("a".dup.mb_chars << "b").class
|
||||
assert_equal ActiveSupport::Multibyte.proxy_class, ((+"a").mb_chars << "b").class
|
||||
end
|
||||
|
||||
def test_ascii_strings_are_treated_at_utf8_strings
|
||||
@ -90,8 +90,8 @@ def test_ascii_strings_are_treated_at_utf8_strings
|
||||
def test_concatenate_should_return_proxy_instance
|
||||
assert(("a".mb_chars + "b").kind_of?(@proxy_class))
|
||||
assert(("a".mb_chars + "b".mb_chars).kind_of?(@proxy_class))
|
||||
assert(("a".dup.mb_chars << "b").kind_of?(@proxy_class))
|
||||
assert(("a".dup.mb_chars << "b".mb_chars).kind_of?(@proxy_class))
|
||||
assert(((+"a").mb_chars << "b").kind_of?(@proxy_class))
|
||||
assert(((+"a").mb_chars << "b".mb_chars).kind_of?(@proxy_class))
|
||||
end
|
||||
|
||||
def test_should_return_string_as_json
|
||||
@ -135,7 +135,7 @@ def test_tidy_bytes_bang_should_return_self
|
||||
end
|
||||
|
||||
def test_tidy_bytes_bang_should_change_wrapped_string
|
||||
original = " Un bUen café \x92".dup
|
||||
original = +" Un bUen café \x92"
|
||||
proxy = chars(original.dup)
|
||||
proxy.tidy_bytes!
|
||||
assert_not_equal original, proxy.to_s
|
||||
@ -152,7 +152,7 @@ def test_identity
|
||||
end
|
||||
|
||||
def test_string_methods_are_chainable
|
||||
assert chars("".dup).insert(0, "").kind_of?(ActiveSupport::Multibyte.proxy_class)
|
||||
assert chars(+"").insert(0, "").kind_of?(ActiveSupport::Multibyte.proxy_class)
|
||||
assert chars("").rjust(1).kind_of?(ActiveSupport::Multibyte.proxy_class)
|
||||
assert chars("").ljust(1).kind_of?(ActiveSupport::Multibyte.proxy_class)
|
||||
assert chars("").center(1).kind_of?(ActiveSupport::Multibyte.proxy_class)
|
||||
@ -197,7 +197,7 @@ def test_should_return_character_offset_for_regexp_matches
|
||||
end
|
||||
|
||||
def test_should_use_character_offsets_for_insert_offsets
|
||||
assert_equal "", "".dup.mb_chars.insert(0, "")
|
||||
assert_equal "", (+"").mb_chars.insert(0, "")
|
||||
assert_equal "こわにちわ", @chars.insert(1, "わ")
|
||||
assert_equal "こわわわにちわ", @chars.insert(2, "わわ")
|
||||
assert_equal "わこわわわにちわ", @chars.insert(0, "わ")
|
||||
@ -420,13 +420,13 @@ def test_slice_bang_returns_nil_on_out_of_bound_arguments
|
||||
end
|
||||
|
||||
def test_slice_bang_removes_the_slice_from_the_receiver
|
||||
chars = "úüù".dup.mb_chars
|
||||
chars = (+"úüù").mb_chars
|
||||
chars.slice!(0, 2)
|
||||
assert_equal "ù", chars
|
||||
end
|
||||
|
||||
def test_slice_bang_returns_nil_and_does_not_modify_receiver_if_out_of_bounds
|
||||
string = "úüù".dup
|
||||
string = +"úüù"
|
||||
chars = string.mb_chars
|
||||
assert_nil chars.slice!(4, 5)
|
||||
assert_equal "úüù", chars
|
||||
|
@ -29,7 +29,7 @@ def self.download(from, to)
|
||||
|
||||
UNICODE_STRING = "こにちわ".freeze
|
||||
ASCII_STRING = "ohayo".freeze
|
||||
BYTE_STRING = "\270\236\010\210\245".dup.force_encoding("ASCII-8BIT").freeze
|
||||
BYTE_STRING = (+"\270\236\010\210\245").force_encoding("ASCII-8BIT").freeze
|
||||
|
||||
def chars(str)
|
||||
ActiveSupport::Multibyte::Chars.new(str)
|
||||
|
@ -75,7 +75,7 @@ def start
|
||||
args += ["-P", "#{config['password']}"] if config["password"]
|
||||
|
||||
if config["host"]
|
||||
host_arg = "#{config['host']}".dup
|
||||
host_arg = +"#{config['host']}"
|
||||
host_arg << ":#{config['port']}" if config["port"]
|
||||
args += ["-S", host_arg]
|
||||
end
|
||||
|
@ -153,7 +153,7 @@ def token?
|
||||
end
|
||||
|
||||
def inject_options
|
||||
"".dup.tap { |s| options_for_migration.each { |k, v| s << ", #{k}: #{v.inspect}" } }
|
||||
(+"").tap { |s| options_for_migration.each { |k, v| s << ", #{k}: #{v.inspect}" } }
|
||||
end
|
||||
|
||||
def inject_index_options
|
||||
|
@ -41,7 +41,7 @@ def to_s
|
||||
alias inspect to_s
|
||||
|
||||
def to_html
|
||||
"<table>".dup.tap do |table|
|
||||
(+"<table>").tap do |table|
|
||||
properties.each do |(name, value)|
|
||||
table << %(<tr><td class="name">#{CGI.escapeHTML(name.to_s)}</td>)
|
||||
formatted_value = if value.kind_of?(Array)
|
||||
|
@ -50,7 +50,7 @@ def self.register_extensions(*exts, &block)
|
||||
# If +options+ has a flag <tt>:tag</tt> the tag is shown as in the example above.
|
||||
# Otherwise the string contains just line and text.
|
||||
def to_s(options = {})
|
||||
s = "[#{line.to_s.rjust(options[:indent])}] ".dup
|
||||
s = +"[#{line.to_s.rjust(options[:indent])}] "
|
||||
s << "[#{tag}] " if options[:tag]
|
||||
s << text
|
||||
end
|
||||
|
@ -9,7 +9,7 @@ module ConsoleHelpers
|
||||
def assert_output(expected, io, timeout = 10)
|
||||
timeout = Time.now + timeout
|
||||
|
||||
output = "".dup
|
||||
output = +""
|
||||
until output.include?(expected) || Time.now > timeout
|
||||
if IO.select([io], [], [], 0.1)
|
||||
output << io.read(1)
|
||||
|
@ -964,7 +964,7 @@ def test_psych_gem
|
||||
|
||||
def test_after_bundle_callback
|
||||
path = "http://example.org/rails_template"
|
||||
template = %{ after_bundle { run 'echo ran after_bundle' } }.dup
|
||||
template = +%{ after_bundle { run 'echo ran after_bundle' } }
|
||||
template.instance_eval "def read; self; end" # Make the string respond to read
|
||||
|
||||
check_open = -> *args do
|
||||
|
@ -737,7 +737,7 @@ def test_app_update_generates_bin_file
|
||||
|
||||
def test_after_bundle_callback
|
||||
path = "http://example.org/rails_template"
|
||||
template = %{ after_bundle { run "echo ran after_bundle" } }.dup
|
||||
template = +%{ after_bundle { run "echo ran after_bundle" } }
|
||||
template.instance_eval "def read; self; end" # Make the string respond to read
|
||||
|
||||
check_open = -> *args do
|
||||
|
@ -83,7 +83,7 @@ def test_template_raises_an_error_with_invalid_path
|
||||
|
||||
def test_template_is_executed_when_supplied_an_https_path
|
||||
path = "https://gist.github.com/josevalim/103208/raw/"
|
||||
template = %{ say "It works!" }.dup
|
||||
template = +%{ say "It works!" }
|
||||
template.instance_eval "def read; self; end" # Make the string respond to read
|
||||
|
||||
check_open = -> *args do
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user