diff options
729 files changed, 2731 insertions, 1363 deletions
diff --git a/.rubocop.yml b/.rubocop.yml index 8a0c55d5d4..9b5044a6fc 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -77,6 +77,12 @@ Layout/SpaceBeforeFirstArg: Style/MethodDefParentheses: Enabled: true +Style/FrozenStringLiteralComment: + Enabled: true + EnforcedStyle: always + Include: + - 'activesupport/**/*' + # Use `foo {}` not `foo{}`. Layout/SpaceBeforeBlockBraces: Enabled: true @@ -11,6 +11,7 @@ gem "arel", github: "rails/arel" # We need a newish Rake since Active Job sets its test tasks' descriptions. gem "rake", ">= 11.1" +gem "thor", github: "erikhuda/thor" # This needs to be with require false to ensure correct loading order, as it has to # be loaded after loading the test library. diff --git a/Gemfile.lock b/Gemfile.lock index 9f636b0307..f06b9a32f2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,6 +7,12 @@ GIT pg (>= 0.17, < 0.20) GIT + remote: https://github.com/erikhuda/thor.git + revision: df5ba2b653a28087b3617d6c082b00866b0c0d6c + specs: + thor (0.19.4) + +GIT remote: https://github.com/matthewd/websocket-client-simple.git revision: e161305f1a466b9398d86df3b1731b03362da91b branch: close-race @@ -70,7 +76,7 @@ PATH activemodel (= 5.2.0.alpha) activerecord (= 5.2.0.alpha) activesupport (= 5.2.0.alpha) - bundler (>= 1.3.0, < 2.0) + bundler (>= 1.3.0) railties (= 5.2.0.alpha) sprockets-rails (>= 2.0.0) railties (5.2.0.alpha) @@ -336,7 +342,6 @@ GEM daemons (~> 1.0, >= 1.0.9) eventmachine (~> 1.0, >= 1.0.4) rack (>= 1, < 3) - thor (0.19.4) thread (0.1.7) thread_safe (0.3.6) tilt (2.0.5) @@ -421,6 +426,7 @@ DEPENDENCIES sqlite3 (~> 1.3.6) stackprof sucker_punch + thor! turbolinks (~> 5) tzinfo-data uglifier (>= 1.3.0) diff --git a/actioncable/CHANGELOG.md b/actioncable/CHANGELOG.md index b1408496a0..fbe9863af7 100644 --- a/actioncable/CHANGELOG.md +++ b/actioncable/CHANGELOG.md @@ -1,3 +1,12 @@ +* Hash long stream identifiers when using Postgres adapter. + + PostgreSQL has a limit on identifiers length (63 chars, [docs](https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS)). + Provided fix minifies identifiers longer than 63 chars by hashing them with SHA1. + + Fixes #28751. + + *Vladimir Dementyev* + * ActionCable's `redis` adapter allows for other common redis-rb options (`host`, `port`, `db`, `password`) in cable.yml. Previously, it accepts only a [redis:// url](https://www.iana.org/assignments/uri-schemes/prov/redis) as an option. diff --git a/actioncable/lib/action_cable.rb b/actioncable/lib/action_cable.rb index c2d3550acb..9edd82e7b5 100644 --- a/actioncable/lib/action_cable.rb +++ b/actioncable/lib/action_cable.rb @@ -23,7 +23,7 @@ require "active_support" require "active_support/rails" -require "action_cable/version" +require_relative "action_cable/version" module ActionCable extend ActiveSupport::Autoload diff --git a/actioncable/lib/action_cable/engine.rb b/actioncable/lib/action_cable/engine.rb index 63a26636a0..d8c49ec6e1 100644 --- a/actioncable/lib/action_cable/engine.rb +++ b/actioncable/lib/action_cable/engine.rb @@ -1,6 +1,6 @@ require "rails" require "action_cable" -require "action_cable/helpers/action_cable_helper" +require_relative "helpers/action_cable_helper" require "active_support/core_ext/hash/indifferent_access" module ActionCable diff --git a/actioncable/lib/action_cable/subscription_adapter/async.rb b/actioncable/lib/action_cable/subscription_adapter/async.rb index 46819dbfec..9169734471 100644 --- a/actioncable/lib/action_cable/subscription_adapter/async.rb +++ b/actioncable/lib/action_cable/subscription_adapter/async.rb @@ -1,4 +1,4 @@ -require "action_cable/subscription_adapter/inline" +require_relative "inline" module ActionCable module SubscriptionAdapter diff --git a/actioncable/lib/action_cable/subscription_adapter/postgresql.rb b/actioncable/lib/action_cable/subscription_adapter/postgresql.rb index bdab5205ec..487564c46c 100644 --- a/actioncable/lib/action_cable/subscription_adapter/postgresql.rb +++ b/actioncable/lib/action_cable/subscription_adapter/postgresql.rb @@ -1,6 +1,7 @@ gem "pg", "~> 0.18" require "pg" require "thread" +require "digest/sha1" module ActionCable module SubscriptionAdapter @@ -12,16 +13,16 @@ module ActionCable def broadcast(channel, payload) with_connection do |pg_conn| - pg_conn.exec("NOTIFY #{pg_conn.escape_identifier(channel)}, '#{pg_conn.escape_string(payload)}'") + pg_conn.exec("NOTIFY #{pg_conn.escape_identifier(channel_identifier(channel))}, '#{pg_conn.escape_string(payload)}'") end end def subscribe(channel, callback, success_callback = nil) - listener.add_subscriber(channel, callback, success_callback) + listener.add_subscriber(channel_identifier(channel), callback, success_callback) end def unsubscribe(channel, callback) - listener.remove_subscriber(channel, callback) + listener.remove_subscriber(channel_identifier(channel), callback) end def shutdown @@ -41,6 +42,10 @@ module ActionCable end private + def channel_identifier(channel) + channel.size > 63 ? Digest::SHA1.hexdigest(channel) : channel + end + def listener @listener || @server.mutex.synchronize { @listener ||= Listener.new(self, @server.event_loop) } end diff --git a/actioncable/test/subscription_adapter/base_test.rb b/actioncable/test/subscription_adapter/base_test.rb index 212ea49d2f..5793415b5f 100644 --- a/actioncable/test/subscription_adapter/base_test.rb +++ b/actioncable/test/subscription_adapter/base_test.rb @@ -39,35 +39,25 @@ class ActionCable::SubscriptionAdapter::BaseTest < ActionCable::TestCase # TEST METHODS THAT ARE REQUIRED OF THE ADAPTER'S BACKEND STORAGE OBJECT test "#broadcast is implemented" do - broadcast = SuccessAdapter.new(@server).broadcast("channel", "payload") - - assert_respond_to(SuccessAdapter.new(@server), :broadcast) - assert_nothing_raised do - broadcast + SuccessAdapter.new(@server).broadcast("channel", "payload") end end test "#subscribe is implemented" do callback = lambda { puts "callback" } success_callback = lambda { puts "success" } - subscribe = SuccessAdapter.new(@server).subscribe("channel", callback, success_callback) - - assert_respond_to(SuccessAdapter.new(@server), :subscribe) assert_nothing_raised do - subscribe + SuccessAdapter.new(@server).subscribe("channel", callback, success_callback) end end test "#unsubscribe is implemented" do callback = lambda { puts "callback" } - unsubscribe = SuccessAdapter.new(@server).unsubscribe("channel", callback) - - assert_respond_to(SuccessAdapter.new(@server), :unsubscribe) assert_nothing_raised do - unsubscribe + SuccessAdapter.new(@server).unsubscribe("channel", callback) end end end diff --git a/actioncable/test/subscription_adapter/common.rb b/actioncable/test/subscription_adapter/common.rb index 3aa88c2caa..80baf2f771 100644 --- a/actioncable/test/subscription_adapter/common.rb +++ b/actioncable/test/subscription_adapter/common.rb @@ -112,4 +112,18 @@ module CommonSubscriptionAdapterTest assert_equal "two", queue.pop end end + + def test_long_identifiers + channel_1 = "a" * 100 + "1" + channel_2 = "a" * 100 + "2" + subscribe_as_queue(channel_1) do |queue| + subscribe_as_queue(channel_2) do |queue_2| + @tx_adapter.broadcast(channel_1, "apples") + @tx_adapter.broadcast(channel_2, "oranges") + + assert_equal "apples", queue.pop + assert_equal "oranges", queue_2.pop + end + end + end end diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index 8e59f033d0..8eba811ab6 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -22,7 +22,7 @@ #++ require "abstract_controller" -require "action_mailer/version" +require_relative "action_mailer/version" # Common Active Support usage in Action Mailer require "active_support" diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index f8aa54bd44..2b4992791d 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -1,11 +1,11 @@ require "mail" -require "action_mailer/collector" +require_relative "collector" require "active_support/core_ext/string/inflections" require "active_support/core_ext/hash/except" require "active_support/core_ext/module/anonymous" -require "action_mailer/log_subscriber" -require "action_mailer/rescuable" +require_relative "log_subscriber" +require_relative "rescuable" module ActionMailer # Action Mailer allows you to send email from your application using a mailer model and views. diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index ebb97078e6..06d4ea197c 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -120,7 +120,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" + expected = "\312\213\254\232)b".dup expected.force_encoding(Encoding::BINARY) assert_equal expected, email.attachments["invoice.jpg"].decoded end @@ -129,7 +129,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" + expected = "\312\213\254\232)b".dup expected.force_encoding(Encoding::BINARY) assert_equal expected, email.attachments["invoice.jpg"].decoded end diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb index dc79820a82..bca850c0c0 100644 --- a/actionpack/lib/abstract_controller/base.rb +++ b/actionpack/lib/abstract_controller/base.rb @@ -1,4 +1,4 @@ -require "abstract_controller/error" +require_relative "error" require "active_support/configurable" require "active_support/descendants_tracker" require "active_support/core_ext/module/anonymous" diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 54af938a93..1c87739d42 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -1,4 +1,4 @@ -require "abstract_controller/error" +require_relative "error" require "action_view" require "action_view/view_paths" require "set" diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index 50f20aa789..4e2d67954f 100644 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -1,8 +1,8 @@ require "active_support/rails" require "abstract_controller" require "action_dispatch" -require "action_controller/metal/live" -require "action_controller/metal/strong_parameters" +require_relative "action_controller/metal/live" +require_relative "action_controller/metal/strong_parameters" module ActionController extend ActiveSupport::Autoload diff --git a/actionpack/lib/action_controller/api.rb b/actionpack/lib/action_controller/api.rb index 94698df730..2bfa65021d 100644 --- a/actionpack/lib/action_controller/api.rb +++ b/actionpack/lib/action_controller/api.rb @@ -1,6 +1,6 @@ require "action_view" require "action_controller" -require "action_controller/log_subscriber" +require_relative "log_subscriber" module ActionController # API Controller is a lightweight version of <tt>ActionController::Base</tt>, diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 8c2b111f89..6e195fa359 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -1,6 +1,6 @@ require "action_view" -require "action_controller/log_subscriber" -require "action_controller/metal/params_wrapper" +require_relative "log_subscriber" +require_relative "metal/params_wrapper" module ActionController # Action Controllers are the core of a web request in \Rails. They are made up of one or more actions that are executed diff --git a/actionpack/lib/action_controller/log_subscriber.rb b/actionpack/lib/action_controller/log_subscriber.rb index d00fcbcd13..5d75393897 100644 --- a/actionpack/lib/action_controller/log_subscriber.rb +++ b/actionpack/lib/action_controller/log_subscriber.rb @@ -24,7 +24,7 @@ module ActionController 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" + message = "Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in #{event.duration.round}ms".dup message << " (#{additions.join(" | ".freeze)})" unless additions.empty? message << "\n\n" if defined?(Rails.env) && Rails.env.development? diff --git a/actionpack/lib/action_controller/metal/data_streaming.rb b/actionpack/lib/action_controller/metal/data_streaming.rb index 731e03e2fc..3dbdd4a1b6 100644 --- a/actionpack/lib/action_controller/metal/data_streaming.rb +++ b/actionpack/lib/action_controller/metal/data_streaming.rb @@ -1,4 +1,4 @@ -require "action_controller/metal/exceptions" +require_relative "exceptions" module ActionController #:nodoc: # Methods for sending arbitrary data and for streaming files to the browser, diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index 44151c9f71..818af549eb 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -232,12 +232,7 @@ module ActionController # by the metal call stack. def process_action(*args) if _wrapper_enabled? - if request.parameters[_wrapper_key].present? - wrapped_hash = _extract_parameters(request.parameters) - else - wrapped_hash = _wrap_parameters request.request_parameters - end - + wrapped_hash = _wrap_parameters request.request_parameters wrapped_keys = request.request_parameters.keys wrapped_filtered_hash = _wrap_parameters request.filtered_parameters.slice(*wrapped_keys) @@ -282,7 +277,7 @@ module ActionController return false unless request.has_content_type? ref = request.content_mime_type.ref - _wrapper_formats.include?(ref) && _wrapper_key && !request.request_parameters.key?(_wrapper_key) + _wrapper_formats.include?(ref) && _wrapper_key && !request.parameters.key?(_wrapper_key) end end end diff --git a/actionpack/lib/action_controller/metal/request_forgery_protection.rb b/actionpack/lib/action_controller/metal/request_forgery_protection.rb index 5051c02a62..4468cbb2fc 100644 --- a/actionpack/lib/action_controller/metal/request_forgery_protection.rb +++ b/actionpack/lib/action_controller/metal/request_forgery_protection.rb @@ -1,5 +1,5 @@ require "rack/session/abstract/id" -require "action_controller/metal/exceptions" +require_relative "exceptions" require "active_support/security_utils" module ActionController #:nodoc: diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index fadfc8de60..31db7518f1 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -2,7 +2,7 @@ require "rails" require "action_controller" require "action_dispatch/railtie" require "abstract_controller/railties/routes_helpers" -require "action_controller/railties/helpers" +require_relative "railties/helpers" require "action_view/railtie" module ActionController @@ -22,13 +22,15 @@ module ActionController initializer "action_controller.parameters_config" do |app| options = app.config.action_controller - ActionController::Parameters.permit_all_parameters = options.delete(:permit_all_parameters) { false } - if app.config.action_controller[:always_permitted_parameters] - ActionController::Parameters.always_permitted_parameters = - app.config.action_controller.delete(:always_permitted_parameters) - end - ActionController::Parameters.action_on_unpermitted_parameters = options.delete(:action_on_unpermitted_parameters) do - (Rails.env.test? || Rails.env.development?) ? :log : false + ActiveSupport.on_load(:action_controller) do + ActionController::Parameters.permit_all_parameters = options.delete(:permit_all_parameters) { false } + if app.config.action_controller[:always_permitted_parameters] + ActionController::Parameters.always_permitted_parameters = + app.config.action_controller.delete(:always_permitted_parameters) + end + ActionController::Parameters.action_on_unpermitted_parameters = options.delete(:action_on_unpermitted_parameters) do + (Rails.env.test? || Rails.env.development?) ? :log : false + end end end diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index bc42d50205..9d8240e46d 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -4,7 +4,7 @@ require "active_support/core_ext/object/to_query" require "active_support/core_ext/module/anonymous" require "active_support/core_ext/hash/keys" require "active_support/testing/constant_lookup" -require "action_controller/template_assertions" +require_relative "template_assertions" require "rails-dom-testing" module ActionController diff --git a/actionpack/lib/action_dispatch/http/filter_parameters.rb b/actionpack/lib/action_dispatch/http/filter_parameters.rb index 077ab2561f..eb6761d067 100644 --- a/actionpack/lib/action_dispatch/http/filter_parameters.rb +++ b/actionpack/lib/action_dispatch/http/filter_parameters.rb @@ -1,4 +1,4 @@ -require "action_dispatch/http/parameter_filter" +require_relative "parameter_filter" module ActionDispatch module Http diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb index 74a3afab44..5a0f661d99 100644 --- a/actionpack/lib/action_dispatch/http/mime_type.rb +++ b/actionpack/lib/action_dispatch/http/mime_type.rb @@ -337,4 +337,4 @@ module Mime end end -require "action_dispatch/http/mime_types" +require_relative "mime_types" diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index 6d42404a98..914163f219 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -1,15 +1,16 @@ +# frozen_string_literal: true require "stringio" require "active_support/inflector" -require "action_dispatch/http/headers" +require_relative "headers" require "action_controller/metal/exceptions" require "rack/request" -require "action_dispatch/http/cache" -require "action_dispatch/http/mime_negotiation" -require "action_dispatch/http/parameters" -require "action_dispatch/http/filter_parameters" -require "action_dispatch/http/upload" -require "action_dispatch/http/url" +require_relative "cache" +require_relative "mime_negotiation" +require_relative "parameters" +require_relative "filter_parameters" +require_relative "upload" +require_relative "url" require "active_support/core_ext/array/conversions" module ActionDispatch diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 3c91677d55..eab663e2e0 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -1,6 +1,6 @@ require "active_support/core_ext/module/attribute_accessors" -require "action_dispatch/http/filter_redirect" -require "action_dispatch/http/cache" +require_relative "filter_redirect" +require_relative "cache" require "monitor" module ActionDispatch # :nodoc: @@ -103,7 +103,7 @@ module ActionDispatch # :nodoc: def body @str_body ||= begin - buf = "" + buf = "".dup each { |chunk| buf << chunk } buf end diff --git a/actionpack/lib/action_dispatch/http/url.rb b/actionpack/lib/action_dispatch/http/url.rb index f902fe36e0..28672e2a1a 100644 --- a/actionpack/lib/action_dispatch/http/url.rb +++ b/actionpack/lib/action_dispatch/http/url.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "active_support/core_ext/module/attribute_accessors" module ActionDispatch @@ -155,7 +156,7 @@ module ActionDispatch subdomain = options.fetch :subdomain, true domain = options[:domain] - host = "" + host = "".dup if subdomain == true return _host if domain.nil? diff --git a/actionpack/lib/action_dispatch/journey.rb b/actionpack/lib/action_dispatch/journey.rb index d1cfc51f3e..222cbf4584 100644 --- a/actionpack/lib/action_dispatch/journey.rb +++ b/actionpack/lib/action_dispatch/journey.rb @@ -1,5 +1,5 @@ -require "action_dispatch/journey/router" -require "action_dispatch/journey/gtg/builder" -require "action_dispatch/journey/gtg/simulator" -require "action_dispatch/journey/nfa/builder" -require "action_dispatch/journey/nfa/simulator" +require_relative "journey/router" +require_relative "journey/gtg/builder" +require_relative "journey/gtg/simulator" +require_relative "journey/nfa/builder" +require_relative "journey/nfa/simulator" diff --git a/actionpack/lib/action_dispatch/journey/formatter.rb b/actionpack/lib/action_dispatch/journey/formatter.rb index 326f4e52f9..119811d8ea 100644 --- a/actionpack/lib/action_dispatch/journey/formatter.rb +++ b/actionpack/lib/action_dispatch/journey/formatter.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "action_controller/metal/exceptions" module ActionDispatch @@ -48,7 +49,7 @@ module ActionDispatch 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}" + message = "No route matches #{Hash[constraints.sort_by { |k, v| k.to_s }].inspect}".dup 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? diff --git a/actionpack/lib/action_dispatch/journey/gtg/builder.rb b/actionpack/lib/action_dispatch/journey/gtg/builder.rb index 0f8bed89bf..b1132ef17c 100644 --- a/actionpack/lib/action_dispatch/journey/gtg/builder.rb +++ b/actionpack/lib/action_dispatch/journey/gtg/builder.rb @@ -1,4 +1,4 @@ -require "action_dispatch/journey/gtg/transition_table" +require_relative "transition_table" module ActionDispatch module Journey # :nodoc: diff --git a/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb b/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb index 45aff287b1..278e4f0e11 100644 --- a/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb +++ b/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb @@ -1,4 +1,4 @@ -require "action_dispatch/journey/nfa/dot" +require_relative "../nfa/dot" module ActionDispatch module Journey # :nodoc: diff --git a/actionpack/lib/action_dispatch/journey/nfa/builder.rb b/actionpack/lib/action_dispatch/journey/nfa/builder.rb index 532f765094..5b628d8cef 100644 --- a/actionpack/lib/action_dispatch/journey/nfa/builder.rb +++ b/actionpack/lib/action_dispatch/journey/nfa/builder.rb @@ -1,5 +1,5 @@ -require "action_dispatch/journey/nfa/transition_table" -require "action_dispatch/journey/gtg/transition_table" +require_relative "transition_table" +require_relative "../gtg/transition_table" module ActionDispatch module Journey # :nodoc: diff --git a/actionpack/lib/action_dispatch/journey/nfa/transition_table.rb b/actionpack/lib/action_dispatch/journey/nfa/transition_table.rb index 543a670da0..d18243545b 100644 --- a/actionpack/lib/action_dispatch/journey/nfa/transition_table.rb +++ b/actionpack/lib/action_dispatch/journey/nfa/transition_table.rb @@ -1,4 +1,4 @@ -require "action_dispatch/journey/nfa/dot" +require_relative "dot" module ActionDispatch module Journey # :nodoc: diff --git a/actionpack/lib/action_dispatch/journey/nodes/node.rb b/actionpack/lib/action_dispatch/journey/nodes/node.rb index 0d874a84c9..97acad6995 100644 --- a/actionpack/lib/action_dispatch/journey/nodes/node.rb +++ b/actionpack/lib/action_dispatch/journey/nodes/node.rb @@ -1,4 +1,4 @@ -require "action_dispatch/journey/visitors" +require_relative "../visitors" module ActionDispatch module Journey # :nodoc: diff --git a/actionpack/lib/action_dispatch/journey/parser.rb b/actionpack/lib/action_dispatch/journey/parser.rb index e002755bcf..6ddfe96098 100644 --- a/actionpack/lib/action_dispatch/journey/parser.rb +++ b/actionpack/lib/action_dispatch/journey/parser.rb @@ -8,7 +8,7 @@ require 'racc/parser.rb' # :stopdoc: -require "action_dispatch/journey/parser_extras" +require_relative "parser_extras" module ActionDispatch module Journey class Parser < Racc::Parser diff --git a/actionpack/lib/action_dispatch/journey/parser.y b/actionpack/lib/action_dispatch/journey/parser.y index f9b1a7a958..850c84ea1a 100644 --- a/actionpack/lib/action_dispatch/journey/parser.y +++ b/actionpack/lib/action_dispatch/journey/parser.y @@ -47,4 +47,4 @@ end ---- header # :stopdoc: -require "action_dispatch/journey/parser_extras" +require_relative "parser_extras" diff --git a/actionpack/lib/action_dispatch/journey/parser_extras.rb b/actionpack/lib/action_dispatch/journey/parser_extras.rb index 4c7e82d93c..d26f0e121f 100644 --- a/actionpack/lib/action_dispatch/journey/parser_extras.rb +++ b/actionpack/lib/action_dispatch/journey/parser_extras.rb @@ -1,5 +1,5 @@ -require "action_dispatch/journey/scanner" -require "action_dispatch/journey/nodes/node" +require_relative "scanner" +require_relative "nodes/node" module ActionDispatch # :stopdoc: diff --git a/actionpack/lib/action_dispatch/journey/router.rb b/actionpack/lib/action_dispatch/journey/router.rb index d55e1399e4..85f4aade55 100644 --- a/actionpack/lib/action_dispatch/journey/router.rb +++ b/actionpack/lib/action_dispatch/journey/router.rb @@ -1,14 +1,14 @@ -require "action_dispatch/journey/router/utils" -require "action_dispatch/journey/routes" -require "action_dispatch/journey/formatter" +require_relative "router/utils" +require_relative "routes" +require_relative "formatter" before = $-w $-w = false -require "action_dispatch/journey/parser" +require_relative "parser" $-w = before -require "action_dispatch/journey/route" -require "action_dispatch/journey/path/pattern" +require_relative "route" +require_relative "path/pattern" module ActionDispatch module Journey # :nodoc: diff --git a/actionpack/lib/action_dispatch/journey/router/utils.rb b/actionpack/lib/action_dispatch/journey/router/utils.rb index 6d400f3364..1ac86d10d6 100644 --- a/actionpack/lib/action_dispatch/journey/router/utils.rb +++ b/actionpack/lib/action_dispatch/journey/router/utils.rb @@ -14,11 +14,11 @@ module ActionDispatch # normalize_path("/%ab") # => "/%AB" def self.normalize_path(path) encoding = path.encoding - path = "/#{path}" + path = "/#{path}".dup path.squeeze!("/".freeze) path.sub!(%r{/+\Z}, "".freeze) path.gsub!(/(%[a-f0-9]{2})/) { $1.upcase } - path = "/" if path == "".freeze + path = "/".dup if path == "".freeze path.force_encoding(encoding) path end @@ -29,7 +29,7 @@ module ActionDispatch ENCODE = "%%%02X".freeze US_ASCII = Encoding::US_ASCII UTF_8 = Encoding::UTF_8 - EMPTY = "".force_encoding(US_ASCII).freeze + EMPTY = "".dup.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 diff --git a/actionpack/lib/action_dispatch/journey/visitors.rb b/actionpack/lib/action_dispatch/journey/visitors.rb index 335797f4b9..12b96afb24 100644 --- a/actionpack/lib/action_dispatch/journey/visitors.rb +++ b/actionpack/lib/action_dispatch/journey/visitors.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActionDispatch # :stopdoc: module Journey @@ -175,7 +176,7 @@ module ActionDispatch last_child = node.children.last node.children.inject(seed) { |s, c| string = visit(c, s) - string << "|".freeze unless last_child == c + string << "|" unless last_child == c string } end @@ -185,7 +186,7 @@ module ActionDispatch end def visit_GROUP(node, seed) - visit(node.left, seed << "(".freeze) << ")".freeze + visit(node.left, seed.dup << "(") << ")" end INSTANCE = new diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb index 336a775880..18852b0a57 100644 --- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb @@ -1,6 +1,7 @@ -require "action_dispatch/http/request" -require "action_dispatch/middleware/exception_wrapper" -require "action_dispatch/routing/inspector" +# frozen_string_literal: true +require_relative "../http/request" +require_relative "exception_wrapper" +require_relative "../routing/inspector" require "action_view" require "action_view/base" @@ -21,7 +22,7 @@ module ActionDispatch if clean_params.empty? "None" else - PP.pp(clean_params, "", 200) + PP.pp(clean_params, "".dup, 200) end end diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb index 21ccf5a097..31979fa576 100644 --- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb @@ -1,8 +1,8 @@ require "rack/utils" require "rack/request" require "rack/session/abstract/id" -require "action_dispatch/middleware/cookies" -require "action_dispatch/request/session" +require_relative "../cookies" +require_relative "../../request/session" module ActionDispatch module Session diff --git a/actionpack/lib/action_dispatch/middleware/session/cache_store.rb b/actionpack/lib/action_dispatch/middleware/session/cache_store.rb index 71274bc13a..4babeb6354 100644 --- a/actionpack/lib/action_dispatch/middleware/session/cache_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/cache_store.rb @@ -1,4 +1,4 @@ -require "action_dispatch/middleware/session/abstract_store" +require_relative "abstract_store" module ActionDispatch module Session diff --git a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb index 57d325a9d8..496f221617 100644 --- a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb @@ -1,5 +1,5 @@ require "active_support/core_ext/hash/keys" -require "action_dispatch/middleware/session/abstract_store" +require_relative "abstract_store" require "rack/session/cookie" module ActionDispatch diff --git a/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb b/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb index ee2b1f26ad..bc2b1c9b12 100644 --- a/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb @@ -1,4 +1,4 @@ -require "action_dispatch/middleware/session/abstract_store" +require_relative "abstract_store" begin require "rack/session/dalli" rescue LoadError => e diff --git a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb index 5a99714ec2..db84ff48e9 100644 --- a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb @@ -1,5 +1,5 @@ -require "action_dispatch/http/request" -require "action_dispatch/middleware/exception_wrapper" +require_relative "../http/request" +require_relative "exception_wrapper" module ActionDispatch # This middleware rescues any exception returned by the application diff --git a/actionpack/lib/action_dispatch/middleware/ssl.rb b/actionpack/lib/action_dispatch/middleware/ssl.rb index 557721c301..e79404c993 100644 --- a/actionpack/lib/action_dispatch/middleware/ssl.rb +++ b/actionpack/lib/action_dispatch/middleware/ssl.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActionDispatch # This middleware is added to the stack when `config.force_ssl = true`, and is passed # the options set in `config.ssl_options`. It does three jobs to enforce secure HTTP @@ -94,7 +95,7 @@ module ActionDispatch # http://tools.ietf.org/html/rfc6797#section-6.1 def build_hsts_header(hsts) - value = "max-age=#{hsts[:expires].to_i}" + value = "max-age=#{hsts[:expires].to_i}".dup value << "; includeSubDomains" if hsts[:subdomains] value << "; preload" if hsts[:preload] value @@ -133,7 +134,7 @@ module ActionDispatch host = @redirect[:host] || request.host port = @redirect[:port] || request.port - location = "https://#{host}" + location = "https://#{host}".dup location << ":#{port}" if port != 80 && port != 443 location << request.fullpath location diff --git a/actionpack/lib/action_dispatch/middleware/static.rb b/actionpack/lib/action_dispatch/middleware/static.rb index fb99f13a1c..6f4a97da3e 100644 --- a/actionpack/lib/action_dispatch/middleware/static.rb +++ b/actionpack/lib/action_dispatch/middleware/static.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "rack/utils" require "active_support/core_ext/uri" @@ -33,7 +34,7 @@ module ActionDispatch paths = [path, "#{path}#{ext}", "#{path}/#{@index}#{ext}"] if match = paths.detect { |p| - path = File.join(@root, p.force_encoding(Encoding::UTF_8)) + path = File.join(@root, p.dup.force_encoding(Encoding::UTF_8)) begin File.file?(path) && File.readable?(path) rescue SystemCallError diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 88deee5f5e..057ff07fcf 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1,9 +1,10 @@ +# frozen_string_literal: true require "active_support/core_ext/hash/slice" require "active_support/core_ext/enumerable" require "active_support/core_ext/array/extract_options" require "active_support/core_ext/regexp" -require "action_dispatch/routing/redirection" -require "action_dispatch/routing/endpoint" +require_relative "redirection" +require_relative "endpoint" module ActionDispatch module Routing @@ -306,7 +307,7 @@ module ActionDispatch 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." + message = "'#{part}' is not a supported controller name. This can lead to potential routing problems.".dup message << " See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use" raise ArgumentError, message @@ -652,18 +653,25 @@ module ActionDispatch def define_generate_prefix(app, name) _route = @set.named_routes.get name _routes = @set - app.routes.define_mounted_helper(name) + + script_namer = ->(options) do + prefix_options = options.slice(*_route.segment_keys) + prefix_options[:relative_url_root] = "".freeze + # We must actually delete prefix segment keys to avoid passing them to next url_for. + _route.segment_keys.each { |k| options.delete(k) } + _routes.url_helpers.send("#{name}_path", prefix_options) + end + + app.routes.define_mounted_helper(name, script_namer) + app.routes.extend Module.new { def optimize_routes_generation?; false; end + define_method :find_script_name do |options| if options.key? :script_name super(options) else - prefix_options = options.slice(*_route.segment_keys) - prefix_options[:relative_url_root] = "".freeze - # We must actually delete prefix segment keys to avoid passing them to next url_for. - _route.segment_keys.each { |k| options.delete(k) } - _routes.url_helpers.send("#{name}_path", prefix_options) + script_namer.call(options) end end } diff --git a/actionpack/lib/action_dispatch/routing/redirection.rb b/actionpack/lib/action_dispatch/routing/redirection.rb index 3bcb341758..6396b5031d 100644 --- a/actionpack/lib/action_dispatch/routing/redirection.rb +++ b/actionpack/lib/action_dispatch/routing/redirection.rb @@ -1,9 +1,9 @@ -require "action_dispatch/http/request" +require_relative "../http/request" require "active_support/core_ext/uri" require "active_support/core_ext/array/extract_options" require "rack/utils" require "action_controller/metal/exceptions" -require "action_dispatch/routing/endpoint" +require_relative "endpoint" module ActionDispatch module Routing diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index d9f7180f51..3f15257ed6 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -1,11 +1,12 @@ -require "action_dispatch/journey" +# frozen_string_literal: true +require_relative "../journey" require "active_support/core_ext/object/to_query" require "active_support/core_ext/hash/slice" require "active_support/core_ext/module/remove_method" require "active_support/core_ext/array/extract_options" require "action_controller/metal/exceptions" -require "action_dispatch/http/request" -require "action_dispatch/routing/endpoint" +require_relative "../http/request" +require_relative "endpoint" module ActionDispatch module Routing @@ -233,7 +234,7 @@ module ActionDispatch missing_keys << missing_key } constraints = Hash[@route.requirements.merge(params).sort_by { |k, v| k.to_s }] - message = "No route matches #{constraints.inspect}" + message = "No route matches #{constraints.inspect}".dup message << ", missing required keys: #{missing_keys.sort.inspect}" raise ActionController::UrlGenerationError, message @@ -449,7 +450,7 @@ module ActionDispatch MountedHelpers end - def define_mounted_helper(name) + def define_mounted_helper(name, script_namer = nil) return if MountedHelpers.method_defined?(name) routes = self @@ -457,7 +458,7 @@ module ActionDispatch MountedHelpers.class_eval do define_method "_#{name}" do - RoutesProxy.new(routes, _routes_context, helpers) + RoutesProxy.new(routes, _routes_context, helpers, script_namer) end end diff --git a/actionpack/lib/action_dispatch/routing/routes_proxy.rb b/actionpack/lib/action_dispatch/routing/routes_proxy.rb index c1423f770f..7a6c2e95d8 100644 --- a/actionpack/lib/action_dispatch/routing/routes_proxy.rb +++ b/actionpack/lib/action_dispatch/routing/routes_proxy.rb @@ -8,9 +8,10 @@ module ActionDispatch attr_accessor :scope, :routes alias :_routes :routes - def initialize(routes, scope, helpers) + def initialize(routes, scope, helpers, script_namer = nil) @routes, @scope = routes, scope @helpers = helpers + @script_namer = script_namer end def url_options @@ -29,7 +30,9 @@ module ActionDispatch self.class.class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{method}(*args) options = args.extract_options! - args << url_options.merge((options || {}).symbolize_keys) + options = url_options.merge((options || {}).symbolize_keys) + options.reverse_merge!(script_name: @script_namer.call(options)) if @script_namer + args << options @helpers.#{method}(*args) end RUBY diff --git a/actionpack/lib/action_dispatch/system_test_case.rb b/actionpack/lib/action_dispatch/system_test_case.rb index c39a135ce0..23ce8d5a92 100644 --- a/actionpack/lib/action_dispatch/system_test_case.rb +++ b/actionpack/lib/action_dispatch/system_test_case.rb @@ -1,10 +1,11 @@ require "capybara/dsl" require "capybara/minitest" require "action_controller" -require "action_dispatch/system_testing/driver" -require "action_dispatch/system_testing/server" -require "action_dispatch/system_testing/test_helpers/screenshot_helper" -require "action_dispatch/system_testing/test_helpers/setup_and_teardown" +require_relative "system_testing/driver" +require_relative "system_testing/server" +require_relative "system_testing/test_helpers/screenshot_helper" +require_relative "system_testing/test_helpers/setup_and_teardown" +require_relative "system_testing/test_helpers/undef_methods" module ActionDispatch # = System Testing @@ -88,6 +89,7 @@ module ActionDispatch include Capybara::Minitest::Assertions include SystemTesting::TestHelpers::SetupAndTeardown include SystemTesting::TestHelpers::ScreenshotHelper + include SystemTesting::TestHelpers::UndefMethods def initialize(*) # :nodoc: super diff --git a/actionpack/lib/action_dispatch/system_testing/driver.rb b/actionpack/lib/action_dispatch/system_testing/driver.rb index 1a027f2e23..81e6f0fc80 100644 --- a/actionpack/lib/action_dispatch/system_testing/driver.rb +++ b/actionpack/lib/action_dispatch/system_testing/driver.rb @@ -9,14 +9,14 @@ module ActionDispatch end def use - register unless rack_test? + register if registerable? setup end private - def rack_test? - @name == :rack_test + def registerable? + [:selenium, :poltergeist, :webkit].include?(@name) end def register diff --git a/actionpack/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb b/actionpack/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb new file mode 100644 index 0000000000..2d3f4662d7 --- /dev/null +++ b/actionpack/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb @@ -0,0 +1,24 @@ +module ActionDispatch + module SystemTesting + module TestHelpers + module UndefMethods # :nodoc: + extend ActiveSupport::Concern + included do + METHODS = %i(get post put patch delete).freeze + + METHODS.each do |verb| + undef_method verb + end + + def method_missing(method, *args, &block) + if METHODS.include?(method) + raise NoMethodError + else + super + end + end + end + end + end + end +end diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index 1baf979ac9..749f2eab57 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -79,7 +79,7 @@ module ActionDispatch 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)}>" - .concat(location_if_redirected).concat(response_body_if_short) + .dup.concat(location_if_redirected).concat(response_body_if_short) end def response_body_if_short diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index f16647fac8..beba4e3c36 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -5,7 +5,7 @@ require "active_support/core_ext/object/try" require "rack/test" require "minitest" -require "action_dispatch/testing/request_encoder" +require_relative "request_encoder" module ActionDispatch module Integration #:nodoc: diff --git a/actionpack/lib/action_dispatch/testing/test_process.rb b/actionpack/lib/action_dispatch/testing/test_process.rb index 0282eb15c3..8061ac2e3b 100644 --- a/actionpack/lib/action_dispatch/testing/test_process.rb +++ b/actionpack/lib/action_dispatch/testing/test_process.rb @@ -1,5 +1,5 @@ -require "action_dispatch/middleware/cookies" -require "action_dispatch/middleware/flash" +require_relative "../middleware/cookies" +require_relative "../middleware/flash" module ActionDispatch module TestProcess diff --git a/actionpack/lib/action_dispatch/testing/test_response.rb b/actionpack/lib/action_dispatch/testing/test_response.rb index 5c89f9c75e..2a1a9ffce9 100644 --- a/actionpack/lib/action_dispatch/testing/test_response.rb +++ b/actionpack/lib/action_dispatch/testing/test_response.rb @@ -1,4 +1,4 @@ -require "action_dispatch/testing/request_encoder" +require_relative "request_encoder" module ActionDispatch # Integration test methods such as ActionDispatch::Integration::Session#get diff --git a/actionpack/lib/action_pack.rb b/actionpack/lib/action_pack.rb index eec622e085..6a74baff09 100644 --- a/actionpack/lib/action_pack.rb +++ b/actionpack/lib/action_pack.rb @@ -21,4 +21,4 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #++ -require "action_pack/version" +require_relative "action_pack/version" diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index bd118b46be..9a337803cb 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true $:.unshift File.expand_path("lib", __dir__) $:.unshift File.expand_path("fixtures/helpers", __dir__) $:.unshift File.expand_path("fixtures/alternate_helpers", __dir__) @@ -175,7 +176,7 @@ end class Rack::TestCase < ActionDispatch::IntegrationTest def self.testing(klass = nil) if klass - @testing = "/#{klass.name.underscore}".sub!(/_controller$/, "") + @testing = "/#{klass.name.underscore}".sub(/_controller$/, "") else @testing end diff --git a/actionpack/test/controller/params_wrapper_test.rb b/actionpack/test/controller/params_wrapper_test.rb index 4cbb28ef60..c0f01e6df8 100644 --- a/actionpack/test/controller/params_wrapper_test.rb +++ b/actionpack/test/controller/params_wrapper_test.rb @@ -226,6 +226,14 @@ class ParamsWrapperTest < ActionController::TestCase end end + def test_preserves_query_string_params_in_filtered_params + with_default_wrapper_options do + @request.env["CONTENT_TYPE"] = "application/json" + get :parse, params: { "user" => { "username" => "nixon" } } + assert_equal({ "controller" => "params_wrapper_test/users", "action" => "parse", "user" => { "username" => "nixon" } }, @request.filtered_parameters) + end + end + def test_empty_parameter_set with_default_wrapper_options do @request.env["CONTENT_TYPE"] = "application/json" diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 56b39510bb..40401cbc95 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "controller/fake_controllers" require "active_support/core_ext/object/with_options" @@ -656,7 +657,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase 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" # 'text' in Russian + token = "\321\202\320\265\320\272\321\201\321\202".dup # 'text' in Russian token.force_encoding(Encoding::BINARY) escaped_token = CGI::escape(token) diff --git a/actionpack/test/dispatch/debug_exceptions_test.rb b/actionpack/test/dispatch/debug_exceptions_test.rb index ea477e8908..bf07410d0d 100644 --- a/actionpack/test/dispatch/debug_exceptions_test.rb +++ b/actionpack/test/dispatch/debug_exceptions_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" class DebugExceptionsTest < ActionDispatch::IntegrationTest @@ -344,7 +345,7 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest }) assert_response 500 - assert_includes(body, CGI.escapeHTML(PP.pp(params, "", 200))) + assert_includes(body, CGI.escapeHTML(PP.pp(params, "".dup, 200))) end test "sets the HTTP charset parameter" do diff --git a/actionpack/test/dispatch/prefix_generation_test.rb b/actionpack/test/dispatch/prefix_generation_test.rb index 0e093d2188..3cd9344c04 100644 --- a/actionpack/test/dispatch/prefix_generation_test.rb +++ b/actionpack/test/dispatch/prefix_generation_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "rack/test" require "rails/engine" @@ -11,7 +12,7 @@ module TestGenerationPrefix end def self.model_name - klass = "Post" + klass = "Post".dup def klass.name; self end ActiveModel::Name.new(klass) diff --git a/actionpack/test/dispatch/static_test.rb b/actionpack/test/dispatch/static_test.rb index 3082d1072b..50780a1dd0 100644 --- a/actionpack/test/dispatch/static_test.rb +++ b/actionpack/test/dispatch/static_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "zlib" @@ -29,7 +30,7 @@ module StaticTests end def test_handles_urls_with_ascii_8bit - assert_equal "Hello, World!", get("/doorkeeper%E3E4".force_encoding("ASCII-8BIT")).body + assert_equal "Hello, World!", get("/doorkeeper%E3E4".dup.force_encoding("ASCII-8BIT")).body end def test_handles_urls_with_ascii_8bit_on_win_31j @@ -37,7 +38,7 @@ module StaticTests Encoding.default_internal = "Windows-31J" Encoding.default_external = "Windows-31J" end - assert_equal "Hello, World!", get("/doorkeeper%E3E4".force_encoding("ASCII-8BIT")).body + assert_equal "Hello, World!", get("/doorkeeper%E3E4".dup.force_encoding("ASCII-8BIT")).body end def test_handles_urls_with_null_byte diff --git a/actionpack/test/dispatch/system_testing/driver_test.rb b/actionpack/test/dispatch/system_testing/driver_test.rb index 4a1b971da5..34d27671bb 100644 --- a/actionpack/test/dispatch/system_testing/driver_test.rb +++ b/actionpack/test/dispatch/system_testing/driver_test.rb @@ -29,7 +29,7 @@ class DriverTest < ActiveSupport::TestCase assert_equal ({ skip_image_loading: true }), driver.instance_variable_get(:@options) end - test "rack_test? returns false if driver is poltergeist" do - assert_not ActionDispatch::SystemTesting::Driver.new(:poltergeist).send(:rack_test?) + test "registerable? returns false if driver is rack_test" do + assert_not ActionDispatch::SystemTesting::Driver.new(:rack_test).send(:registerable?) end end diff --git a/actionpack/test/dispatch/system_testing/system_test_case_test.rb b/actionpack/test/dispatch/system_testing/system_test_case_test.rb index 8f90e45f5f..53f1a1bb37 100644 --- a/actionpack/test/dispatch/system_testing/system_test_case_test.rb +++ b/actionpack/test/dispatch/system_testing/system_test_case_test.rb @@ -31,3 +31,35 @@ class SetHostTest < DrivenByRackTest assert_equal "http://example.com", Capybara.app_host end end + +class UndefMethodsTest < DrivenBySeleniumWithChrome + test "get" do + assert_raise NoMethodError do + get "http://example.com" + end + end + + test "post" do + assert_raise NoMethodError do + post "http://example.com" + end + end + + test "put" do + assert_raise NoMethodError do + put "http://example.com" + end + end + + test "patch" do + assert_raise NoMethodError do + patch "http://example.com" + end + end + + test "delete" do + assert_raise NoMethodError do + delete "http://example.com" + end + end +end diff --git a/actionpack/test/journey/router/utils_test.rb b/actionpack/test/journey/router/utils_test.rb index 74277a4325..a69b606b01 100644 --- a/actionpack/test/journey/router/utils_test.rb +++ b/actionpack/test/journey/router/utils_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" module ActionDispatch @@ -21,7 +22,7 @@ module ActionDispatch end def test_uri_unescape_with_utf8_string - assert_equal "Šašinková", Utils.unescape_uri("%C5%A0a%C5%A1inkov%C3%A1".force_encoding(Encoding::US_ASCII)) + assert_equal "Šašinková", Utils.unescape_uri("%C5%A0a%C5%A1inkov%C3%A1".dup.force_encoding(Encoding::US_ASCII)) end def test_normalize_path_not_greedy diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index e618183129..5bc93fcb5b 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,7 @@ +* Add `srcset` option to `image_tag` helper. + + *Roberto Miranda* + * Fix issues with scopes and engine on `current_page?` method. Fixes #29401. diff --git a/actionview/lib/action_view.rb b/actionview/lib/action_view.rb index 99c5b831b5..53a83d48f6 100644 --- a/actionview/lib/action_view.rb +++ b/actionview/lib/action_view.rb @@ -23,7 +23,7 @@ require "active_support" require "active_support/rails" -require "action_view/version" +require_relative "action_view/version" module ActionView extend ActiveSupport::Autoload diff --git a/actionview/lib/action_view/base.rb b/actionview/lib/action_view/base.rb index 1808553239..969d300bc1 100644 --- a/actionview/lib/action_view/base.rb +++ b/actionview/lib/action_view/base.rb @@ -1,11 +1,11 @@ require "active_support/core_ext/module/attr_internal" require "active_support/core_ext/module/attribute_accessors" require "active_support/ordered_options" -require "action_view/log_subscriber" -require "action_view/helpers" -require "action_view/context" -require "action_view/template" -require "action_view/lookup_context" +require_relative "log_subscriber" +require_relative "helpers" +require_relative "context" +require_relative "template" +require_relative "lookup_context" module ActionView #:nodoc: # = Action View Base diff --git a/actionview/lib/action_view/dependency_tracker.rb b/actionview/lib/action_view/dependency_tracker.rb index 451eeec9d6..ee438f9311 100644 --- a/actionview/lib/action_view/dependency_tracker.rb +++ b/actionview/lib/action_view/dependency_tracker.rb @@ -1,5 +1,5 @@ require "concurrent/map" -require "action_view/path_set" +require_relative "path_set" module ActionView class DependencyTracker # :nodoc: diff --git a/actionview/lib/action_view/digestor.rb b/actionview/lib/action_view/digestor.rb index 5ddf1ceb66..00ff36c879 100644 --- a/actionview/lib/action_view/digestor.rb +++ b/actionview/lib/action_view/digestor.rb @@ -1,5 +1,5 @@ require "concurrent/map" -require "action_view/dependency_tracker" +require_relative "dependency_tracker" require "monitor" module ActionView diff --git a/actionview/lib/action_view/helpers/asset_tag_helper.rb b/actionview/lib/action_view/helpers/asset_tag_helper.rb index c21fe782c6..cc8690e7bc 100644 --- a/actionview/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionview/lib/action_view/helpers/asset_tag_helper.rb @@ -1,7 +1,7 @@ require "active_support/core_ext/array/extract_options" require "active_support/core_ext/hash/keys" -require "action_view/helpers/asset_url_helper" -require "action_view/helpers/tag_helper" +require_relative "asset_url_helper" +require_relative "tag_helper" module ActionView # = Action View Asset Tag Helpers @@ -203,13 +203,15 @@ module ActionView # ==== Options # # You can add HTML attributes using the +options+. The +options+ supports - # two additional keys for convenience and conformance: + # additional keys for convenience and conformance: # # * <tt>:alt</tt> - If no alt text is given, the file name part of the # +source+ is used (capitalized and without the extension) # * <tt>:size</tt> - Supplied as "{Width}x{Height}" or "{Number}", so "30x45" becomes # width="30" and height="45", and "50" becomes width="50" and height="50". # <tt>:size</tt> will be ignored if the value is not in the correct format. + # * <tt>:srcset</tt> - If supplied as a hash or array of <tt>[source, descriptor]</tt> + # pairs, each image path will be expanded before the list is formatted as a string. # # ==== Examples # @@ -227,16 +229,28 @@ module ActionView # # => <img alt="Icon" class="menu_icon" src="/icons/icon.gif" /> # image_tag("/icons/icon.gif", data: { title: 'Rails Application' }) # # => <img data-title="Rails Application" src="/icons/icon.gif" /> + # image_tag("icon.png", srcset: { "icon_2x.png" => "2x", "icon_4x.png" => "4x" }) + # # => <img src="/assets/icon.png" srcset="/assets/icon_2x.png 2x, /assets/icon_4x.png 4x"> + # image_tag("pic.jpg", srcset: [["pic_1024.jpg", "1024w"], ["pic_1980.jpg", "1980w"]], sizes: "100vw") + # # => <img src="/assets/pic.jpg" srcset="/assets/pic_1024.jpg 1024w, /assets/pic_1980.jpg 1980w" sizes="100vw"> def image_tag(source, options = {}) options = options.symbolize_keys check_for_image_tag_errors(options) + skip_pipeline = options.delete(:skip_pipeline) - src = options[:src] = path_to_image(source, skip_pipeline: options.delete(:skip_pipeline)) + src = options[:src] = path_to_image(source, skip_pipeline: skip_pipeline) unless src.start_with?("cid:") || src.start_with?("data:") || src.blank? options[:alt] = options.fetch(:alt) { image_alt(src) } end + if options[:srcset] && !options[:srcset].is_a?(String) + options[:srcset] = options[:srcset].map do |src_path, size| + src_path = path_to_image(src_path, skip_pipeline: skip_pipeline) + "#{src_path} #{size}" + end.join(", ") + end + options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size] tag("img", options) end diff --git a/actionview/lib/action_view/helpers/date_helper.rb b/actionview/lib/action_view/helpers/date_helper.rb index 3f43465aa4..3fbed44f7e 100644 --- a/actionview/lib/action_view/helpers/date_helper.rb +++ b/actionview/lib/action_view/helpers/date_helper.rb @@ -1,5 +1,5 @@ require "date" -require "action_view/helpers/tag_helper" +require_relative "tag_helper" require "active_support/core_ext/array/extract_options" require "active_support/core_ext/date/conversions" require "active_support/core_ext/hash/slice" @@ -1007,7 +1007,7 @@ module ActionView 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" + select_html = "\n".dup 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 @@ -1089,7 +1089,7 @@ module ActionView # Given an ordering of datetime components, create the selection HTML # and join them with their appropriate separators. def build_selects_from_types(order) - select = "" + select = "".dup 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 diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb index 4b2561e53d..6b36c2272a 100644 --- a/actionview/lib/action_view/helpers/form_helper.rb +++ b/actionview/lib/action_view/helpers/form_helper.rb @@ -1,10 +1,10 @@ require "cgi" -require "action_view/helpers/date_helper" -require "action_view/helpers/tag_helper" -require "action_view/helpers/form_tag_helper" -require "action_view/helpers/active_model_helper" -require "action_view/model_naming" -require "action_view/record_identifier" +require_relative "date_helper" +require_relative "tag_helper" +require_relative "form_tag_helper" +require_relative "active_model_helper" +require_relative "../model_naming" +require_relative "../record_identifier" require "active_support/core_ext/module/attribute_accessors" require "active_support/core_ext/hash/slice" require "active_support/core_ext/string/output_safety" diff --git a/actionview/lib/action_view/helpers/form_options_helper.rb b/actionview/lib/action_view/helpers/form_options_helper.rb index 07d4310a4e..0de3800a51 100644 --- a/actionview/lib/action_view/helpers/form_options_helper.rb +++ b/actionview/lib/action_view/helpers/form_options_helper.rb @@ -1,6 +1,6 @@ require "cgi" require "erb" -require "action_view/helpers/form_helper" +require_relative "form_helper" require "active_support/core_ext/string/output_safety" require "active_support/core_ext/array/extract_options" require "active_support/core_ext/array/wrap" diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb index 9fc08b3837..c8c6632781 100644 --- a/actionview/lib/action_view/helpers/form_tag_helper.rb +++ b/actionview/lib/action_view/helpers/form_tag_helper.rb @@ -1,5 +1,5 @@ require "cgi" -require "action_view/helpers/tag_helper" +require_relative "tag_helper" require "active_support/core_ext/string/output_safety" require "active_support/core_ext/module/attribute_accessors" diff --git a/actionview/lib/action_view/helpers/javascript_helper.rb b/actionview/lib/action_view/helpers/javascript_helper.rb index 22e1e74ad6..8806492572 100644 --- a/actionview/lib/action_view/helpers/javascript_helper.rb +++ b/actionview/lib/action_view/helpers/javascript_helper.rb @@ -1,4 +1,4 @@ -require "action_view/helpers/tag_helper" +require_relative "tag_helper" module ActionView module Helpers @@ -13,8 +13,8 @@ module ActionView "'" => "\\'" } - JS_ESCAPE_MAP["\342\200\250".force_encoding(Encoding::UTF_8).encode!] = "
" - JS_ESCAPE_MAP["\342\200\251".force_encoding(Encoding::UTF_8).encode!] = "
" + 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!] = "
" # Escapes carriage returns and single and double quotes for JavaScript segments. # diff --git a/actionview/lib/action_view/helpers/tags/check_box.rb b/actionview/lib/action_view/helpers/tags/check_box.rb index 02f87fc89f..b9b988325d 100644 --- a/actionview/lib/action_view/helpers/tags/check_box.rb +++ b/actionview/lib/action_view/helpers/tags/check_box.rb @@ -1,4 +1,4 @@ -require "action_view/helpers/tags/checkable" +require_relative "checkable" module ActionView module Helpers diff --git a/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb b/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb index e02b7bdb2e..ef37c1c342 100644 --- a/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb +++ b/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb @@ -1,4 +1,4 @@ -require "action_view/helpers/tags/collection_helpers" +require_relative "collection_helpers" module ActionView module Helpers diff --git a/actionview/lib/action_view/helpers/tags/collection_radio_buttons.rb b/actionview/lib/action_view/helpers/tags/collection_radio_buttons.rb index f085a5fb73..c7d28905d0 100644 --- a/actionview/lib/action_view/helpers/tags/collection_radio_buttons.rb +++ b/actionview/lib/action_view/helpers/tags/collection_radio_buttons.rb @@ -1,4 +1,4 @@ -require "action_view/helpers/tags/collection_helpers" +require_relative "collection_helpers" module ActionView module Helpers diff --git a/actionview/lib/action_view/helpers/tags/radio_button.rb b/actionview/lib/action_view/helpers/tags/radio_button.rb index 43dbd32083..782263ac5b 100644 --- a/actionview/lib/action_view/helpers/tags/radio_button.rb +++ b/actionview/lib/action_view/helpers/tags/radio_button.rb @@ -1,4 +1,4 @@ -require "action_view/helpers/tags/checkable" +require_relative "checkable" module ActionView module Helpers diff --git a/actionview/lib/action_view/helpers/tags/text_area.rb b/actionview/lib/action_view/helpers/tags/text_area.rb index 31e3a9e9b1..1058fdf55f 100644 --- a/actionview/lib/action_view/helpers/tags/text_area.rb +++ b/actionview/lib/action_view/helpers/tags/text_area.rb @@ -1,4 +1,4 @@ -require "action_view/helpers/tags/placeholderable" +require_relative "placeholderable" module ActionView module Helpers diff --git a/actionview/lib/action_view/helpers/tags/text_field.rb b/actionview/lib/action_view/helpers/tags/text_field.rb index 613cade7b3..1d55105587 100644 --- a/actionview/lib/action_view/helpers/tags/text_field.rb +++ b/actionview/lib/action_view/helpers/tags/text_field.rb @@ -1,4 +1,4 @@ -require "action_view/helpers/tags/placeholderable" +require_relative "placeholderable" module ActionView module Helpers diff --git a/actionview/lib/action_view/helpers/translation_helper.rb b/actionview/lib/action_view/helpers/translation_helper.rb index cc928f2b7a..b10cfadaed 100644 --- a/actionview/lib/action_view/helpers/translation_helper.rb +++ b/actionview/lib/action_view/helpers/translation_helper.rb @@ -1,4 +1,4 @@ -require "action_view/helpers/tag_helper" +require_relative "tag_helper" require "active_support/core_ext/string/access" require "i18n/exceptions" @@ -95,7 +95,7 @@ module ActionView raise e if raise_error keys = I18n.normalize_keys(e.locale, e.key, e.options[:scope]) - title = "translation missing: #{keys.join('.')}" + title = "translation missing: #{keys.join('.')}".dup interpolations = options.except(:default, :scope) if interpolations.any? diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb index b78c367921..644e1e4391 100644 --- a/actionview/lib/action_view/helpers/url_helper.rb +++ b/actionview/lib/action_view/helpers/url_helper.rb @@ -1,4 +1,4 @@ -require "action_view/helpers/javascript_helper" +require_relative "javascript_helper" require "active_support/core_ext/array/access" require "active_support/core_ext/hash/keys" require "active_support/core_ext/string/output_safety" diff --git a/actionview/lib/action_view/layouts.rb b/actionview/lib/action_view/layouts.rb index ab8409e8d0..b62fde30e8 100644 --- a/actionview/lib/action_view/layouts.rb +++ b/actionview/lib/action_view/layouts.rb @@ -1,4 +1,4 @@ -require "action_view/rendering" +require_relative "rendering" require "active_support/core_ext/module/remove_method" module ActionView diff --git a/actionview/lib/action_view/log_subscriber.rb b/actionview/lib/action_view/log_subscriber.rb index ab8ec0aa42..c8623f1e9f 100644 --- a/actionview/lib/action_view/log_subscriber.rb +++ b/actionview/lib/action_view/log_subscriber.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "active_support/log_subscriber" module ActionView @@ -14,7 +15,7 @@ module ActionView def render_template(event) info do - message = " Rendered #{from_rails_root(event.payload[:identifier])}" + message = " Rendered #{from_rails_root(event.payload[:identifier])}".dup message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout] message << " (#{event.duration.round(1)}ms)" end @@ -22,7 +23,7 @@ module ActionView def render_partial(event) info do - message = " Rendered #{from_rails_root(event.payload[:identifier])}" + message = " Rendered #{from_rails_root(event.payload[:identifier])}".dup 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? @@ -83,7 +84,7 @@ module ActionView def log_rendering_start(payload) info do - message = " Rendering #{from_rails_root(payload[:identifier])}" + message = " Rendering #{from_rails_root(payload[:identifier])}".dup message << " within #{from_rails_root(payload[:layout])}" if payload[:layout] message end diff --git a/actionview/lib/action_view/lookup_context.rb b/actionview/lib/action_view/lookup_context.rb index b7dbb38369..ce5493c01b 100644 --- a/actionview/lib/action_view/lookup_context.rb +++ b/actionview/lib/action_view/lookup_context.rb @@ -1,7 +1,7 @@ require "concurrent/map" require "active_support/core_ext/module/remove_method" require "active_support/core_ext/module/attribute_accessors" -require "action_view/template/resolver" +require_relative "template/resolver" module ActionView # = Action View Lookup Context diff --git a/actionview/lib/action_view/record_identifier.rb b/actionview/lib/action_view/record_identifier.rb index 48bea315a9..6805513347 100644 --- a/actionview/lib/action_view/record_identifier.rb +++ b/actionview/lib/action_view/record_identifier.rb @@ -1,5 +1,5 @@ require "active_support/core_ext/module" -require "action_view/model_naming" +require_relative "model_naming" module ActionView # RecordIdentifier encapsulates methods used by various ActionView helpers diff --git a/actionview/lib/action_view/renderer/partial_renderer.rb b/actionview/lib/action_view/renderer/partial_renderer.rb index 1f8f997a2d..77f5084686 100644 --- a/actionview/lib/action_view/renderer/partial_renderer.rb +++ b/actionview/lib/action_view/renderer/partial_renderer.rb @@ -1,5 +1,5 @@ require "concurrent/map" -require "action_view/renderer/partial_renderer/collection_caching" +require_relative "partial_renderer/collection_caching" module ActionView class PartialIteration diff --git a/actionview/lib/action_view/rendering.rb b/actionview/lib/action_view/rendering.rb index cf18562c45..9bee76a1f7 100644 --- a/actionview/lib/action_view/rendering.rb +++ b/actionview/lib/action_view/rendering.rb @@ -1,4 +1,4 @@ -require "action_view/view_paths" +require_relative "view_paths" module ActionView # This is a class to fix I18n global state. Whenever you provide I18n.locale during a request, diff --git a/actionview/lib/action_view/template.rb b/actionview/lib/action_view/template.rb index b0e2f1e54e..80b294dc3d 100644 --- a/actionview/lib/action_view/template.rb +++ b/actionview/lib/action_view/template.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "active_support/core_ext/object/try" require "active_support/core_ext/kernel/singleton_class" require "thread" @@ -282,7 +283,7 @@ module ActionView # Make sure that the resulting String to be eval'd is in the # encoding of the code - source = <<-end_src + source = <<-end_src.dup 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 @@ -329,12 +330,12 @@ module ActionView locals = locals.grep(/\A@?(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/) # Double assign to suppress the dreaded 'assigned but unused variable' warning - locals.each_with_object("") { |key, code| code << "#{key} = #{key} = local_assigns[:#{key}];" } + locals.each_with_object("".dup) { |key, code| code << "#{key} = #{key} = local_assigns[:#{key}];" } end def method_name @method_name ||= begin - m = "_#{identifier_method_name}__#{@identifier.hash}_#{__id__}" + m = "_#{identifier_method_name}__#{@identifier.hash}_#{__id__}".dup m.tr!("-".freeze, "_".freeze) m end diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb index 75ea4d31f5..0ccf398d9a 100644 --- a/actionview/lib/action_view/template/resolver.rb +++ b/actionview/lib/action_view/template/resolver.rb @@ -1,7 +1,7 @@ require "pathname" require "active_support/core_ext/class" require "active_support/core_ext/module/attribute_accessors" -require "action_view/template" +require_relative "../template" require "thread" require "concurrent/map" @@ -14,7 +14,7 @@ module ActionView alias_method :partial?, :partial def self.build(name, prefix, partial) - virtual = "" + virtual = "".dup virtual << "#{prefix}/" unless prefix.empty? virtual << (partial ? "_#{name}" : name) new name, prefix, partial, virtual diff --git a/actionview/lib/action_view/test_case.rb b/actionview/lib/action_view/test_case.rb index 80403799ab..424a86ba3e 100644 --- a/actionview/lib/action_view/test_case.rb +++ b/actionview/lib/action_view/test_case.rb @@ -104,7 +104,7 @@ module ActionView # 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 = "" + @rendered = "".dup make_test_case_available_to_view! say_no_to_protect_against_forgery! diff --git a/actionview/lib/action_view/testing/resolvers.rb b/actionview/lib/action_view/testing/resolvers.rb index 3188526b63..5e853311e6 100644 --- a/actionview/lib/action_view/testing/resolvers.rb +++ b/actionview/lib/action_view/testing/resolvers.rb @@ -1,4 +1,4 @@ -require "action_view/template/resolver" +require_relative "../template/resolver" module ActionView #:nodoc: # Use FixtureResolver in your tests to simulate the presence of files on the @@ -20,7 +20,7 @@ module ActionView #:nodoc: private def query(path, exts, _, _) - query = "" + query = "".dup EXTENSIONS.each_key do |ext| query << "(" << exts[ext].map { |e| e && Regexp.escape(".#{e}") }.join("|") << "|)" end diff --git a/actionview/test/activerecord/form_helper_activerecord_test.rb b/actionview/test/activerecord/form_helper_activerecord_test.rb index 3b314588c7..9949c3fde0 100644 --- a/actionview/test/activerecord/form_helper_activerecord_test.rb +++ b/actionview/test/activerecord/form_helper_activerecord_test.rb @@ -55,7 +55,7 @@ class FormHelperActiveRecordTest < ActionView::TestCase private def hidden_fields(method = nil) - txt = %{<input name="utf8" type="hidden" value="✓" />} + txt = %{<input name="utf8" type="hidden" value="✓" />}.dup if method && !%w(get post).include?(method.to_s) txt << %{<input name="_method" type="hidden" value="#{method}" />} @@ -65,7 +65,7 @@ class FormHelperActiveRecordTest < ActionView::TestCase end def form_text(action = "/", id = nil, html_class = nil, remote = nil, multipart = nil, method = nil) - txt = %{<form accept-charset="UTF-8" action="#{action}"} + txt = %{<form accept-charset="UTF-8" action="#{action}"}.dup txt << %{ enctype="multipart/form-data"} if multipart txt << %{ data-remote="true"} if remote txt << %{ class="#{html_class}"} if html_class diff --git a/actionview/test/fixtures/ruby_template.ruby b/actionview/test/fixtures/ruby_template.ruby index 5097bce47c..93334610a8 100644 --- a/actionview/test/fixtures/ruby_template.ruby +++ b/actionview/test/fixtures/ruby_template.ruby @@ -1,2 +1,2 @@ -body = "" +body = "".dup body << ["Hello", "from", "Ruby", "code"].join(" ") diff --git a/actionview/test/template/asset_tag_helper_test.rb b/actionview/test/template/asset_tag_helper_test.rb index 6093a4e660..d1190b1bd7 100644 --- a/actionview/test/template/asset_tag_helper_test.rb +++ b/actionview/test/template/asset_tag_helper_test.rb @@ -197,7 +197,10 @@ class AssetTagHelperTest < ActionView::TestCase %(image_tag("mouse.png", :alt => nil)) => %(<img src="/images/mouse.png" />), %(image_tag("data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==", :alt => nil)) => %(<img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" />), %(image_tag("")) => %(<img src="" />), - %(image_tag("gold.png", data: { title: 'Rails Application' })) => %(<img data-title="Rails Application" src="/images/gold.png" alt="Gold" />) + %(image_tag("gold.png", data: { title: 'Rails Application' })) => %(<img data-title="Rails Application" src="/images/gold.png" alt="Gold" />), + %(image_tag("rss.gif", srcset: "/assets/pic_640.jpg 640w, /assets/pic_1024.jpg 1024w")) => %(<img srcset="/assets/pic_640.jpg 640w, /assets/pic_1024.jpg 1024w" src="/images/rss.gif" alt="Rss" />), + %(image_tag("rss.gif", srcset: { "pic_640.jpg" => "640w", "pic_1024.jpg" => "1024w" })) => %(<img srcset="/images/pic_640.jpg 640w, /images/pic_1024.jpg 1024w" src="/images/rss.gif" alt="Rss" />), + %(image_tag("rss.gif", srcset: [["pic_640.jpg", "640w"], ["pic_1024.jpg", "1024w"]])) => %(<img srcset="/images/pic_640.jpg 640w, /images/pic_1024.jpg 1024w" src="/images/rss.gif" alt="Rss" />) } FaviconLinkToTag = { diff --git a/actionview/test/template/atom_feed_helper_test.rb b/actionview/test/template/atom_feed_helper_test.rb index 7304b769a4..7fa5e042fb 100644 --- a/actionview/test/template/atom_feed_helper_test.rb +++ b/actionview/test/template/atom_feed_helper_test.rb @@ -194,7 +194,7 @@ class ScrollsController < ActionController::Base FEEDS["provide_builder"] = <<-'EOT' # we pass in the new_xml to the helper so it doesn't # call anything on the original builder - new_xml = Builder::XmlMarkup.new(:target=>'') + new_xml = Builder::XmlMarkup.new(:target=>''.dup) atom_feed(:xml => new_xml) do |feed| feed.title("My great blog!") feed.updated(@scrolls.first.created_at) diff --git a/actionview/test/template/date_helper_test.rb b/actionview/test/template/date_helper_test.rb index b667303318..b9b8194e69 100644 --- a/actionview/test/template/date_helper_test.rb +++ b/actionview/test/template/date_helper_test.rb @@ -214,7 +214,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_day - expected = %(<select id="date_day" name="date[day]">\n) + expected = %(<select id="date_day" name="date[day]">\n).dup expected << %(<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16" selected="selected">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) expected << "</select>\n" @@ -223,7 +223,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_day_with_blank - expected = %(<select id="date_day" name="date[day]">\n) + expected = %(<select id="date_day" name="date[day]">\n).dup expected << %(<option value=""></option>\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16" selected="selected">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) expected << "</select>\n" @@ -232,7 +232,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_day_nil_with_blank - expected = %(<select id="date_day" name="date[day]">\n) + expected = %(<select id="date_day" name="date[day]">\n).dup expected << %(<option value=""></option>\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) expected << "</select>\n" @@ -240,7 +240,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_day_with_two_digit_numbers - expected = %(<select id="date_day" name="date[day]">\n) + expected = %(<select id="date_day" name="date[day]">\n).dup expected << %(<option value="1">01</option>\n<option selected="selected" value="2">02</option>\n<option value="3">03</option>\n<option value="4">04</option>\n<option value="5">05</option>\n<option value="6">06</option>\n<option value="7">07</option>\n<option value="8">08</option>\n<option value="9">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) expected << "</select>\n" @@ -249,7 +249,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_day_with_html_options - expected = %(<select id="date_day" name="date[day]" class="selector">\n) + expected = %(<select id="date_day" name="date[day]" class="selector">\n).dup expected << %(<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16" selected="selected">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) expected << "</select>\n" @@ -258,7 +258,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_day_with_default_prompt - expected = %(<select id="date_day" name="date[day]">\n) + expected = %(<select id="date_day" name="date[day]">\n).dup expected << %(<option value="">Day</option>\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16" selected="selected">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) expected << "</select>\n" @@ -266,7 +266,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_day_with_custom_prompt - expected = %(<select id="date_day" name="date[day]">\n) + expected = %(<select id="date_day" name="date[day]">\n).dup expected << %(<option value="">Choose day</option>\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16" selected="selected">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) expected << "</select>\n" @@ -274,7 +274,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_day_with_generic_with_css_classes - expected = %(<select id="date_day" name="date[day]" class="day">\n) + expected = %(<select id="date_day" name="date[day]" class="day">\n).dup expected << %(<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16" selected="selected">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) expected << "</select>\n" @@ -282,7 +282,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_day_with_custom_with_css_classes - expected = %(<select id="date_day" name="date[day]" class="my-day">\n) + expected = %(<select id="date_day" name="date[day]" class="my-day">\n).dup expected << %(<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16" selected="selected">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) expected << "</select>\n" @@ -290,7 +290,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_month - expected = %(<select id="date_month" name="date[month]">\n) + expected = %(<select id="date_month" name="date[month]">\n).dup expected << %(<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8" selected="selected">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n) expected << "</select>\n" @@ -299,7 +299,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_month_with_two_digit_numbers - expected = %(<select id="date_month" name="date[month]">\n) + expected = %(<select id="date_month" name="date[month]">\n).dup expected << %(<option value="1">01</option>\n<option value="2">02</option>\n<option value="3">03</option>\n<option value="4">04</option>\n<option value="5">05</option>\n<option value="6">06</option>\n<option value="7">07</option>\n<option value="8" selected="selected">08</option>\n<option value="9">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n) expected << "</select>\n" @@ -308,7 +308,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_month_with_disabled - expected = %(<select id="date_month" name="date[month]" disabled="disabled">\n) + expected = %(<select id="date_month" name="date[month]" disabled="disabled">\n).dup expected << %(<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8" selected="selected">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n) expected << "</select>\n" @@ -317,7 +317,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_month_with_field_name_override - expected = %(<select id="date_mois" name="date[mois]">\n) + expected = %(<select id="date_mois" name="date[mois]">\n).dup expected << %(<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8" selected="selected">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n) expected << "</select>\n" @@ -326,7 +326,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_month_with_blank - expected = %(<select id="date_month" name="date[month]">\n) + expected = %(<select id="date_month" name="date[month]">\n).dup expected << %(<option value=""></option>\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8" selected="selected">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n) expected << "</select>\n" @@ -335,7 +335,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_month_nil_with_blank - expected = %(<select id="date_month" name="date[month]">\n) + expected = %(<select id="date_month" name="date[month]">\n).dup expected << %(<option value=""></option>\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n) expected << "</select>\n" @@ -343,7 +343,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_month_with_numbers - expected = %(<select id="date_month" name="date[month]">\n) + expected = %(<select id="date_month" name="date[month]">\n).dup expected << %(<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8" selected="selected">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n) expected << "</select>\n" @@ -352,7 +352,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_month_with_numbers_and_names - expected = %(<select id="date_month" name="date[month]">\n) + expected = %(<select id="date_month" name="date[month]">\n).dup expected << %(<option value="1">1 - January</option>\n<option value="2">2 - February</option>\n<option value="3">3 - March</option>\n<option value="4">4 - April</option>\n<option value="5">5 - May</option>\n<option value="6">6 - June</option>\n<option value="7">7 - July</option>\n<option value="8" selected="selected">8 - August</option>\n<option value="9">9 - September</option>\n<option value="10">10 - October</option>\n<option value="11">11 - November</option>\n<option value="12">12 - December</option>\n) expected << "</select>\n" @@ -361,7 +361,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_month_with_format_string - expected = %(<select id="date_month" name="date[month]">\n) + expected = %(<select id="date_month" name="date[month]">\n).dup expected << %(<option value="1">January (01)</option>\n<option value="2">February (02)</option>\n<option value="3">March (03)</option>\n<option value="4">April (04)</option>\n<option value="5">May (05)</option>\n<option value="6">June (06)</option>\n<option value="7">July (07)</option>\n<option value="8" selected="selected">August (08)</option>\n<option value="9">September (09)</option>\n<option value="10">October (10)</option>\n<option value="11">November (11)</option>\n<option value="12">December (12)</option>\n) expected << "</select>\n" @@ -371,7 +371,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_month_with_numbers_and_names_with_abbv - expected = %(<select id="date_month" name="date[month]">\n) + expected = %(<select id="date_month" name="date[month]">\n).dup expected << %(<option value="1">1 - Jan</option>\n<option value="2">2 - Feb</option>\n<option value="3">3 - Mar</option>\n<option value="4">4 - Apr</option>\n<option value="5">5 - May</option>\n<option value="6">6 - Jun</option>\n<option value="7">7 - Jul</option>\n<option value="8" selected="selected">8 - Aug</option>\n<option value="9">9 - Sep</option>\n<option value="10">10 - Oct</option>\n<option value="11">11 - Nov</option>\n<option value="12">12 - Dec</option>\n) expected << "</select>\n" @@ -380,7 +380,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_month_with_abbv - expected = %(<select id="date_month" name="date[month]">\n) + expected = %(<select id="date_month" name="date[month]">\n).dup expected << %(<option value="1">Jan</option>\n<option value="2">Feb</option>\n<option value="3">Mar</option>\n<option value="4">Apr</option>\n<option value="5">May</option>\n<option value="6">Jun</option>\n<option value="7">Jul</option>\n<option value="8" selected="selected">Aug</option>\n<option value="9">Sep</option>\n<option value="10">Oct</option>\n<option value="11">Nov</option>\n<option value="12">Dec</option>\n) expected << "</select>\n" @@ -391,7 +391,7 @@ class DateHelperTest < ActionView::TestCase def test_select_month_with_custom_names month_names = %w(nil Januar Februar Marts April Maj Juni Juli August September Oktober November December) - expected = %(<select id="date_month" name="date[month]">\n) + expected = %(<select id="date_month" name="date[month]">\n).dup 1.upto(12) { |month| expected << %(<option value="#{month}"#{' selected="selected"' if month == 8}>#{month_names[month]}</option>\n) } expected << "</select>\n" @@ -402,7 +402,7 @@ class DateHelperTest < ActionView::TestCase def test_select_month_with_zero_indexed_custom_names month_names = %w(Januar Februar Marts April Maj Juni Juli August September Oktober November December) - expected = %(<select id="date_month" name="date[month]">\n) + expected = %(<select id="date_month" name="date[month]">\n).dup 1.upto(12) { |month| expected << %(<option value="#{month}"#{' selected="selected"' if month == 8}>#{month_names[month - 1]}</option>\n) } expected << "</select>\n" @@ -419,7 +419,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_month_with_html_options - expected = %(<select id="date_month" name="date[month]" class="selector" accesskey="M">\n) + expected = %(<select id="date_month" name="date[month]" class="selector" accesskey="M">\n).dup expected << %(<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8" selected="selected">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n) expected << "</select>\n" @@ -427,7 +427,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_month_with_default_prompt - expected = %(<select id="date_month" name="date[month]">\n) + expected = %(<select id="date_month" name="date[month]">\n).dup expected << %(<option value="">Month</option>\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8" selected="selected">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n) expected << "</select>\n" @@ -435,7 +435,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_month_with_custom_prompt - expected = %(<select id="date_month" name="date[month]">\n) + expected = %(<select id="date_month" name="date[month]">\n).dup expected << %(<option value="">Choose month</option>\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8" selected="selected">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n) expected << "</select>\n" @@ -443,7 +443,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_month_with_generic_with_css_classes - expected = %(<select id="date_month" name="date[month]" class="month">\n) + expected = %(<select id="date_month" name="date[month]" class="month">\n).dup expected << %(<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8" selected="selected">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n) expected << "</select>\n" @@ -451,7 +451,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_month_with_custom_with_css_classes - expected = %(<select id="date_month" name="date[month]" class="my-month">\n) + expected = %(<select id="date_month" name="date[month]" class="my-month">\n).dup expected << %(<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8" selected="selected">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n) expected << "</select>\n" @@ -459,7 +459,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_year - expected = %(<select id="date_year" name="date[year]">\n) + expected = %(<select id="date_year" name="date[year]">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -468,7 +468,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_year_with_disabled - expected = %(<select id="date_year" name="date[year]" disabled="disabled">\n) + expected = %(<select id="date_year" name="date[year]" disabled="disabled">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -477,7 +477,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_year_with_field_name_override - expected = %(<select id="date_annee" name="date[annee]">\n) + expected = %(<select id="date_annee" name="date[annee]">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -486,7 +486,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_year_with_type_discarding - expected = %(<select id="date_year" name="date_year">\n) + expected = %(<select id="date_year" name="date_year">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -497,7 +497,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_year_descending - expected = %(<select id="date_year" name="date[year]">\n) + expected = %(<select id="date_year" name="date[year]">\n).dup expected << %(<option value="2005" selected="selected">2005</option>\n<option value="2004">2004</option>\n<option value="2003">2003</option>\n) expected << "</select>\n" @@ -514,7 +514,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_year_with_html_options - expected = %(<select id="date_year" name="date[year]" class="selector" accesskey="M">\n) + expected = %(<select id="date_year" name="date[year]" class="selector" accesskey="M">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -522,7 +522,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_year_with_default_prompt - expected = %(<select id="date_year" name="date[year]">\n) + expected = %(<select id="date_year" name="date[year]">\n).dup expected << %(<option value="">Year</option>\n<option value="2003">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -530,7 +530,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_year_with_custom_prompt - expected = %(<select id="date_year" name="date[year]">\n) + expected = %(<select id="date_year" name="date[year]">\n).dup expected << %(<option value="">Choose year</option>\n<option value="2003">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -538,7 +538,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_year_with_generic_with_css_classes - expected = %(<select id="date_year" name="date[year]" class="year">\n) + expected = %(<select id="date_year" name="date[year]" class="year">\n).dup expected << %(<option value="2003">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -546,7 +546,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_year_with_custom_with_css_classes - expected = %(<select id="date_year" name="date[year]" class="my-year">\n) + expected = %(<select id="date_year" name="date[year]" class="my-year">\n).dup expected << %(<option value="2003">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -554,14 +554,14 @@ class DateHelperTest < ActionView::TestCase end def test_select_year_with_position - expected = %(<select id="date_year_1i" name="date[year(1i)]">\n) + expected = %(<select id="date_year_1i" name="date[year(1i)]">\n).dup expected << %(<option value="2003">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" assert_dom_equal expected, select_year(Date.current, include_position: true, start_year: 2003, end_year: 2005) end def test_select_hour - expected = %(<select id="date_hour" name="date[hour]">\n) + expected = %(<select id="date_hour" name="date[hour]">\n).dup expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08" selected="selected">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n) expected << "</select>\n" @@ -569,7 +569,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_hour_with_ampm - expected = %(<select id="date_hour" name="date[hour]">\n) + expected = %(<select id="date_hour" name="date[hour]">\n).dup expected << %(<option value="00">12 AM</option>\n<option value="01">01 AM</option>\n<option value="02">02 AM</option>\n<option value="03">03 AM</option>\n<option value="04">04 AM</option>\n<option value="05">05 AM</option>\n<option value="06">06 AM</option>\n<option value="07">07 AM</option>\n<option value="08" selected="selected">08 AM</option>\n<option value="09">09 AM</option>\n<option value="10">10 AM</option>\n<option value="11">11 AM</option>\n<option value="12">12 PM</option>\n<option value="13">01 PM</option>\n<option value="14">02 PM</option>\n<option value="15">03 PM</option>\n<option value="16">04 PM</option>\n<option value="17">05 PM</option>\n<option value="18">06 PM</option>\n<option value="19">07 PM</option>\n<option value="20">08 PM</option>\n<option value="21">09 PM</option>\n<option value="22">10 PM</option>\n<option value="23">11 PM</option>\n) expected << "</select>\n" @@ -577,7 +577,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_hour_with_disabled - expected = %(<select id="date_hour" name="date[hour]" disabled="disabled">\n) + expected = %(<select id="date_hour" name="date[hour]" disabled="disabled">\n).dup expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08" selected="selected">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n) expected << "</select>\n" @@ -585,7 +585,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_hour_with_field_name_override - expected = %(<select id="date_heure" name="date[heure]">\n) + expected = %(<select id="date_heure" name="date[heure]">\n).dup expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08" selected="selected">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n) expected << "</select>\n" @@ -593,7 +593,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_hour_with_blank - expected = %(<select id="date_hour" name="date[hour]">\n) + expected = %(<select id="date_hour" name="date[hour]">\n).dup expected << %(<option value=""></option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08" selected="selected">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n) expected << "</select>\n" @@ -601,7 +601,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_hour_nil_with_blank - expected = %(<select id="date_hour" name="date[hour]">\n) + expected = %(<select id="date_hour" name="date[hour]">\n).dup expected << %(<option value=""></option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n) expected << "</select>\n" @@ -609,7 +609,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_hour_with_html_options - expected = %(<select id="date_hour" name="date[hour]" class="selector" accesskey="M">\n) + expected = %(<select id="date_hour" name="date[hour]" class="selector" accesskey="M">\n).dup expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08" selected="selected">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n) expected << "</select>\n" @@ -617,7 +617,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_hour_with_default_prompt - expected = %(<select id="date_hour" name="date[hour]">\n) + expected = %(<select id="date_hour" name="date[hour]">\n).dup expected << %(<option value="">Hour</option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08" selected="selected">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n) expected << "</select>\n" @@ -625,7 +625,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_hour_with_custom_prompt - expected = %(<select id="date_hour" name="date[hour]">\n) + expected = %(<select id="date_hour" name="date[hour]">\n).dup expected << %(<option value="">Choose hour</option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08" selected="selected">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n) expected << "</select>\n" @@ -633,7 +633,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_hour_with_generic_with_css_classes - expected = %(<select id="date_hour" name="date[hour]" class="hour">\n) + expected = %(<select id="date_hour" name="date[hour]" class="hour">\n).dup expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08" selected="selected">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n) expected << "</select>\n" @@ -641,7 +641,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_hour_with_custom_with_css_classes - expected = %(<select id="date_hour" name="date[hour]" class="my-hour">\n) + expected = %(<select id="date_hour" name="date[hour]" class="my-hour">\n).dup expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08" selected="selected">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n) expected << "</select>\n" @@ -649,7 +649,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_minute - expected = %(<select id="date_minute" name="date[minute]">\n) + expected = %(<select id="date_minute" name="date[minute]">\n).dup expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04" selected="selected">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -657,7 +657,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_minute_with_disabled - expected = %(<select id="date_minute" name="date[minute]" disabled="disabled">\n) + expected = %(<select id="date_minute" name="date[minute]" disabled="disabled">\n).dup expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04" selected="selected">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -665,7 +665,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_minute_with_field_name_override - expected = %(<select id="date_minuto" name="date[minuto]">\n) + expected = %(<select id="date_minuto" name="date[minuto]">\n).dup expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04" selected="selected">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -673,7 +673,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_minute_with_blank - expected = %(<select id="date_minute" name="date[minute]">\n) + expected = %(<select id="date_minute" name="date[minute]">\n).dup expected << %(<option value=""></option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04" selected="selected">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -681,7 +681,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_minute_with_blank_and_step - expected = %(<select id="date_minute" name="date[minute]">\n) + expected = %(<select id="date_minute" name="date[minute]">\n).dup expected << %(<option value=""></option>\n<option value="00">00</option>\n<option value="15">15</option>\n<option value="30">30</option>\n<option value="45">45</option>\n) expected << "</select>\n" @@ -689,7 +689,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_minute_nil_with_blank - expected = %(<select id="date_minute" name="date[minute]">\n) + expected = %(<select id="date_minute" name="date[minute]">\n).dup expected << %(<option value=""></option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -697,7 +697,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_minute_nil_with_blank_and_step - expected = %(<select id="date_minute" name="date[minute]">\n) + expected = %(<select id="date_minute" name="date[minute]">\n).dup expected << %(<option value=""></option>\n<option value="00">00</option>\n<option value="15">15</option>\n<option value="30">30</option>\n<option value="45">45</option>\n) expected << "</select>\n" @@ -713,7 +713,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_minute_with_html_options - expected = %(<select id="date_minute" name="date[minute]" class="selector" accesskey="M">\n) + expected = %(<select id="date_minute" name="date[minute]" class="selector" accesskey="M">\n).dup expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04" selected="selected">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -721,7 +721,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_minute_with_default_prompt - expected = %(<select id="date_minute" name="date[minute]">\n) + expected = %(<select id="date_minute" name="date[minute]">\n).dup expected << %(<option value="">Minute</option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04" selected="selected">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -729,7 +729,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_minute_with_custom_prompt - expected = %(<select id="date_minute" name="date[minute]">\n) + expected = %(<select id="date_minute" name="date[minute]">\n).dup expected << %(<option value="">Choose minute</option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04" selected="selected">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -737,7 +737,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_minute_with_generic_with_css_classes - expected = %(<select id="date_minute" name="date[minute]" class="minute">\n) + expected = %(<select id="date_minute" name="date[minute]" class="minute">\n).dup expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04" selected="selected">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -745,7 +745,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_minute_with_custom_with_css_classes - expected = %(<select id="date_minute" name="date[minute]" class="my-minute">\n) + expected = %(<select id="date_minute" name="date[minute]" class="my-minute">\n).dup expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04" selected="selected">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -753,7 +753,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_second - expected = %(<select id="date_second" name="date[second]">\n) + expected = %(<select id="date_second" name="date[second]">\n).dup expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18" selected="selected">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -761,7 +761,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_second_with_disabled - expected = %(<select id="date_second" name="date[second]" disabled="disabled">\n) + expected = %(<select id="date_second" name="date[second]" disabled="disabled">\n).dup expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18" selected="selected">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -769,7 +769,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_second_with_field_name_override - expected = %(<select id="date_segundo" name="date[segundo]">\n) + expected = %(<select id="date_segundo" name="date[segundo]">\n).dup expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18" selected="selected">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -777,7 +777,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_second_with_blank - expected = %(<select id="date_second" name="date[second]">\n) + expected = %(<select id="date_second" name="date[second]">\n).dup expected << %(<option value=""></option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18" selected="selected">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -785,7 +785,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_second_nil_with_blank - expected = %(<select id="date_second" name="date[second]">\n) + expected = %(<select id="date_second" name="date[second]">\n).dup expected << %(<option value=""></option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -793,7 +793,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_second_with_html_options - expected = %(<select id="date_second" name="date[second]" class="selector" accesskey="M">\n) + expected = %(<select id="date_second" name="date[second]" class="selector" accesskey="M">\n).dup expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18" selected="selected">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -801,7 +801,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_second_with_default_prompt - expected = %(<select id="date_second" name="date[second]">\n) + expected = %(<select id="date_second" name="date[second]">\n).dup expected << %(<option value="">Seconds</option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18" selected="selected">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -809,7 +809,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_second_with_custom_prompt - expected = %(<select id="date_second" name="date[second]">\n) + expected = %(<select id="date_second" name="date[second]">\n).dup expected << %(<option value="">Choose seconds</option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18" selected="selected">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -817,7 +817,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_second_with_generic_with_css_classes - expected = %(<select id="date_second" name="date[second]" class="second">\n) + expected = %(<select id="date_second" name="date[second]" class="second">\n).dup expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18" selected="selected">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -825,7 +825,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_second_with_custom_with_css_classes - expected = %(<select id="date_second" name="date[second]" class="my-second">\n) + expected = %(<select id="date_second" name="date[second]" class="my-second">\n).dup expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18" selected="selected">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n) expected << "</select>\n" @@ -833,7 +833,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -858,7 +858,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_order - expected = %(<select id="date_first_month" name="date[first][month]">\n) + expected = %(<select id="date_first_month" name="date[first][month]">\n).dup expected << %(<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8" selected="selected">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n) expected << "</select>\n" @@ -875,7 +875,7 @@ class DateHelperTest < ActionView::TestCase def test_select_date_with_incomplete_order # Since the order is incomplete nothing will be shown - expected = %(<input id="date_first_year" name="date[first][year]" type="hidden" value="2003" />\n) + expected = %(<input id="date_first_year" name="date[first][year]" type="hidden" value="2003" />\n).dup expected << %(<input id="date_first_month" name="date[first][month]" type="hidden" value="8" />\n) expected << %(<input id="date_first_day" name="date[first][day]" type="hidden" value="1" />\n) @@ -883,7 +883,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_disabled - expected = %(<select id="date_first_year" name="date[first][year]" disabled="disabled">\n) + expected = %(<select id="date_first_year" name="date[first][year]" disabled="disabled">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -899,7 +899,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_no_start_year - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup (Date.today.year - 5).upto(Date.today.year + 1) do |y| if y == Date.today.year expected << %(<option value="#{y}" selected="selected">#{y}</option>\n) @@ -923,7 +923,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_no_end_year - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup 2003.upto(2008) do |y| if y == 2003 expected << %(<option value="#{y}" selected="selected">#{y}</option>\n) @@ -947,7 +947,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_no_start_or_end_year - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup (Date.today.year - 5).upto(Date.today.year + 5) do |y| if y == Date.today.year expected << %(<option value="#{y}" selected="selected">#{y}</option>\n) @@ -971,7 +971,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_zero_value - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup expected << %(<option value="2003">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -987,7 +987,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_zero_value_and_no_start_year - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup (Date.today.year - 5).upto(Date.today.year + 1) { |y| expected << %(<option value="#{y}">#{y}</option>\n) } expected << "</select>\n" @@ -1003,7 +1003,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_zero_value_and_no_end_year - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup last_year = Time.now.year + 5 2003.upto(last_year) { |y| expected << %(<option value="#{y}">#{y}</option>\n) } expected << "</select>\n" @@ -1020,7 +1020,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_zero_value_and_no_start_and_end_year - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup (Date.today.year - 5).upto(Date.today.year + 5) { |y| expected << %(<option value="#{y}">#{y}</option>\n) } expected << "</select>\n" @@ -1036,7 +1036,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_nil_value_and_no_start_and_end_year - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup (Date.today.year - 5).upto(Date.today.year + 5) { |y| expected << %(<option value="#{y}">#{y}</option>\n) } expected << "</select>\n" @@ -1052,7 +1052,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_html_options - expected = %(<select id="date_first_year" name="date[first][year]" class="selector">\n) + expected = %(<select id="date_first_year" name="date[first][year]" class="selector">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1068,7 +1068,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_separator - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1088,7 +1088,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_separator_and_discard_day - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1104,7 +1104,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_separator_discard_month_and_day - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1115,7 +1115,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_hidden - expected = %(<input id="date_first_year" name="date[first][year]" type="hidden" value="2003"/>\n) + expected = %(<input id="date_first_year" name="date[first][year]" type="hidden" value="2003"/>\n).dup expected << %(<input id="date_first_month" name="date[first][month]" type="hidden" value="8" />\n) expected << %(<input id="date_first_day" name="date[first][day]" type="hidden" value="16" />\n) @@ -1124,7 +1124,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_css_classes_option - expected = %(<select id="date_first_year" name="date[first][year]" class="year">\n) + expected = %(<select id="date_first_year" name="date[first][year]" class="year">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1140,7 +1140,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_custom_with_css_classes - expected = %(<select id="date_year" name="date[year]" class="my-year">\n) + expected = %(<select id="date_year" name="date[year]" class="my-year">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1156,7 +1156,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_css_classes_option_and_html_class_option - expected = %(<select id="date_first_year" name="date[first][year]" class="datetime optional year">\n) + expected = %(<select id="date_first_year" name="date[first][year]" class="datetime optional year">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1172,7 +1172,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_custom_with_css_classes_and_html_class_option - expected = %(<select id="date_year" name="date[year]" class="date optional my-year">\n) + expected = %(<select id="date_year" name="date[year]" class="date optional my-year">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1188,7 +1188,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_partial_with_css_classes_and_html_class_option - expected = %(<select id="date_year" name="date[year]" class="date optional">\n) + expected = %(<select id="date_year" name="date[year]" class="date optional">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1204,7 +1204,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_html_class_option - expected = %(<select id="date_year" name="date[year]" class="date optional custom-grid">\n) + expected = %(<select id="date_year" name="date[year]" class="date optional custom-grid">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1220,7 +1220,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_datetime - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1248,7 +1248,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_datetime_with_ampm - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1276,7 +1276,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_datetime_with_separators - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1304,7 +1304,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_datetime_with_nil_value_and_no_start_and_end_year - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup (Date.today.year - 5).upto(Date.today.year + 5) { |y| expected << %(<option value="#{y}">#{y}</option>\n) } expected << "</select>\n" @@ -1332,7 +1332,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_datetime_with_html_options - expected = %(<select id="date_first_year" name="date[first][year]" class="selector">\n) + expected = %(<select id="date_first_year" name="date[first][year]" class="selector">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1360,7 +1360,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_datetime_with_all_separators - expected = %(<select id="date_first_year" name="date[first][year]" class="selector">\n) + expected = %(<select id="date_first_year" name="date[first][year]" class="selector">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1396,7 +1396,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_datetime_with_default_prompt - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup expected << %(<option value="">Year</option>\n<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1425,7 +1425,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_datetime_with_custom_prompt - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup expected << %(<option value="">Choose year</option>\n<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1454,7 +1454,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_datetime_with_generic_with_css_classes - expected = %(<select id="date_year" name="date[year]" class="year">\n) + expected = %(<select id="date_year" name="date[year]" class="year">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1482,7 +1482,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_datetime_with_custom_with_css_classes - expected = %(<select id="date_year" name="date[year]" class="my-year">\n) + expected = %(<select id="date_year" name="date[year]" class="my-year">\n).dup expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1510,7 +1510,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_datetime_with_custom_hours - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup expected << %(<option value="">Choose year</option>\n<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) expected << "</select>\n" @@ -1539,7 +1539,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_datetime_with_hidden - expected = %(<input id="date_first_year" name="date[first][year]" type="hidden" value="2003" />\n) + expected = %(<input id="date_first_year" name="date[first][year]" type="hidden" value="2003" />\n).dup expected << %(<input id="date_first_month" name="date[first][month]" type="hidden" value="8" />\n) expected << %(<input id="date_first_day" name="date[first][day]" type="hidden" value="16" />\n) expected << %(<input id="date_first_hour" name="date[first][hour]" type="hidden" value="8" />\n) @@ -1551,7 +1551,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_time - expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n) + expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n).dup expected << %(<input name="date[month]" id="date_month" value="8" type="hidden" />\n) expected << %(<input name="date[day]" id="date_day" value="16" type="hidden" />\n) @@ -1570,7 +1570,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_time_with_ampm - expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n) + expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n).dup expected << %(<input name="date[month]" id="date_month" value="8" type="hidden" />\n) expected << %(<input name="date[day]" id="date_day" value="16" type="hidden" />\n) @@ -1588,7 +1588,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_time_with_separator - expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n) + expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n).dup expected << %(<input name="date[month]" id="date_month" value="8" type="hidden" />\n) expected << %(<input name="date[day]" id="date_day" value="16" type="hidden" />\n) expected << %(<select id="date_hour" name="date[hour]">\n) @@ -1606,7 +1606,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_time_with_seconds - expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n) + expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n).dup expected << %(<input name="date[month]" id="date_month" value="8" type="hidden" />\n) expected << %(<input name="date[day]" id="date_day" value="16" type="hidden" />\n) @@ -1630,7 +1630,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_time_with_seconds_and_separator - expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n) + expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n).dup expected << %(<input name="date[month]" id="date_month" value="8" type="hidden" />\n) expected << %(<input name="date[day]" id="date_day" value="16" type="hidden" />\n) @@ -1654,7 +1654,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_time_with_html_options - expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n) + expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n).dup expected << %(<input name="date[month]" id="date_month" value="8" type="hidden" />\n) expected << %(<input name="date[day]" id="date_day" value="16" type="hidden" />\n) @@ -1677,7 +1677,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_time_with_default_prompt - expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n) + expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n).dup expected << %(<input name="date[month]" id="date_month" value="8" type="hidden" />\n) expected << %(<input name="date[day]" id="date_day" value="16" type="hidden" />\n) @@ -1701,7 +1701,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_time_with_custom_prompt - expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n) + expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n).dup expected << %(<input name="date[month]" id="date_month" value="8" type="hidden" />\n) expected << %(<input name="date[day]" id="date_day" value="16" type="hidden" />\n) @@ -1726,7 +1726,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_time_with_generic_with_css_classes - expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n) + expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n).dup expected << %(<input name="date[month]" id="date_month" value="8" type="hidden" />\n) expected << %(<input name="date[day]" id="date_day" value="16" type="hidden" />\n) @@ -1750,7 +1750,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_time_with_custom_with_css_classes - expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n) + expected = %(<input name="date[year]" id="date_year" value="2003" type="hidden" />\n).dup expected << %(<input name="date[month]" id="date_month" value="8" type="hidden" />\n) expected << %(<input name="date[day]" id="date_day" value="16" type="hidden" />\n) @@ -1774,7 +1774,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_time_with_hidden - expected = %(<input id="date_first_year" name="date[first][year]" type="hidden" value="2003" />\n) + expected = %(<input id="date_first_year" name="date[first][year]" type="hidden" value="2003" />\n).dup expected << %(<input id="date_first_month" name="date[first][month]" type="hidden" value="8" />\n) expected << %(<input id="date_first_day" name="date[first][day]" type="hidden" value="16" />\n) expected << %(<input id="date_first_hour" name="date[first][hour]" type="hidden" value="8" />\n) @@ -1788,7 +1788,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Date.new(2004, 6, 15) - expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n} + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -1808,7 +1808,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Date.new(2004, 6, 15) - expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n} + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option selected="selected" value="2004">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -1828,7 +1828,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Date.new(2004, 6, 15) - expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n} + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option selected="selected" value="2004">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -1866,7 +1866,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Date.new(2004, 6, 15) - expected = "<input type=\"hidden\" id=\"post_written_on_3i\" name=\"post[written_on(3i)]\" value=\"1\" />\n" + expected = "<input type=\"hidden\" id=\"post_written_on_3i\" name=\"post[written_on(3i)]\" value=\"1\" />\n".dup expected << %{<select id="post_written_on_2i" name="post[written_on(2i)]">\n} expected << %{<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n} @@ -1883,7 +1883,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Date.new(2004, 2, 29) - expected = "<input type=\"hidden\" id=\"post_written_on_2i\" name=\"post[written_on(2i)]\" value=\"2\" />\n" + expected = "<input type=\"hidden\" id=\"post_written_on_2i\" name=\"post[written_on(2i)]\" value=\"2\" />\n".dup expected << "<input type=\"hidden\" id=\"post_written_on_3i\" name=\"post[written_on(3i)]\" value=\"1\" />\n" expected << %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n} @@ -1897,7 +1897,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Date.new(2004, 6, 15) - expected = "<input type=\"hidden\" id=\"post_written_on_3i\" name=\"post[written_on(3i)]\" value=\"1\" />\n" + expected = "<input type=\"hidden\" id=\"post_written_on_3i\" name=\"post[written_on(3i)]\" value=\"1\" />\n".dup expected << %{<select id="post_written_on_2i" name="post[written_on(2i)]">\n} expected << %{<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n} @@ -1916,7 +1916,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Date.new(2004, 6, 15) - expected = "<input type=\"hidden\" id=\"post_written_on_3i\" disabled=\"disabled\" name=\"post[written_on(3i)]\" value=\"1\" />\n" + expected = "<input type=\"hidden\" id=\"post_written_on_3i\" disabled=\"disabled\" name=\"post[written_on(3i)]\" value=\"1\" />\n".dup expected << %{<select id="post_written_on_2i" disabled="disabled" name="post[written_on(2i)]">\n} expected << %{<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n} @@ -1937,7 +1937,7 @@ class DateHelperTest < ActionView::TestCase concat f.date_select(:written_on) end - expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option selected="selected" value="2004">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n} + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option selected="selected" value="2004">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n}.dup expected << %{<select id="post_written_on_2i" name="post[written_on(2i)]">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option selected="selected" value="6">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n} expected << %{<select id="post_written_on_3i" name="post[written_on(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option selected="selected" value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n} @@ -1953,7 +1953,7 @@ class DateHelperTest < ActionView::TestCase concat f.date_select(:written_on) end - expected = %{<select id="post_#{id}_written_on_1i" name="post[#{id}][written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option selected="selected" value="2004">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n} + expected = %{<select id="post_#{id}_written_on_1i" name="post[#{id}][written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option selected="selected" value="2004">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n}.dup expected << %{<select id="post_#{id}_written_on_2i" name="post[#{id}][written_on(2i)]">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option selected="selected" value="6">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n} expected << %{<select id="post_#{id}_written_on_3i" name="post[#{id}][written_on(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option selected="selected" value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n} @@ -1969,7 +1969,7 @@ class DateHelperTest < ActionView::TestCase concat f.date_select(:written_on) end - expected = %{<select id="post_#{id}_written_on_1i" name="post[#{id}][written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option selected="selected" value="2004">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n} + expected = %{<select id="post_#{id}_written_on_1i" name="post[#{id}][written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option selected="selected" value="2004">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n}.dup expected << %{<select id="post_#{id}_written_on_2i" name="post[#{id}][written_on(2i)]">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option selected="selected" value="6">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n} expected << %{<select id="post_#{id}_written_on_3i" name="post[#{id}][written_on(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option selected="selected" value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n} @@ -1981,7 +1981,7 @@ class DateHelperTest < ActionView::TestCase @post.written_on = Date.new(2004, 6, 15) id = 456 - expected = %{<select id="post_456_written_on_1i" name="post[#{id}][written_on(1i)]">\n} + expected = %{<select id="post_456_written_on_1i" name="post[#{id}][written_on(1i)]">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -2001,7 +2001,7 @@ class DateHelperTest < ActionView::TestCase @post.written_on = Date.new(2004, 6, 15) id = 123 - expected = %{<select id="post_123_written_on_1i" name="post[#{id}][written_on(1i)]">\n} + expected = %{<select id="post_123_written_on_1i" name="post[#{id}][written_on(1i)]">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -2020,7 +2020,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Date.new(2004, 6, 15) - expected = %{<select id="post_written_on_3i" name="post[written_on(3i)]">\n} + expected = %{<select id="post_written_on_3i" name="post[written_on(3i)]">\n}.dup 1.upto(31) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 15}>#{i}</option>\n) } expected << "</select>\n" @@ -2040,7 +2040,7 @@ class DateHelperTest < ActionView::TestCase start_year = Time.now.year - 5 end_year = Time.now.year + 5 - expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n} + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n}.dup start_year.upto(end_year) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == Time.now.year}>#{i}</option>\n) } expected << "</select>\n" @@ -2060,7 +2060,7 @@ class DateHelperTest < ActionView::TestCase start_year = Time.now.year - 5 end_year = Time.now.year + 5 - expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n} + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n}.dup expected << "<option value=\"\"></option>\n" start_year.upto(end_year) { |i| expected << %(<option value="#{i}">#{i}</option>\n) } expected << "</select>\n" @@ -2104,7 +2104,7 @@ class DateHelperTest < ActionView::TestCase start_year = Time.now.year - 5 end_year = Time.now.year + 5 - expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n} + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n}.dup expected << "<option value=\"\"></option>\n" start_year.upto(end_year) { |i| expected << %(<option value="#{i}">#{i}</option>\n) } expected << "</select>\n" @@ -2136,7 +2136,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Date.new(2004, 6, 15) - expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n} + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -2155,7 +2155,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Date.new(2004, 6, 15) - expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]" class="selector">\n} + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]" class="selector">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -2179,7 +2179,7 @@ class DateHelperTest < ActionView::TestCase concat f.date_select(:written_on, {}, class: "selector") end - expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]" class="selector">\n} + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]" class="selector">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -2199,7 +2199,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Date.new(2004, 6, 15) - expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n} + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -2223,7 +2223,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Date.new(2004, 6, 15) - expected = %{<select id="post_written_on_3i" name="post[written_on(3i)]">\n} + expected = %{<select id="post_written_on_3i" name="post[written_on(3i)]">\n}.dup expected << %{<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n} expected << "</select>\n" @@ -2246,7 +2246,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Date.new(2004, 6, 15) - expected = %{<select id="post_written_on_3i" name="post[written_on(3i)]">\n} + expected = %{<select id="post_written_on_3i" name="post[written_on(3i)]">\n}.dup expected << %{<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n} expected << "</select>\n" @@ -2264,7 +2264,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Date.new(2004, 6, 15) - expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n} + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n}.dup expected << %{<option value="">Year</option>\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -2284,7 +2284,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Date.new(2004, 6, 15) - expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n} + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n}.dup expected << %{<option value="">Choose year</option>\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -2304,7 +2304,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Date.new(2004, 6, 15) - expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]" class="year">\n} + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]" class="year">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -2324,7 +2324,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Date.new(2004, 6, 15) - expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]" class="my-year">\n} + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]" class="my-year">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -2344,7 +2344,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n} + expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n}.dup expected << %{<input type="hidden" id="post_written_on_2i" name="post[written_on(2i)]" value="6" />\n} expected << %{<input type="hidden" id="post_written_on_3i" name="post[written_on(3i)]" value="15" />\n} @@ -2363,7 +2363,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n} + expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n}.dup expected << %{<input type="hidden" id="post_written_on_2i" name="post[written_on(2i)]" value="6" />\n} expected << %{<input type="hidden" id="post_written_on_3i" name="post[written_on(3i)]" value="15" />\n} @@ -2382,7 +2382,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="1" />\n} + expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="1" />\n}.dup expected << %{<input type="hidden" id="post_written_on_2i" name="post[written_on(2i)]" value="1" />\n} expected << %{<input type="hidden" id="post_written_on_3i" name="post[written_on(3i)]" value="1" />\n} @@ -2401,7 +2401,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) - expected = %(<select id="post_written_on_4i" name="post[written_on(4i)]">\n) + expected = %(<select id="post_written_on_4i" name="post[written_on(4i)]">\n).dup 0.upto(23) { |i| expected << %(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 15}>#{sprintf("%02d", i)}</option>\n) } expected << "</select>\n" expected << " : " @@ -2416,7 +2416,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n} + expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n}.dup expected << %{<input type="hidden" id="post_written_on_2i" name="post[written_on(2i)]" value="6" />\n} expected << %{<input type="hidden" id="post_written_on_3i" name="post[written_on(3i)]" value="15" />\n} @@ -2439,7 +2439,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n} + expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n}.dup expected << %{<input type="hidden" id="post_written_on_2i" name="post[written_on(2i)]" value="6" />\n} expected << %{<input type="hidden" id="post_written_on_3i" name="post[written_on(3i)]" value="15" />\n} @@ -2462,7 +2462,7 @@ class DateHelperTest < ActionView::TestCase concat f.time_select(:written_on, {}, class: "selector") end - expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n} + expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n}.dup expected << %{<input type="hidden" id="post_written_on_2i" name="post[written_on(2i)]" value="6" />\n} expected << %{<input type="hidden" id="post_written_on_3i" name="post[written_on(3i)]" value="15" />\n} @@ -2481,7 +2481,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n} + expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n}.dup expected << %{<input type="hidden" id="post_written_on_2i" name="post[written_on(2i)]" value="6" />\n} expected << %{<input type="hidden" id="post_written_on_3i" name="post[written_on(3i)]" value="15" />\n} @@ -2508,7 +2508,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n} + expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n}.dup expected << %{<input type="hidden" id="post_written_on_2i" name="post[written_on(2i)]" value="6" />\n} expected << %{<input type="hidden" id="post_written_on_3i" name="post[written_on(3i)]" value="15" />\n} @@ -2529,7 +2529,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n} + expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n}.dup expected << %{<input type="hidden" id="post_written_on_2i" name="post[written_on(2i)]" value="6" />\n} expected << %{<input type="hidden" id="post_written_on_3i" name="post[written_on(3i)]" value="15" />\n} @@ -2550,7 +2550,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n} + expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n}.dup expected << %{<input type="hidden" id="post_written_on_2i" name="post[written_on(2i)]" value="6" />\n} expected << %{<input type="hidden" id="post_written_on_3i" name="post[written_on(3i)]" value="15" />\n} @@ -2571,7 +2571,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n} + expected = %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n}.dup expected << %{<input type="hidden" id="post_written_on_2i" name="post[written_on(2i)]" value="6" />\n} expected << %{<input type="hidden" id="post_written_on_3i" name="post[written_on(3i)]" value="15" />\n} @@ -2592,7 +2592,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<input type="hidden" id="post_written_on_1i" disabled="disabled" name="post[written_on(1i)]" value="2004" />\n} + expected = %{<input type="hidden" id="post_written_on_1i" disabled="disabled" name="post[written_on(1i)]" value="2004" />\n}.dup expected << %{<input type="hidden" id="post_written_on_2i" disabled="disabled" name="post[written_on(2i)]" value="6" />\n} expected << %{<input type="hidden" id="post_written_on_3i" disabled="disabled" name="post[written_on(3i)]" value="15" />\n} @@ -2611,7 +2611,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = Time.local(2004, 6, 15, 16, 35) - expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n} + expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -2640,7 +2640,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = Time.local(2004, 6, 15, 16, 35) - expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n} + expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -2706,7 +2706,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new - expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n} + expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -2741,7 +2741,7 @@ class DateHelperTest < ActionView::TestCase concat f.datetime_select(:updated_at, {}, class: "selector") end - expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]" class="selector">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option selected="selected" value="2004">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n} + expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]" class="selector">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option selected="selected" value="2004">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n}.dup expected << %{<select id="post_updated_at_2i" name="post[updated_at(2i)]" class="selector">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option selected="selected" value="6">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n} expected << %{<select id="post_updated_at_3i" name="post[updated_at(3i)]" class="selector">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option selected="selected" value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n} expected << %{ — <select id="post_updated_at_4i" name="post[updated_at(4i)]" class="selector">\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option selected="selected" value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n} @@ -2754,7 +2754,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n} + expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -2807,7 +2807,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = nil - expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n} + expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n}.dup expected << %{<option value="">Year</option>\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -2836,7 +2836,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = nil - expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n} + expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n}.dup expected << %{<option value="">Choose year</option>\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -2865,7 +2865,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]" class="year">\n} + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]" class="year">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -2894,7 +2894,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]" class="my-year">\n} + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]" class="my-year">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -2920,7 +2920,7 @@ class DateHelperTest < ActionView::TestCase end def test_date_select_with_zero_value_and_no_start_year - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup (Date.today.year - 5).upto(Date.today.year + 1) { |y| expected << %(<option value="#{y}">#{y}</option>\n) } expected << "</select>\n" @@ -2936,7 +2936,7 @@ class DateHelperTest < ActionView::TestCase end def test_date_select_with_zero_value_and_no_end_year - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup last_year = Time.now.year + 5 2003.upto(last_year) { |y| expected << %(<option value="#{y}">#{y}</option>\n) } expected << "</select>\n" @@ -2953,7 +2953,7 @@ class DateHelperTest < ActionView::TestCase end def test_date_select_with_zero_value_and_no_start_and_end_year - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup (Date.today.year - 5).upto(Date.today.year + 5) { |y| expected << %(<option value="#{y}">#{y}</option>\n) } expected << "</select>\n" @@ -2969,7 +2969,7 @@ class DateHelperTest < ActionView::TestCase end def test_date_select_with_nil_value_and_no_start_and_end_year - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup (Date.today.year - 5).upto(Date.today.year + 5) { |y| expected << %(<option value="#{y}">#{y}</option>\n) } expected << "</select>\n" @@ -2985,7 +2985,7 @@ class DateHelperTest < ActionView::TestCase end def test_datetime_select_with_nil_value_and_no_start_and_end_year - expected = %(<select id="date_first_year" name="date[first][year]">\n) + expected = %(<select id="date_first_year" name="date[first][year]">\n).dup (Date.today.year - 5).upto(Date.today.year + 5) { |y| expected << %(<option value="#{y}">#{y}</option>\n) } expected << "</select>\n" @@ -3017,7 +3017,7 @@ class DateHelperTest < ActionView::TestCase @post.updated_at = Time.local(2004, 6, 15, 16, 35) id = 456 - expected = %{<select id="post_456_updated_at_1i" name="post[#{id}][updated_at(1i)]">\n} + expected = %{<select id="post_456_updated_at_1i" name="post[#{id}][updated_at(1i)]">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -3051,7 +3051,7 @@ class DateHelperTest < ActionView::TestCase concat f.datetime_select(:updated_at) end - expected = %{<select id="post_456_updated_at_1i" name="post[#{id}][updated_at(1i)]">\n} + expected = %{<select id="post_456_updated_at_1i" name="post[#{id}][updated_at(1i)]">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -3081,7 +3081,7 @@ class DateHelperTest < ActionView::TestCase @post.updated_at = Time.local(2004, 6, 15, 16, 35) id = @post.id - expected = %{<select id="post_123_updated_at_1i" name="post[#{id}][updated_at(1i)]">\n} + expected = %{<select id="post_123_updated_at_1i" name="post[#{id}][updated_at(1i)]">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" @@ -3110,7 +3110,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n} + expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n}.dup 1999.upto(2009) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 2004}>#{i}</option>\n) } expected << "</select>\n" expected << %{<select id="post_updated_at_2i" name="post[updated_at(2i)]">\n} @@ -3141,7 +3141,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<input type="hidden" id="post_updated_at_1i" name="post[updated_at(1i)]" value="2004" />\n} + expected = %{<input type="hidden" id="post_updated_at_1i" name="post[updated_at(1i)]" value="2004" />\n}.dup expected << %{<select id="post_updated_at_2i" name="post[updated_at(2i)]">\n} 1.upto(12) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 6}>#{Date::MONTHNAMES[i]}</option>\n) } expected << "</select>\n" @@ -3166,7 +3166,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n} + expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n}.dup 1999.upto(2009) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 2004}>#{i}</option>\n) } expected << "</select>\n" expected << %{<input type="hidden" id="post_updated_at_2i" name="post[updated_at(2i)]" value="6" />\n} @@ -3189,7 +3189,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<input type="hidden" id="post_updated_at_1i" name="post[updated_at(1i)]" value="2004" />\n} + expected = %{<input type="hidden" id="post_updated_at_1i" name="post[updated_at(1i)]" value="2004" />\n}.dup expected << %{<input type="hidden" id="post_updated_at_2i" name="post[updated_at(2i)]" value="6" />\n} expected << %{<input type="hidden" id="post_updated_at_3i" name="post[updated_at(3i)]" value="1" />\n} @@ -3208,7 +3208,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<input type="hidden" id="post_updated_at_1i" disabled="disabled" name="post[updated_at(1i)]" value="2004" />\n} + expected = %{<input type="hidden" id="post_updated_at_1i" disabled="disabled" name="post[updated_at(1i)]" value="2004" />\n}.dup expected << %{<input type="hidden" id="post_updated_at_2i" disabled="disabled" name="post[updated_at(2i)]" value="6" />\n} expected << %{<input type="hidden" id="post_updated_at_3i" disabled="disabled" name="post[updated_at(3i)]" value="1" />\n} @@ -3227,7 +3227,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n} + expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n}.dup 1999.upto(2009) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 2004}>#{i}</option>\n) } expected << "</select>\n" expected << %{<select id="post_updated_at_2i" name="post[updated_at(2i)]">\n} @@ -3244,7 +3244,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n} + expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n}.dup 1999.upto(2009) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 2004}>#{i}</option>\n) } expected << "</select>\n" expected << %{<select id="post_updated_at_2i" name="post[updated_at(2i)]">\n} @@ -3268,7 +3268,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<select id="post_updated_at_1i" disabled="disabled" name="post[updated_at(1i)]">\n} + expected = %{<select id="post_updated_at_1i" disabled="disabled" name="post[updated_at(1i)]">\n}.dup 1999.upto(2009) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 2004}>#{i}</option>\n) } expected << "</select>\n" expected << %{<select id="post_updated_at_2i" disabled="disabled" name="post[updated_at(2i)]">\n} @@ -3292,7 +3292,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<select id="post_updated_at_3i" name="post[updated_at(3i)]">\n} + expected = %{<select id="post_updated_at_3i" name="post[updated_at(3i)]">\n}.dup 1.upto(31) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 15}>#{i}</option>\n) } expected << "</select>\n" expected << %{<select id="post_updated_at_2i" name="post[updated_at(2i)]">\n} @@ -3319,7 +3319,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = Time.local(2004, 6, 15, 15, 16, 35) - expected = %{<input type="hidden" id="post_updated_at_1i" name="post[updated_at(1i)]" value="2004" />\n} + expected = %{<input type="hidden" id="post_updated_at_1i" name="post[updated_at(1i)]" value="2004" />\n}.dup expected << %{<select id="post_updated_at_3i" name="post[updated_at(3i)]">\n} 1.upto(31) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 15}>#{i}</option>\n) } expected << "</select>\n" @@ -3344,7 +3344,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = nil - expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n} + expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n}.dup 2001.upto(2011) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == 2006}>#{i}</option>\n) } expected << "</select>\n" expected << %{<select id="post_updated_at_2i" name="post[updated_at(2i)]">\n} @@ -3371,7 +3371,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = nil - expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n} + expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n}.dup expected << %(<option value=""></option>\n) (Time.now.year - 5).upto(Time.now.year + 5) { |i| expected << %(<option value="#{i}">#{i}</option>\n) } expected << "</select>\n" @@ -3391,7 +3391,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = nil - expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n} + expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n}.dup (Time.now.year - 5).upto(Time.now.year + 5) { |i| expected << %(<option value="#{i}"#{' selected="selected"' if i == Time.now.year}>#{i}</option>\n) } expected << "</select>\n" expected << %{<select id="post_updated_at_2i" name="post[updated_at(2i)]">\n} @@ -3418,7 +3418,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = Time.local(2004, 6, 15, 16, 35) - expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]" class="selector">\n} + expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]" class="selector">\n}.dup expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} expected << "</select>\n" diff --git a/actionview/test/template/form_helper/form_with_test.rb b/actionview/test/template/form_helper/form_with_test.rb index ecdd5ce672..c1a8181204 100644 --- a/actionview/test/template/form_helper/form_with_test.rb +++ b/actionview/test/template/form_helper/form_with_test.rb @@ -16,7 +16,7 @@ class FormWithActsLikeFormTagTest < FormWithTest method = options[:method] skip_enforcing_utf8 = options.fetch(:skip_enforcing_utf8, false) - "".tap do |txt| + "".dup.tap do |txt| unless skip_enforcing_utf8 txt << %{<input name="utf8" type="hidden" value="✓" />} end @@ -32,7 +32,7 @@ class FormWithActsLikeFormTagTest < FormWithTest method = method.to_s == "get" ? "get" : "post" - txt = %{<form accept-charset="UTF-8" action="#{action}"} + txt = %{<form accept-charset="UTF-8" action="#{action}"}.dup txt << %{ enctype="multipart/form-data"} if enctype txt << %{ data-remote="true"} unless local txt << %{ class="#{html_class}"} if html_class @@ -1642,7 +1642,7 @@ class FormWithActsLikeFormForTest < FormWithTest expected = 0 @post.comments.each do |comment| f.fields(:comments, model: comment) { |cf| - assert_equal cf.index, expected + assert_equal expected, cf.index expected += 1 } end @@ -1656,7 +1656,7 @@ class FormWithActsLikeFormForTest < FormWithTest expected = 0 @post.comments.each do |comment| f.fields(:comments, model: comment) { |cf| - assert_equal cf.index, expected + assert_equal expected, cf.index expected += 1 } end @@ -1669,7 +1669,7 @@ class FormWithActsLikeFormForTest < FormWithTest form_with(model: @post) do |f| expected = 0 f.fields(:comments, model: @post.comments) { |cf| - assert_equal cf.index, expected + assert_equal expected, cf.index expected += 1 } end @@ -1680,7 +1680,7 @@ class FormWithActsLikeFormForTest < FormWithTest form_with(model: @post) do |f| f.fields(:comments, model: Comment.new(321), child_index: "abc") { |cf| - assert_equal cf.index, "abc" + assert_equal "abc", cf.index } end end @@ -2194,9 +2194,9 @@ class FormWithActsLikeFormForTest < FormWithTest method = options[:method] if options.fetch(:skip_enforcing_utf8, false) - txt = "" + txt = "".dup else - txt = %{<input name="utf8" type="hidden" value="✓" />} + txt = %{<input name="utf8" type="hidden" value="✓" />}.dup end if method && !%w(get post).include?(method.to_s) @@ -2207,7 +2207,7 @@ class FormWithActsLikeFormForTest < FormWithTest end def form_text(action = "/", id = nil, html_class = nil, local = nil, multipart = nil, method = nil) - txt = %{<form accept-charset="UTF-8" action="#{action}"} + txt = %{<form accept-charset="UTF-8" action="#{action}"}.dup txt << %{ enctype="multipart/form-data"} if multipart txt << %{ data-remote="true"} unless local txt << %{ class="#{html_class}"} if html_class diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index b3a180b28a..b24f9ed3f0 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -2893,7 +2893,7 @@ class FormHelperTest < ActionView::TestCase expected = 0 @post.comments.each do |comment| f.fields_for(:comments, comment) { |cf| - assert_equal cf.index, expected + assert_equal expected, cf.index expected += 1 } end @@ -2907,7 +2907,7 @@ class FormHelperTest < ActionView::TestCase expected = 0 @post.comments.each do |comment| f.fields_for(:comments, comment) { |cf| - assert_equal cf.index, expected + assert_equal expected, cf.index expected += 1 } end @@ -2920,7 +2920,7 @@ class FormHelperTest < ActionView::TestCase form_for(@post) do |f| expected = 0 f.fields_for(:comments, @post.comments) { |cf| - assert_equal cf.index, expected + assert_equal expected, cf.index expected += 1 } end @@ -2931,7 +2931,7 @@ class FormHelperTest < ActionView::TestCase form_for(@post) do |f| f.fields_for(:comments, Comment.new(321), child_index: "abc") { |cf| - assert_equal cf.index, "abc" + assert_equal "abc", cf.index } end end @@ -3446,9 +3446,9 @@ class FormHelperTest < ActionView::TestCase method = options[:method] if options.fetch(:enforce_utf8, true) - txt = %{<input name="utf8" type="hidden" value="✓" />} + txt = %{<input name="utf8" type="hidden" value="✓" />}.dup else - txt = "" + txt = "".dup end if method && !%w(get post).include?(method.to_s) @@ -3459,7 +3459,7 @@ class FormHelperTest < ActionView::TestCase end def form_text(action = "/", id = nil, html_class = nil, remote = nil, multipart = nil, method = nil) - txt = %{<form accept-charset="UTF-8" action="#{action}"} + txt = %{<form accept-charset="UTF-8" action="#{action}"}.dup txt << %{ enctype="multipart/form-data"} if multipart txt << %{ data-remote="true"} if remote txt << %{ class="#{html_class}"} if html_class diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb index c13d0c32ae..7ac15db9fe 100644 --- a/actionview/test/template/form_tag_helper_test.rb +++ b/actionview/test/template/form_tag_helper_test.rb @@ -14,7 +14,7 @@ class FormTagHelperTest < ActionView::TestCase method = options[:method] enforce_utf8 = options.fetch(:enforce_utf8, true) - "".tap do |txt| + "".dup.tap do |txt| if enforce_utf8 txt << %{<input name="utf8" type="hidden" value="✓" />} end @@ -30,7 +30,7 @@ class FormTagHelperTest < ActionView::TestCase method = method.to_s == "get" ? "get" : "post" - txt = %{<form accept-charset="UTF-8" action="#{action}"} + txt = %{<form accept-charset="UTF-8" action="#{action}"}.dup txt << %{ enctype="multipart/form-data"} if enctype txt << %{ data-remote="true"} if remote txt << %{ class="#{html_class}"} if html_class diff --git a/actionview/test/template/javascript_helper_test.rb b/actionview/test/template/javascript_helper_test.rb index c7670b056b..67747a7a83 100644 --- a/actionview/test/template/javascript_helper_test.rb +++ b/actionview/test/template/javascript_helper_test.rb @@ -20,8 +20,8 @@ class JavaScriptHelperTest < ActionView::TestCase 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).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 %(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 %(dont <\\/close> tags), j(%(dont </close> tags)) end diff --git a/actionview/test/template/render_test.rb b/actionview/test/template/render_test.rb index 9999607067..1fd8b4fe1a 100644 --- a/actionview/test/template/render_test.rb +++ b/actionview/test/template/render_test.rb @@ -439,7 +439,7 @@ module RenderTestCases end CustomHandler = lambda do |template| - "@output_buffer = ''\n" \ + "@output_buffer = ''.dup\n" \ "@output_buffer << 'source: #{template.source.inspect}'\n" end @@ -583,7 +583,7 @@ module RenderTestCases 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!", type: :foo1), @view.render(inline: "Hello, World!", type: :foo2) + assert_equal @view.render(inline: "Hello, World!".dup, type: :foo1), @view.render(inline: "Hello, World!".dup, type: :foo2) ensure ActionView::Template.unregister_template_handler :foo1, :foo2 end diff --git a/actionview/test/template/streaming_render_test.rb b/actionview/test/template/streaming_render_test.rb index 6ce66a1275..41b9063417 100644 --- a/actionview/test/template/streaming_render_test.rb +++ b/actionview/test/template/streaming_render_test.rb @@ -17,7 +17,7 @@ class FiberedTest < ActiveSupport::TestCase def buffered_render(options) body = render_body(options) - string = "" + string = "".dup body.each do |piece| string << piece end diff --git a/actionview/test/template/template_test.rb b/actionview/test/template/template_test.rb index 9d31a98703..dd131f0246 100644 --- a/actionview/test/template/template_test.rb +++ b/actionview/test/template/template_test.rb @@ -53,7 +53,7 @@ class TestERBTemplate < ActiveSupport::TestCase end def new_template(body = "<%= hello %>", details = { format: :html }) - ActionView::Template.new(body, "hello template", details.fetch(:handler) { ERBHandler }, { virtual_path: "hello" }.merge!(details)) + ActionView::Template.new(body.dup, "hello template", details.fetch(:handler) { ERBHandler }, { virtual_path: "hello" }.merge!(details)) end def render(locals = {}) diff --git a/actionview/test/template/text_helper_test.rb b/actionview/test/template/text_helper_test.rb index 251c98230f..21ee4cc8e5 100644 --- a/actionview/test/template/text_helper_test.rb +++ b/actionview/test/template/text_helper_test.rb @@ -11,7 +11,7 @@ class TextHelperTest < ActionView::TestCase end def test_concat - self.output_buffer = "foo" + self.output_buffer = "foo".dup assert_equal "foobar", concat("bar") assert_equal "foobar", output_buffer end @@ -104,8 +104,8 @@ class TextHelperTest < ActionView::TestCase end def test_truncate_multibyte - 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) + 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) end def test_truncate_does_not_modify_the_options_hash @@ -325,7 +325,7 @@ class TextHelperTest < ActionView::TestCase end def test_excerpt_with_utf8 - 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)) + 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)) end def test_excerpt_does_not_modify_the_options_hash diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb index bdedbeba92..a087c5c0cd 100644 --- a/actionview/test/template/url_helper_test.rb +++ b/actionview/test/template/url_helper_test.rb @@ -539,7 +539,7 @@ class UrlHelperTest < ActiveSupport::TestCase def test_current_page_with_escaped_params_with_different_encoding @request = request_for_url("/") - @request.stub(:path, "/category/administra%c3%a7%c3%a3o".force_encoding(Encoding::ASCII_8BIT)) do + @request.stub(:path, "/category/administra%c3%a7%c3%a3o".dup.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 diff --git a/activejob/lib/active_job.rb b/activejob/lib/active_job.rb index 8b7aef65a2..79cad9457d 100644 --- a/activejob/lib/active_job.rb +++ b/activejob/lib/active_job.rb @@ -23,7 +23,7 @@ require "active_support" require "active_support/rails" -require "active_job/version" +require_relative "active_job/version" require "global_id" module ActiveJob diff --git a/activejob/lib/active_job/base.rb b/activejob/lib/active_job/base.rb index 18e8641e50..af76d019c4 100644 --- a/activejob/lib/active_job/base.rb +++ b/activejob/lib/active_job/base.rb @@ -1,13 +1,13 @@ -require "active_job/core" -require "active_job/queue_adapter" -require "active_job/queue_name" -require "active_job/queue_priority" -require "active_job/enqueuing" -require "active_job/execution" -require "active_job/callbacks" -require "active_job/exceptions" -require "active_job/logging" -require "active_job/translation" +require_relative "core" +require_relative "queue_adapter" +require_relative "queue_name" +require_relative "queue_priority" +require_relative "enqueuing" +require_relative "execution" +require_relative "callbacks" +require_relative "exceptions" +require_relative "logging" +require_relative "translation" module ActiveJob #:nodoc: # = Active Job diff --git a/activejob/lib/active_job/enqueuing.rb b/activejob/lib/active_job/enqueuing.rb index c73117e7f3..994645c62a 100644 --- a/activejob/lib/active_job/enqueuing.rb +++ b/activejob/lib/active_job/enqueuing.rb @@ -1,4 +1,4 @@ -require "active_job/arguments" +require_relative "arguments" module ActiveJob # Provides behavior for enqueuing jobs. diff --git a/activejob/lib/active_job/execution.rb b/activejob/lib/active_job/execution.rb index 94d30c8eaf..69486676d1 100644 --- a/activejob/lib/active_job/execution.rb +++ b/activejob/lib/active_job/execution.rb @@ -1,5 +1,5 @@ require "active_support/rescuable" -require "active_job/arguments" +require_relative "arguments" module ActiveJob module Execution diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md index 2916e5eabb..048c43f2c4 100644 --- a/activemodel/CHANGELOG.md +++ b/activemodel/CHANGELOG.md @@ -1,3 +1,7 @@ +* Add method `#merge!` for `ActiveModel::Errors`. + + *Jahfer Husain* + * Fix regression in numericality validator when comparing Decimal and Float input values with more scale than the schema. diff --git a/activemodel/lib/active_model.rb b/activemodel/lib/active_model.rb index a2892e9ea9..ba1d2fbd44 100644 --- a/activemodel/lib/active_model.rb +++ b/activemodel/lib/active_model.rb @@ -23,7 +23,7 @@ require "active_support" require "active_support/rails" -require "active_model/version" +require_relative "active_model/version" module ActiveModel extend ActiveSupport::Autoload diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 942b4fa9bb..76c23df541 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -93,6 +93,18 @@ module ActiveModel @details = other.details.dup end + # Merges the errors from <tt>other</tt>. + # + # other - The ActiveModel::Errors instance. + # + # Examples + # + # person.errors.merge!(other) + def merge!(other) + @messages.merge!(other.messages) { |_, ary1, ary2| ary1 + ary2 } + @details.merge!(other.details) { |_, ary1, ary2| ary1 + ary2 } + end + # Clear the error messages. # # person.errors.full_messages # => ["name cannot be nil"] diff --git a/activemodel/lib/active_model/type.rb b/activemodel/lib/active_model/type.rb index 095801d8f0..1741a67a4d 100644 --- a/activemodel/lib/active_model/type.rb +++ b/activemodel/lib/active_model/type.rb @@ -1,19 +1,19 @@ -require "active_model/type/helpers" -require "active_model/type/value" +require_relative "type/helpers" +require_relative "type/value" -require "active_model/type/big_integer" -require "active_model/type/binary" -require "active_model/type/boolean" -require "active_model/type/date" -require "active_model/type/date_time" -require "active_model/type/decimal" -require "active_model/type/float" -require "active_model/type/immutable_string" -require "active_model/type/integer" -require "active_model/type/string" -require "active_model/type/time" +require_relative "type/big_integer" +require_relative "type/binary" +require_relative "type/boolean" +require_relative "type/date" +require_relative "type/date_time" +require_relative "type/decimal" +require_relative "type/float" +require_relative "type/immutable_string" +require_relative "type/integer" +require_relative "type/string" +require_relative "type/time" -require "active_model/type/registry" +require_relative "type/registry" module ActiveModel module Type diff --git a/activemodel/lib/active_model/type/big_integer.rb b/activemodel/lib/active_model/type/big_integer.rb index 3b629682fe..f461d7041e 100644 --- a/activemodel/lib/active_model/type/big_integer.rb +++ b/activemodel/lib/active_model/type/big_integer.rb @@ -1,4 +1,4 @@ -require "active_model/type/integer" +require_relative "integer" module ActiveModel module Type diff --git a/activemodel/lib/active_model/type/date_time.rb b/activemodel/lib/active_model/type/date_time.rb index 5cb0077e45..8ad0daa9a6 100644 --- a/activemodel/lib/active_model/type/date_time.rb +++ b/activemodel/lib/active_model/type/date_time.rb @@ -10,6 +10,10 @@ module ActiveModel :datetime end + def serialize(value) + super(cast(value)) + end + private def cast_value(value) diff --git a/activemodel/lib/active_model/type/helpers.rb b/activemodel/lib/active_model/type/helpers.rb index 82cd9ebe98..1fe06ab3d5 100644 --- a/activemodel/lib/active_model/type/helpers.rb +++ b/activemodel/lib/active_model/type/helpers.rb @@ -1,4 +1,4 @@ -require "active_model/type/helpers/accepts_multiparameter_time" -require "active_model/type/helpers/numeric" -require "active_model/type/helpers/mutable" -require "active_model/type/helpers/time_value" +require_relative "helpers/accepts_multiparameter_time" +require_relative "helpers/numeric" +require_relative "helpers/mutable" +require_relative "helpers/time_value" diff --git a/activemodel/lib/active_model/type/string.rb b/activemodel/lib/active_model/type/string.rb index 850cab962b..2fc027d3c4 100644 --- a/activemodel/lib/active_model/type/string.rb +++ b/activemodel/lib/active_model/type/string.rb @@ -1,4 +1,4 @@ -require "active_model/type/immutable_string" +require_relative "immutable_string" module ActiveModel module Type diff --git a/activemodel/lib/active_model/validations/exclusion.rb b/activemodel/lib/active_model/validations/exclusion.rb index b7156ba802..d587079bd3 100644 --- a/activemodel/lib/active_model/validations/exclusion.rb +++ b/activemodel/lib/active_model/validations/exclusion.rb @@ -1,4 +1,4 @@ -require "active_model/validations/clusivity" +require_relative "clusivity" module ActiveModel module Validations diff --git a/activemodel/lib/active_model/validations/inclusion.rb b/activemodel/lib/active_model/validations/inclusion.rb index c6c5bae649..74dac3b7df 100644 --- a/activemodel/lib/active_model/validations/inclusion.rb +++ b/activemodel/lib/active_model/validations/inclusion.rb @@ -1,4 +1,4 @@ -require "active_model/validations/clusivity" +require_relative "clusivity" module ActiveModel module Validations diff --git a/activemodel/test/cases/dirty_test.rb b/activemodel/test/cases/dirty_test.rb index fdd18d7601..0242b96083 100644 --- a/activemodel/test/cases/dirty_test.rb +++ b/activemodel/test/cases/dirty_test.rb @@ -96,7 +96,7 @@ class DirtyTest < ActiveModel::TestCase end test "attribute mutation" do - @model.instance_variable_set("@name", "Yam") + @model.instance_variable_set("@name", "Yam".dup) assert !@model.name_changed? @model.name.replace("Hadad") assert !@model.name_changed? diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index 43aee5a814..7383b3e9b0 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -375,6 +375,18 @@ class ErrorsTest < ActiveModel::TestCase assert_equal [:name], person.errors.details.keys end + test "merge errors" do + errors = ActiveModel::Errors.new(Person.new) + errors.add(:name, :invalid) + + person = Person.new + person.errors.add(:name, :blank) + person.errors.merge!(errors) + + assert_equal({ name: ["can't be blank", "is invalid"] }, person.errors.messages) + assert_equal({ name: [{ error: :blank }, { error: :invalid }] }, person.errors.details) + end + test "errors are marshalable" do errors = ActiveModel::Errors.new(Person.new) errors.add(:name, :invalid) diff --git a/activemodel/test/cases/type/string_test.rb b/activemodel/test/cases/type/string_test.rb index 47d412e27e..5bf9fc3527 100644 --- a/activemodel/test/cases/type/string_test.rb +++ b/activemodel/test/cases/type/string_test.rb @@ -14,7 +14,7 @@ module ActiveModel test "cast strings are mutable" do type = Type::String.new - s = "foo" + s = "foo".dup assert_equal false, type.cast(s).frozen? assert_equal false, s.frozen? diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 824e9d4258..786bef7359 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,40 @@ +* Skip query caching when working with batches of records (`find_each`, `find_in_batches`, + `in_batches`). + + Previously, records would be fetched in batches, but all records would be retained in memory + until the end of the request or job. + + *Eugene Kenny* + +* Prevent errors raised by `sql.active_record` notification subscribers from being converted into + `ActiveRecord::StatementInvalid` exceptions. + + *Dennis Taylor* + +* Fix eager loading/preloading association with scope including joins. + + Fixes #28324. + + *Ryuta Kamizono* + +* Fix transactions to apply state to child transactions + + Previously if you had a nested transaction and the outer transaction was rolledback the record from the + inner transaction would still be marked as persisted. + + This change fixes that by applying the state of the parent transaction to the child transaction when the + parent transaction is rolledback. This will correctly mark records from the inner transaction as not persisted. + + *Eileen M. Uchitelle*, *Aaron Patterson* + +* Deprecate `set_state` method in `TransactionState` + + Deprecated the `set_state` method in favor of setting the state via specific methods. If you need to mark the + state of the transaction you can now use `rollback!`, `commit!` or `nullify!` instead of + `set_state(:rolledback)`, `set_state(:committed)`, or `set_state(nil)`. + + *Eileen M. Uchitelle*, *Aaron Patterson* + * Deprecate delegating to `arel` in `Relation`. *Ryuta Kamizono* @@ -6,7 +43,7 @@ *Ryuta Kamizono* -* Query cache was unavailable when entering the ActiveRecord::Base.cache block +* Query cache was unavailable when entering the `ActiveRecord::Base.cache` block without being connected. *Tsukasa Oishi* @@ -40,7 +77,7 @@ *bogdanvlviv* * Fix destroying existing object does not work well when optimistic locking enabled and - `locking column` is null in the database. + `locking_column` is null in the database. *bogdanvlviv* diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb index 29f49c6195..25d5e87317 100644 --- a/activerecord/lib/active_record.rb +++ b/activerecord/lib/active_record.rb @@ -26,8 +26,8 @@ require "active_support/rails" require "active_model" require "arel" -require "active_record/version" -require "active_record/attribute_set" +require_relative "active_record/version" +require_relative "active_record/attribute_set" module ActiveRecord extend ActiveSupport::Autoload diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index f05a122544..e782196ce6 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1,7 +1,7 @@ require "active_support/core_ext/enumerable" require "active_support/core_ext/string/conversions" require "active_support/core_ext/module/remove_method" -require "active_record/errors" +require_relative "errors" module ActiveRecord class AssociationNotFoundError < ConfigurationError #:nodoc: diff --git a/activerecord/lib/active_record/associations/builder/collection_association.rb b/activerecord/lib/active_record/associations/builder/collection_association.rb index 1fb8f76f2e..c58b7d8160 100644 --- a/activerecord/lib/active_record/associations/builder/collection_association.rb +++ b/activerecord/lib/active_record/associations/builder/collection_association.rb @@ -1,4 +1,4 @@ -require "active_record/associations" +require_relative "../../associations" module ActiveRecord::Associations::Builder # :nodoc: class CollectionAssociation < Association #:nodoc: diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index bc66194aef..04cdcb6a7f 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -198,8 +198,7 @@ module ActiveRecord def table_alias_for(reflection, parent, join) name = "#{reflection.plural_name}_#{parent.table_name}" - name << "_join" if join - name + join ? "#{name}_join" : name end def walk(left, right) diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb index 005410d598..b14ddfeeeb 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -1,4 +1,4 @@ -require "active_record/associations/join_dependency/join_part" +require_relative "join_part" module ActiveRecord module Associations @@ -34,13 +34,19 @@ module ActiveRecord table = tables.shift klass = reflection.klass - join_scope = reflection.join_scope(table, foreign_table, foreign_klass) - - binds.concat join_scope.bound_attributes - constraint = join_scope.arel.constraints + constraint = reflection.build_join_constraint(table, foreign_table) joins << table.create_join(table, table.create_on(constraint), join_type) + join_scope = reflection.join_scope(table, foreign_klass) + + if join_scope.arel.constraints.any? + binds.concat join_scope.bound_attributes + joins.concat join_scope.arel.join_sources + right = joins.last.right + right.expr = right.expr.and(join_scope.arel.constraints) + end + # The current table in this iteration becomes the foreign table in the next foreign_table, foreign_klass = table, klass end diff --git a/activerecord/lib/active_record/associations/join_dependency/join_base.rb b/activerecord/lib/active_record/associations/join_dependency/join_base.rb index fca20514d1..6e0963425d 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_base.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_base.rb @@ -1,4 +1,4 @@ -require "active_record/associations/join_dependency/join_part" +require_relative "join_part" module ActiveRecord module Associations diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb index 208d1b2670..a18994cec4 100644 --- a/activerecord/lib/active_record/associations/preloader.rb +++ b/activerecord/lib/active_record/associations/preloader.rb @@ -54,8 +54,6 @@ module ActiveRecord autoload :BelongsTo, "active_record/associations/preloader/belongs_to" end - NULL_RELATION = Struct.new(:values, :where_clause, :joins_values).new({}, Relation::WhereClause.empty, []) - # Eager loads the named associations for the given Active Record record(s). # # In this description, 'association name' shall refer to the name passed @@ -93,7 +91,6 @@ module ActiveRecord def preload(records, associations, preload_scope = nil) records = Array.wrap(records).compact.uniq associations = Array.wrap(associations) - preload_scope = preload_scope || NULL_RELATION if records.empty? [] diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb index 63ef3f2d8c..85343040db 100644 --- a/activerecord/lib/active_record/associations/preloader/association.rb +++ b/activerecord/lib/active_record/associations/preloader/association.rb @@ -11,7 +11,6 @@ module ActiveRecord @reflection = reflection @preload_scope = preload_scope @model = owners.first && owners.first.class - @scope = nil @preloaded_records = [] end @@ -23,29 +22,11 @@ module ActiveRecord raise NotImplementedError end - def scope - @scope ||= build_scope - end - - def records_for(ids) - scope.where(association_key_name => ids) - end - - def table - klass.arel_table - end - # The name of the key on the associated records def association_key_name raise NotImplementedError end - # This is overridden by HABTM as the condition should be on the foreign_key column in - # the join table - def association_key - klass.arel_attribute(association_key_name, table) - end - # The name of the key on the model which declares the association def owner_key_name raise NotImplementedError @@ -114,54 +95,35 @@ module ActiveRecord # Make several smaller queries if necessary or make one query if the adapter supports it slices = owner_keys.each_slice(klass.connection.in_clause_length || owner_keys.size) @preloaded_records = slices.flat_map do |slice| - records_for(slice).load(&block) + records_for(slice, &block) end @preloaded_records.group_by do |record| convert_key(record[association_key_name]) end end + def records_for(ids, &block) + scope.where(association_key_name => ids).load(&block) + end + + def scope + @scope ||= build_scope + end + def reflection_scope @reflection_scope ||= reflection.scope_for(klass) end def build_scope - scope = klass.unscoped - - values = reflection_scope.values - preload_values = preload_scope.values - - scope.where_clause = reflection_scope.where_clause + preload_scope.where_clause - scope.references_values = Array(values[:references]) + Array(preload_values[:references]) - - if preload_values[:select] || values[:select] - scope._select!(preload_values[:select] || values[:select]) - end - scope.includes! preload_values[:includes] || values[:includes] - if preload_scope.joins_values.any? - scope.joins!(preload_scope.joins_values) - else - scope.joins!(reflection_scope.joins_values) - end - - if order_values = preload_values[:order] || values[:order] - scope.order!(order_values) - end - - if preload_values[:reordering] || values[:reordering] - scope.reordering_value = true - end - - if preload_values[:readonly] || values[:readonly] - scope.readonly! - end + scope = klass.default_scoped - if options[:as] - scope.where!(klass.table_name => { reflection.type => model.base_class.sti_name }) + if reflection.type + scope.where!(reflection.type => model.base_class.sti_name) end - scope.unscope_values = Array(values[:unscope]) + Array(preload_values[:unscope]) - klass.default_scoped.merge(scope) + scope.merge!(reflection_scope) + scope.merge!(preload_scope) if preload_scope + scope end end end diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb index 34587fd3f5..0999746cd5 100644 --- a/activerecord/lib/active_record/associations/preloader/through_association.rb +++ b/activerecord/lib/active_record/associations/preloader/through_association.rb @@ -79,17 +79,24 @@ module ActiveRecord def through_scope scope = through_reflection.klass.unscoped + values = reflection_scope.values if options[:source_type] scope.where! reflection.foreign_type => options[:source_type] else unless reflection_scope.where_clause.empty? - scope.includes_values = Array(reflection_scope.values[:includes] || options[:source]) + scope.includes_values = Array(values[:includes] || options[:source]) scope.where_clause = reflection_scope.where_clause + if joins = values[:joins] + scope.joins!(source_reflection.name => joins) + end + if left_outer_joins = values[:left_outer_joins] + scope.left_outer_joins!(source_reflection.name => left_outer_joins) + end end - scope.references! reflection_scope.values[:references] - if scope.eager_loading? && order_values = reflection_scope.values[:order] + scope.references! values[:references] + if scope.eager_loading? && order_values = values[:order] scope = scope.order(order_values) end end diff --git a/activerecord/lib/active_record/attribute/user_provided_default.rb b/activerecord/lib/active_record/attribute/user_provided_default.rb index 57f8bbed76..c4e731fb28 100644 --- a/activerecord/lib/active_record/attribute/user_provided_default.rb +++ b/activerecord/lib/active_record/attribute/user_provided_default.rb @@ -1,4 +1,4 @@ -require "active_record/attribute" +require_relative "../attribute" module ActiveRecord class Attribute # :nodoc: diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb index 76987fb8f4..8c58e63931 100644 --- a/activerecord/lib/active_record/attribute_methods/dirty.rb +++ b/activerecord/lib/active_record/attribute_methods/dirty.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true require "active_support/core_ext/module/attribute_accessors" -require "active_record/attribute_mutation_tracker" +require_relative "../attribute_mutation_tracker" module ActiveRecord module AttributeMethods @@ -80,7 +80,7 @@ module ActiveRecord clear_mutation_trackers end - def raw_write_attribute(attr_name, *) + def write_attribute_without_type_cast(attr_name, *) result = super clear_attribute_change(attr_name) result diff --git a/activerecord/lib/active_record/attribute_methods/primary_key.rb b/activerecord/lib/active_record/attribute_methods/primary_key.rb index b9b2acff37..081aad434d 100644 --- a/activerecord/lib/active_record/attribute_methods/primary_key.rb +++ b/activerecord/lib/active_record/attribute_methods/primary_key.rb @@ -21,7 +21,7 @@ module ActiveRecord # Sets the primary key value. def id=(value) sync_with_transaction_state - write_attribute(self.class.primary_key, value) if self.class.primary_key + _write_attribute(self.class.primary_key, value) if self.class.primary_key end # Queries the primary key value. diff --git a/activerecord/lib/active_record/attribute_methods/write.rb b/activerecord/lib/active_record/attribute_methods/write.rb index 75c5a1a600..54b673c72e 100644 --- a/activerecord/lib/active_record/attribute_methods/write.rb +++ b/activerecord/lib/active_record/attribute_methods/write.rb @@ -17,7 +17,7 @@ module ActiveRecord generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1 def __temp__#{safe_name}=(value) name = ::ActiveRecord::AttributeMethods::AttrNames::ATTR_#{safe_name} - write_attribute(name, value) + _write_attribute(name, value) end alias_method #{(name + '=').inspect}, :__temp__#{safe_name}= undef_method :__temp__#{safe_name}= @@ -36,20 +36,26 @@ module ActiveRecord end name = self.class.primary_key if name == "id".freeze && self.class.primary_key - @attributes.write_from_user(name, value) - value + _write_attribute(name, value) end - def raw_write_attribute(attr_name, value) # :nodoc: - name = attr_name.to_s - @attributes.write_cast_value(name, value) + # This method exists to avoid the expensive primary_key check internally, without + # breaking compatibility with the write_attribute API + def _write_attribute(attr_name, value) # :nodoc: + @attributes.write_from_user(attr_name.to_s, value) value end private + def write_attribute_without_type_cast(attr_name, value) + name = attr_name.to_s + @attributes.write_cast_value(name, value) + value + end + # Handle *= for method_missing. def attribute=(attribute_name, value) - write_attribute(attribute_name, value) + _write_attribute(attribute_name, value) end end end diff --git a/activerecord/lib/active_record/attribute_mutation_tracker.rb b/activerecord/lib/active_record/attribute_mutation_tracker.rb index 4de993e169..a01a58f8a5 100644 --- a/activerecord/lib/active_record/attribute_mutation_tracker.rb +++ b/activerecord/lib/active_record/attribute_mutation_tracker.rb @@ -26,6 +26,7 @@ module ActiveRecord end def change_to_attribute(attr_name) + attr_name = attr_name.to_s if changed?(attr_name) [attributes[attr_name].original_value, attributes.fetch_value(attr_name)] end @@ -44,7 +45,7 @@ module ActiveRecord end def changed_in_place?(attr_name) - attributes[attr_name].changed_in_place? + attributes[attr_name.to_s].changed_in_place? end def forget_change(attr_name) @@ -54,7 +55,7 @@ module ActiveRecord end def original_value(attr_name) - attributes[attr_name].original_value + attributes[attr_name.to_s].original_value end def force_change(attr_name) diff --git a/activerecord/lib/active_record/attribute_set.rb b/activerecord/lib/active_record/attribute_set.rb index 01f9d815d5..6399e3de70 100644 --- a/activerecord/lib/active_record/attribute_set.rb +++ b/activerecord/lib/active_record/attribute_set.rb @@ -1,5 +1,5 @@ -require "active_record/attribute_set/builder" -require "active_record/attribute_set/yaml_encoder" +require_relative "attribute_set/builder" +require_relative "attribute_set/yaml_encoder" module ActiveRecord class AttributeSet # :nodoc: diff --git a/activerecord/lib/active_record/attribute_set/builder.rb b/activerecord/lib/active_record/attribute_set/builder.rb index 2f624d32af..abe22b9ae4 100644 --- a/activerecord/lib/active_record/attribute_set/builder.rb +++ b/activerecord/lib/active_record/attribute_set/builder.rb @@ -1,4 +1,4 @@ -require "active_record/attribute" +require_relative "../attribute" module ActiveRecord class AttributeSet # :nodoc: diff --git a/activerecord/lib/active_record/attributes.rb b/activerecord/lib/active_record/attributes.rb index 475b9beec4..dde22bcdaa 100644 --- a/activerecord/lib/active_record/attributes.rb +++ b/activerecord/lib/active_record/attributes.rb @@ -1,4 +1,4 @@ -require "active_record/attribute/user_provided_default" +require_relative "attribute/user_provided_default" module ActiveRecord # See ActiveRecord::Attributes::ClassMethods for documentation diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index ac1aa2df45..f0e455478a 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -13,14 +13,14 @@ require "active_support/core_ext/kernel/singleton_class" require "active_support/core_ext/module/introspection" require "active_support/core_ext/object/duplicable" require "active_support/core_ext/class/subclasses" -require "active_record/attribute_decorators" -require "active_record/define_callbacks" -require "active_record/errors" -require "active_record/log_subscriber" -require "active_record/explain_subscriber" -require "active_record/relation/delegation" -require "active_record/attributes" -require "active_record/type_caster" +require_relative "attribute_decorators" +require_relative "define_callbacks" +require_relative "errors" +require_relative "log_subscriber" +require_relative "explain_subscriber" +require_relative "relation/delegation" +require_relative "attributes" +require_relative "type_caster" module ActiveRecord #:nodoc: # = Active Record diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index 61bf5477aa..627b753f01 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -679,7 +679,7 @@ module ActiveRecord # 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" + msg = "could not obtain ownership of all database connections in #{checkout_timeout} seconds".dup thread_report = [] @connections.each do |conn| diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb index 93f4529202..8865e7c703 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb @@ -22,7 +22,7 @@ module ActiveRecord private def visit_AlterTable(o) - sql = "ALTER TABLE #{quote_table_name(o.name)} " + sql = "ALTER TABLE #{quote_table_name(o.name)} ".dup 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(" ") @@ -30,17 +30,17 @@ module ActiveRecord def visit_ColumnDefinition(o) o.sql_type = type_to_sql(o.type, o.options) - column_sql = "#{quote_column_name(o.name)} #{o.sql_type}" + column_sql = "#{quote_column_name(o.name)} #{o.sql_type}".dup add_column_options!(column_sql, column_options(o)) unless o.type == :primary_key column_sql end def visit_AddColumnDefinition(o) - "ADD #{accept(o.column)}" + "ADD #{accept(o.column)}".dup end def visit_TableDefinition(o) - create_sql = "CREATE#{' TEMPORARY' if o.temporary} TABLE #{quote_table_name(o.name)} " + create_sql = "CREATE#{' TEMPORARY' if o.temporary} TABLE #{quote_table_name(o.name)} ".dup statements = o.columns.map { |c| accept c } statements << accept(o.primary_keys) if o.primary_keys diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 41d900733a..475463c4fd 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -1,4 +1,4 @@ -require "active_record/migration/join_table" +require_relative "../../migration/join_table" require "active_support/core_ext/string/access" require "digest" @@ -1348,7 +1348,7 @@ module ActiveRecord sm_table = quote_table_name(ActiveRecord::SchemaMigration.table_name) if versions.is_a?(Array) - sql = "INSERT INTO #{sm_table} (version) VALUES\n" + sql = "INSERT INTO #{sm_table} (version) VALUES\n".dup sql << versions.map { |v| "(#{quote(v)})" }.join(",\n") sql << ";\n\n" sql diff --git a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb index 19b7821494..f63d09039f 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb @@ -1,10 +1,13 @@ module ActiveRecord module ConnectionAdapters class TransactionState - VALID_STATES = Set.new([:committed, :rolledback, nil]) - def initialize(state = nil) @state = state + @children = [] + end + + def add_child(state) + @children << state end def finalized? @@ -19,15 +22,43 @@ module ActiveRecord @state == :rolledback end + def fully_completed? + completed? + end + def completed? committed? || rolledback? end def set_state(state) - unless VALID_STATES.include?(state) + ActiveSupport::Deprecation.warn(<<-MSG.squish) + The set_state method is deprecated and will be removed in + Rails 6.0. Please use rollback! or commit! to set transaction + state directly. + MSG + case state + when :rolledback + rollback! + when :committed + commit! + when nil + nullify! + else raise ArgumentError, "Invalid transaction state: #{state}" end - @state = state + end + + def rollback! + @children.each { |c| c.rollback! } + @state = :rolledback + end + + def commit! + @state = :committed + end + + def nullify! + @state = nil end end @@ -57,7 +88,7 @@ module ActiveRecord end def rollback - @state.set_state(:rolledback) + @state.rollback! end def rollback_records @@ -72,7 +103,7 @@ module ActiveRecord end def commit - @state.set_state(:committed) + @state.commit! end def before_commit_records @@ -100,8 +131,11 @@ module ActiveRecord end class SavepointTransaction < Transaction - def initialize(connection, savepoint_name, options, *args) + def initialize(connection, savepoint_name, parent_transaction, options, *args) super(connection, options, *args) + + parent_transaction.state.add_child(@state) + if options[:isolation] raise ActiveRecord::TransactionIsolationError, "cannot set transaction isolation in a nested transaction" end @@ -155,7 +189,7 @@ module ActiveRecord if @stack.empty? RealTransaction.new(@connection, options, run_commit_callbacks: run_commit_callbacks) else - SavepointTransaction.new(@connection, "active_record_#{@stack.size}", options, + SavepointTransaction.new(@connection, "active_record_#{@stack.size}", @stack.last, options, run_commit_callbacks: run_commit_callbacks) end diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 85d6fbe8b3..30b29e7007 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -1,9 +1,9 @@ -require "active_record/type" -require "active_record/connection_adapters/determine_if_preparable_visitor" -require "active_record/connection_adapters/schema_cache" -require "active_record/connection_adapters/sql_type_metadata" -require "active_record/connection_adapters/abstract/schema_dumper" -require "active_record/connection_adapters/abstract/schema_creation" +require_relative "../type" +require_relative "determine_if_preparable_visitor" +require_relative "schema_cache" +require_relative "sql_type_metadata" +require_relative "abstract/schema_dumper" +require_relative "abstract/schema_creation" require "arel/collectors/bind" require "arel/collectors/sql_string" @@ -147,7 +147,7 @@ module ActiveRecord # this method must only be called while holding connection pool's mutex def lease if in_use? - msg = "Cannot lease connection, " + msg = "Cannot lease connection, ".dup if @owner == Thread.current msg << "it is already leased by the current thread." else @@ -576,12 +576,14 @@ module ActiveRecord type_casted_binds: type_casted_binds, statement_name: statement_name, connection_id: object_id) do + begin @lock.synchronize do yield end + rescue => e + raise translate_exception_class(e, sql) end - rescue => e - raise translate_exception_class(e, sql) + end end def translate_exception(exception, message) diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 6a907699e9..06976aa769 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -1,13 +1,13 @@ -require "active_record/connection_adapters/abstract_adapter" -require "active_record/connection_adapters/statement_pool" -require "active_record/connection_adapters/mysql/column" -require "active_record/connection_adapters/mysql/explain_pretty_printer" -require "active_record/connection_adapters/mysql/quoting" -require "active_record/connection_adapters/mysql/schema_creation" -require "active_record/connection_adapters/mysql/schema_definitions" -require "active_record/connection_adapters/mysql/schema_dumper" -require "active_record/connection_adapters/mysql/schema_statements" -require "active_record/connection_adapters/mysql/type_metadata" +require_relative "abstract_adapter" +require_relative "statement_pool" +require_relative "mysql/column" +require_relative "mysql/explain_pretty_printer" +require_relative "mysql/quoting" +require_relative "mysql/schema_creation" +require_relative "mysql/schema_definitions" +require_relative "mysql/schema_dumper" +require_relative "mysql/schema_statements" +require_relative "mysql/type_metadata" require "active_support/core_ext/string/strip" @@ -59,12 +59,12 @@ module ActiveRecord @statements = StatementPool.new(self.class.type_cast_config_to_integer(config[:statement_limit])) if version < "5.1.10" - raise "Your version of MySQL (#{full_version.match(/^\d+\.\d+\.\d+/)[0]}) is too old. Active Record supports MySQL >= 5.1.10." + raise "Your version of MySQL (#{version_string}) is too old. Active Record supports MySQL >= 5.1.10." end end def version #:nodoc: - @version ||= Version.new(full_version.match(/^\d+\.\d+\.\d+/)[0]) + @version ||= Version.new(version_string) end def mariadb? # :nodoc: @@ -132,7 +132,7 @@ module ActiveRecord end def index_algorithms - { default: "ALGORITHM = DEFAULT", copy: "ALGORITHM = COPY", inplace: "ALGORITHM = INPLACE" } + { default: "ALGORITHM = DEFAULT".dup, copy: "ALGORITHM = COPY".dup, inplace: "ALGORITHM = INPLACE".dup } end # HELPER METHODS =========================================== @@ -379,7 +379,7 @@ module ActiveRecord 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}" + sql = "CREATE #{index_type} INDEX #{quote_column_name(index_name)} #{index_using} ON #{quote_table_name(table_name)} (#{index_columns}) #{index_algorithm}".dup execute add_sql_comment!(sql, comment) end @@ -464,7 +464,7 @@ module ActiveRecord super end - sql << " unsigned" if unsigned && type != :primary_key + sql = "#{sql} unsigned" if unsigned && type != :primary_key sql end @@ -778,7 +778,7 @@ module ActiveRecord # http://dev.mysql.com/doc/refman/5.7/en/set-statement.html#id944430 # (trailing comma because variable_assignments will always have content) if @config[:encoding] - encoding = "NAMES #{@config[:encoding]}" + encoding = "NAMES #{@config[:encoding]}".dup encoding << " COLLATE #{@config[:collation]}" if @config[:collation] encoding << ", " end @@ -854,7 +854,8 @@ module ActiveRecord end end - class MysqlJson < Type::Json # :nodoc: + def version_string + full_version.match(/^(?:5\.5\.5-)?(\d+\.\d+\.\d+)/)[1] end class MysqlString < Type::String # :nodoc: diff --git a/activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb b/activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb index 083cd6340f..eea4984680 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb @@ -16,7 +16,7 @@ module ActiveRecord end def visit_ChangeColumnDefinition(o) - change_column_sql = "CHANGE #{quote_column_name(o.name)} #{accept(o.column)}" + change_column_sql = "CHANGE #{quote_column_name(o.name)} #{accept(o.column)}".dup add_column_position!(change_column_sql, column_options(o.column)) end @@ -63,7 +63,7 @@ module ActiveRecord 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})", comment) + add_sql_comment!("#{index_type} INDEX #{quote_column_name(index_name)} #{index_using} (#{index_columns})".dup, comment) end end end diff --git a/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb b/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb index eff96e329f..a46d9f8cbb 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb @@ -53,7 +53,7 @@ module ActiveRecord end def extract_expression_for_virtual_column(column) - if mariadb? + if mariadb? && version < "10.2.5" create_table_info = create_table_info(column.table_name) if %r/#{quote_column_name(column.name)} #{Regexp.quote(column.sql_type)}(?: COLLATE \w+)? AS \((?<expression>.+?)\) #{column.extra}/ =~ create_table_info $~[:expression].inspect diff --git a/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb index fc57e41fc9..24f8ff6367 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb @@ -73,8 +73,8 @@ module ActiveRecord def new_column_from_field(table_name, field) type_metadata = fetch_type_metadata(field[:Type], field[:Extra]) - if type_metadata.type == :datetime && field[:Default] == "CURRENT_TIMESTAMP" - default, default_function = nil, field[:Default] + if type_metadata.type == :datetime && /\ACURRENT_TIMESTAMP(?:\(\))?\z/i.match?(field[:Default]) + default, default_function = nil, "CURRENT_TIMESTAMP" else default, default_function = field[:Default], nil end @@ -102,7 +102,7 @@ module ActiveRecord def data_source_sql(name = nil, type: nil) scope = quoted_scope(name, type: type) - sql = "SELECT table_name FROM information_schema.tables" + sql = "SELECT table_name FROM information_schema.tables".dup sql << " WHERE table_schema = #{scope[:schema]}" sql << " AND table_name = #{scope[:name]}" if scope[:name] sql << " AND table_type = #{scope[:type]}" if scope[:type] diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb index af55cfe2f6..c5c0a071e7 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb @@ -1,5 +1,5 @@ -require "active_record/connection_adapters/abstract_mysql_adapter" -require "active_record/connection_adapters/mysql/database_statements" +require_relative "abstract_mysql_adapter" +require_relative "mysql/database_statements" gem "mysql2", ">= 0.3.18", "< 0.5" require "mysql2" diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb index 4098250f3e..6666622c08 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb @@ -1,26 +1,25 @@ -require "active_record/connection_adapters/postgresql/oid/array" -require "active_record/connection_adapters/postgresql/oid/bit" -require "active_record/connection_adapters/postgresql/oid/bit_varying" -require "active_record/connection_adapters/postgresql/oid/bytea" -require "active_record/connection_adapters/postgresql/oid/cidr" -require "active_record/connection_adapters/postgresql/oid/date_time" -require "active_record/connection_adapters/postgresql/oid/decimal" -require "active_record/connection_adapters/postgresql/oid/enum" -require "active_record/connection_adapters/postgresql/oid/hstore" -require "active_record/connection_adapters/postgresql/oid/inet" -require "active_record/connection_adapters/postgresql/oid/json" -require "active_record/connection_adapters/postgresql/oid/jsonb" -require "active_record/connection_adapters/postgresql/oid/money" -require "active_record/connection_adapters/postgresql/oid/oid" -require "active_record/connection_adapters/postgresql/oid/point" -require "active_record/connection_adapters/postgresql/oid/legacy_point" -require "active_record/connection_adapters/postgresql/oid/range" -require "active_record/connection_adapters/postgresql/oid/specialized_string" -require "active_record/connection_adapters/postgresql/oid/uuid" -require "active_record/connection_adapters/postgresql/oid/vector" -require "active_record/connection_adapters/postgresql/oid/xml" +require_relative "oid/array" +require_relative "oid/bit" +require_relative "oid/bit_varying" +require_relative "oid/bytea" +require_relative "oid/cidr" +require_relative "oid/date_time" +require_relative "oid/decimal" +require_relative "oid/enum" +require_relative "oid/hstore" +require_relative "oid/inet" +require_relative "oid/jsonb" +require_relative "oid/money" +require_relative "oid/oid" +require_relative "oid/point" +require_relative "oid/legacy_point" +require_relative "oid/range" +require_relative "oid/specialized_string" +require_relative "oid/uuid" +require_relative "oid/vector" +require_relative "oid/xml" -require "active_record/connection_adapters/postgresql/oid/type_map_initializer" +require_relative "oid/type_map_initializer" module ActiveRecord module ConnectionAdapters diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb deleted file mode 100644 index 3c706c27c4..0000000000 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb +++ /dev/null @@ -1,10 +0,0 @@ -module ActiveRecord - module ConnectionAdapters - module PostgreSQL - module OID # :nodoc: - class Json < Type::Json # :nodoc: - end - end - end - end -end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/money.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/money.rb index 7a91272d1c..cd7442e751 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/money.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/money.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveRecord module ConnectionAdapters module PostgreSQL @@ -22,7 +23,7 @@ module ActiveRecord # (3) -$2.55 # (4) ($2.55) - value.sub!(/^\((.+)\)$/, '-\1') # (4) + value = value.sub(/^\((.+)\)$/, '-\1') # (4) case value when /^-?\D+[\d,]+\.\d{2}$/ # (1) value.gsub!(/[^-\d.]/, "") diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/uuid.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/uuid.rb index 5e839228e9..db92333ef7 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/uuid.rb @@ -3,7 +3,7 @@ module ActiveRecord module PostgreSQL module OID # :nodoc: class Uuid < Type::Value # :nodoc: - ACCEPTABLE_UUID = %r{\A\{?([a-fA-F0-9]{4}-?){8}\}?\z}x + ACCEPTABLE_UUID = %r{\A(\{)?([a-fA-F0-9]{4}-?){8}(?(1)\}|)\z} alias_method :serialize, :deserialize diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index 8a999a8429..a710ea6cc9 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -406,7 +406,7 @@ module ActiveRecord quoted_table_name = quote_table_name(table_name) quoted_column_name = quote_column_name(column_name) sql_type = type_to_sql(type, options) - sql = "ALTER TABLE #{quoted_table_name} ALTER COLUMN #{quoted_column_name} TYPE #{sql_type}" + sql = "ALTER TABLE #{quoted_table_name} ALTER COLUMN #{quoted_column_name} TYPE #{sql_type}".dup if options[:collation] sql << " COLLATE \"#{options[:collation]}\"" end @@ -566,7 +566,7 @@ module ActiveRecord super end - sql << "[]" if array && type != :primary_key + sql = "#{sql}[]" if array && type != :primary_key sql end @@ -635,7 +635,7 @@ module ActiveRecord scope = quoted_scope(name, type: type) scope[:type] ||= "'r','v','m'" # (r)elation/table, (v)iew, (m)aterialized view - sql = "SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace" + sql = "SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace".dup sql << " WHERE n.nspname = #{scope[:schema]}" sql << " AND c.relname = #{scope[:name]}" if scope[:name] sql << " AND c.relkind IN (#{scope[:type]})" diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index e63563afc4..8baef19030 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -2,20 +2,20 @@ gem "pg", "~> 0.18" require "pg" -require "active_record/connection_adapters/abstract_adapter" -require "active_record/connection_adapters/statement_pool" -require "active_record/connection_adapters/postgresql/column" -require "active_record/connection_adapters/postgresql/database_statements" -require "active_record/connection_adapters/postgresql/explain_pretty_printer" -require "active_record/connection_adapters/postgresql/oid" -require "active_record/connection_adapters/postgresql/quoting" -require "active_record/connection_adapters/postgresql/referential_integrity" -require "active_record/connection_adapters/postgresql/schema_creation" -require "active_record/connection_adapters/postgresql/schema_definitions" -require "active_record/connection_adapters/postgresql/schema_dumper" -require "active_record/connection_adapters/postgresql/schema_statements" -require "active_record/connection_adapters/postgresql/type_metadata" -require "active_record/connection_adapters/postgresql/utils" +require_relative "abstract_adapter" +require_relative "statement_pool" +require_relative "postgresql/column" +require_relative "postgresql/database_statements" +require_relative "postgresql/explain_pretty_printer" +require_relative "postgresql/oid" +require_relative "postgresql/quoting" +require_relative "postgresql/referential_integrity" +require_relative "postgresql/schema_creation" +require_relative "postgresql/schema_definitions" +require_relative "postgresql/schema_dumper" +require_relative "postgresql/schema_statements" +require_relative "postgresql/type_metadata" +require_relative "postgresql/utils" module ActiveRecord module ConnectionHandling # :nodoc: diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb index 00ff804e80..31e83f9260 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb @@ -67,7 +67,7 @@ module ActiveRecord scope = quoted_scope(name, type: type) scope[:type] ||= "'table','view'" - sql = "SELECT name FROM sqlite_master WHERE name <> 'sqlite_sequence'" + sql = "SELECT name FROM sqlite_master WHERE name <> 'sqlite_sequence'".dup sql << " AND name = #{scope[:name]}" if scope[:name] sql << " AND type IN (#{scope[:type]})" sql diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index 17c63d4b5f..04129841e4 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -1,11 +1,11 @@ -require "active_record/connection_adapters/abstract_adapter" -require "active_record/connection_adapters/statement_pool" -require "active_record/connection_adapters/sqlite3/explain_pretty_printer" -require "active_record/connection_adapters/sqlite3/quoting" -require "active_record/connection_adapters/sqlite3/schema_creation" -require "active_record/connection_adapters/sqlite3/schema_definitions" -require "active_record/connection_adapters/sqlite3/schema_dumper" -require "active_record/connection_adapters/sqlite3/schema_statements" +require_relative "abstract_adapter" +require_relative "statement_pool" +require_relative "sqlite3/explain_pretty_printer" +require_relative "sqlite3/quoting" +require_relative "sqlite3/schema_creation" +require_relative "sqlite3/schema_definitions" +require_relative "sqlite3/schema_dumper" +require_relative "sqlite3/schema_statements" gem "sqlite3", "~> 1.3.6" require "sqlite3" diff --git a/activerecord/lib/active_record/explain.rb b/activerecord/lib/active_record/explain.rb index 8f7ae2c33c..eff5990f3a 100644 --- a/activerecord/lib/active_record/explain.rb +++ b/activerecord/lib/active_record/explain.rb @@ -1,4 +1,4 @@ -require "active_record/explain_registry" +require_relative "explain_registry" module ActiveRecord module Explain @@ -16,7 +16,7 @@ module ActiveRecord # Returns a formatted string ready to be logged. def exec_explain(queries) # :nodoc: str = queries.map do |sql, binds| - msg = "EXPLAIN for: #{sql}" + msg = "EXPLAIN for: #{sql}".dup unless binds.empty? msg << " " msg << binds.map { |attr| render_bind(attr) }.inspect diff --git a/activerecord/lib/active_record/explain_subscriber.rb b/activerecord/lib/active_record/explain_subscriber.rb index abd8cfc8f2..928720d011 100644 --- a/activerecord/lib/active_record/explain_subscriber.rb +++ b/activerecord/lib/active_record/explain_subscriber.rb @@ -1,5 +1,5 @@ require "active_support/notifications" -require "active_record/explain_registry" +require_relative "explain_registry" module ActiveRecord class ExplainSubscriber # :nodoc: diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index e9acb8acae..c9e97d9d2b 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -4,8 +4,8 @@ require "zlib" require "set" require "active_support/dependencies" require "active_support/core_ext/digest/uuid" -require "active_record/fixture_set/file" -require "active_record/errors" +require_relative "fixture_set/file" +require_relative "errors" module ActiveRecord class FixtureClassNotFound < ActiveRecord::ActiveRecordError #:nodoc: diff --git a/activerecord/lib/active_record/inheritance.rb b/activerecord/lib/active_record/inheritance.rb index 5776807507..1753322274 100644 --- a/activerecord/lib/active_record/inheritance.rb +++ b/activerecord/lib/active_record/inheritance.rb @@ -245,7 +245,7 @@ module ActiveRecord def ensure_proper_type klass = self.class if klass.finder_needs_type_condition? - write_attribute(klass.inheritance_column, klass.sti_name) + _write_attribute(klass.inheritance_column, klass.sti_name) end end end diff --git a/activerecord/lib/active_record/internal_metadata.rb b/activerecord/lib/active_record/internal_metadata.rb index 25ee9d6bfe..89e5d153b8 100644 --- a/activerecord/lib/active_record/internal_metadata.rb +++ b/activerecord/lib/active_record/internal_metadata.rb @@ -1,5 +1,5 @@ -require "active_record/scoping/default" -require "active_record/scoping/named" +require_relative "scoping/default" +require_relative "scoping/named" module ActiveRecord # This class is used to create a table that keeps track of values and keys such diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 51c82f4ced..42220b9a5e 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -157,7 +157,7 @@ module ActiveRecord class ProtectedEnvironmentError < ActiveRecordError #:nodoc: def initialize(env = "production") - msg = "You are attempting to run a destructive action against your '#{env}' database.\n" + msg = "You are attempting to run a destructive action against your '#{env}' database.\n".dup 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) @@ -166,7 +166,7 @@ module ActiveRecord 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" + msg = "You are attempting to modify a database that was last run in `#{ stored }` environment.\n".dup msg << "You are running in `#{ current }` environment. " msg << "If you are sure you want to continue, first set the environment using:\n\n" msg << " bin/rails db:environment:set" @@ -863,15 +863,17 @@ module ActiveRecord source_migrations.each do |migration| source = File.binread(migration.filename) inserted_comment = "# This migration comes from #{scope} (originally #{migration.version})\n" - if /\A#.*\b(?:en)?coding:\s*\S+/ =~ source + magic_comments = "".dup + 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) # so the magic keep working. # Note that magic comments must be at the first line(except sh-bang). - source[/\n/] = "\n#{inserted_comment}" - else - source = "#{inserted_comment}#{source}" + source.sub!(/\A(?:#.*\b(?:en)?coding:\s*\S+|#\s*frozen_string_literal:\s*(?:true|false)).*\n/) do |magic_comment| + magic_comments << magic_comment; "" + end || break end + source = "#{magic_comments}#{inserted_comment}#{source}" if duplicate = destination_migrations.detect { |m| m.name == migration.name } if options[:on_skip] && duplicate.scope != scope.to_s @@ -1239,7 +1241,7 @@ module ActiveRecord record_version_state_after_migrating(migration.version) end rescue => e - msg = "An error has occurred, " + msg = "An error has occurred, ".dup msg << "this and " if use_transaction?(migration) msg << "all later migrations canceled:\n\n#{e}" raise StandardError, msg, e.backtrace diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index b2dba5516e..a9509e562a 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -333,7 +333,7 @@ module ActiveRecord updated_count = self.class.unscoped.where(self.class.primary_key => id).update_all(attributes) attributes.each do |k, v| - raw_write_attribute(k, v) + write_attribute_without_type_cast(k, v) end updated_count == 1 diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb index 73518ca144..9cca103a18 100644 --- a/activerecord/lib/active_record/railtie.rb +++ b/activerecord/lib/active_record/railtie.rb @@ -48,8 +48,8 @@ module ActiveRecord # to avoid cross references when loading a constant for the # first time. Also, make it output to STDERR. console do |app| - require "active_record/railties/console_sandbox" if app.sandbox? - require "active_record/base" + require_relative "railties/console_sandbox" if app.sandbox? + require_relative "base" unless ActiveSupport::Logger.logger_outputs_to?(Rails.logger, STDERR, STDOUT) console = ActiveSupport::Logger.new(STDERR) Rails.logger.extend ActiveSupport::Logger.broadcast console @@ -57,7 +57,7 @@ module ActiveRecord end runner do - require "active_record/base" + require_relative "base" end initializer "active_record.initialize_timezone" do @@ -101,7 +101,7 @@ module ActiveRecord initializer "active_record.warn_on_records_fetched_greater_than" do if config.active_record.warn_on_records_fetched_greater_than ActiveSupport.on_load(:active_record) do - require "active_record/relation/record_fetch_warning" + require_relative "relation/record_fetch_warning" end end end @@ -139,7 +139,7 @@ end_warning # Expose database runtime to controller for logging. initializer "active_record.log_runtime" do - require "active_record/railties/controller_runtime" + require_relative "railties/controller_runtime" ActiveSupport.on_load(:action_controller) do include ActiveRecord::Railties::ControllerRuntime end diff --git a/activerecord/lib/active_record/railties/controller_runtime.rb b/activerecord/lib/active_record/railties/controller_runtime.rb index 8658188623..4030cdc158 100644 --- a/activerecord/lib/active_record/railties/controller_runtime.rb +++ b/activerecord/lib/active_record/railties/controller_runtime.rb @@ -1,5 +1,5 @@ require "active_support/core_ext/module/attr_internal" -require "active_record/log_subscriber" +require_relative "../log_subscriber" module ActiveRecord module Railties # :nodoc: diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index 711099e9e1..abc7323341 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -187,7 +187,7 @@ db_namespace = namespace :db do namespace :fixtures do desc "Loads fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures." task load: [:environment, :load_config] do - require "active_record/fixtures" + require_relative "../fixtures" base_dir = ActiveRecord::Tasks::DatabaseTasks.fixtures_path @@ -209,7 +209,7 @@ db_namespace = namespace :db do # desc "Search for a fixture given a LABEL or ID. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures." task identify: [:environment, :load_config] do - require "active_record/fixtures" + require_relative "../fixtures" label, id = ENV["LABEL"], ENV["ID"] raise "LABEL or ID required" if label.blank? && id.blank? @@ -235,7 +235,7 @@ db_namespace = namespace :db do namespace :schema do desc "Creates a db/schema.rb file that is portable against any DB supported by Active Record" task dump: [:environment, :load_config] do - require "active_record/schema_dumper" + require_relative "../schema_dumper" filename = ENV["SCHEMA"] || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, "schema.rb") File.open(filename, "w:utf-8") do |file| ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file) diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 8ff2f50fdb..a453ca55c7 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -185,19 +185,23 @@ module ActiveRecord end deprecate :scope_chain - def join_scope(table, foreign_table, foreign_klass) - predicate_builder = predicate_builder(table) - scope_chain_items = join_scopes(table, predicate_builder) - klass_scope = klass_join_scope(table, predicate_builder) - + def build_join_constraint(table, foreign_table) key = join_keys.key foreign_key = join_keys.foreign_key - klass_scope.where!(table[key].eq(foreign_table[foreign_key])) + constraint = table[key].eq(foreign_table[foreign_key]) if klass.finder_needs_type_condition? - klass_scope.where!(klass.send(:type_condition, table)) + table.create_and([constraint, klass.send(:type_condition, table)]) + else + constraint end + end + + def join_scope(table, foreign_klass) + predicate_builder = predicate_builder(table) + scope_chain_items = join_scopes(table, predicate_builder) + klass_scope = klass_join_scope(table, predicate_builder) if type klass_scope.where!(type => foreign_klass.base_class.sti_name) diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 52f5d5f3e3..76cf47a3ed 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -6,7 +6,7 @@ module ActiveRecord :extending, :unscope] SINGLE_VALUE_METHODS = [:limit, :offset, :lock, :readonly, :reordering, - :reverse_order, :distinct, :create_with] + :reverse_order, :distinct, :create_with, :skip_query_cache] CLAUSE_METHODS = [:where, :having, :from] INVALID_METHODS_FOR_DELETE_ALL = [:limit, :distinct, :offset, :group, :having] @@ -657,20 +657,32 @@ module ActiveRecord end def exec_queries(&block) - @records = eager_loading? ? find_with_associations.freeze : @klass.find_by_sql(arel, bound_attributes, &block).freeze - - preload = preload_values - preload += includes_values unless eager_loading? - preloader = nil - preload.each do |associations| - preloader ||= build_preloader - preloader.preload @records, associations - end + skip_query_cache_if_necessary do + @records = eager_loading? ? find_with_associations.freeze : @klass.find_by_sql(arel, bound_attributes, &block).freeze + + preload = preload_values + preload += includes_values unless eager_loading? + preloader = nil + preload.each do |associations| + preloader ||= build_preloader + preloader.preload @records, associations + end - @records.each(&:readonly!) if readonly_value + @records.each(&:readonly!) if readonly_value - @loaded = true - @records + @loaded = true + @records + end + end + + def skip_query_cache_if_necessary + if skip_query_cache_value + uncached do + yield + end + else + yield + end end def build_preloader diff --git a/activerecord/lib/active_record/relation/batches.rb b/activerecord/lib/active_record/relation/batches.rb index 13a2c3f511..c7e4f8a88a 100644 --- a/activerecord/lib/active_record/relation/batches.rb +++ b/activerecord/lib/active_record/relation/batches.rb @@ -1,4 +1,4 @@ -require "active_record/relation/batches/batch_enumerator" +require_relative "batches/batch_enumerator" module ActiveRecord module Batches @@ -209,6 +209,7 @@ module ActiveRecord relation = relation.reorder(batch_order).limit(batch_limit) relation = apply_limits(relation, start, finish) + relation.skip_query_cache! # Retaining the results in the query cache would undermine the point of batching batch_relation = relation loop do diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 8a54f8f2c3..aaba6c71f2 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -184,7 +184,7 @@ module ActiveRecord relation.select_values = column_names.map { |cn| @klass.has_attribute?(cn) || @klass.attribute_alias?(cn) ? arel_attribute(cn) : cn } - result = klass.connection.select_all(relation.arel, nil, bound_attributes) + result = skip_query_cache_if_necessary { klass.connection.select_all(relation.arel, nil, bound_attributes) } result.cast_values(klass.attribute_types) end end @@ -260,7 +260,7 @@ module ActiveRecord query_builder = relation.arel end - result = @klass.connection.select_all(query_builder, nil, bound_attributes) + result = skip_query_cache_if_necessary { @klass.connection.select_all(query_builder, nil, bound_attributes) } row = result.first value = row && row.values.first type = result.column_types.fetch(column_alias) do @@ -311,7 +311,7 @@ module ActiveRecord relation.group_values = group_fields relation.select_values = select_values - calculated_data = @klass.connection.select_all(relation.arel, nil, relation.bound_attributes) + calculated_data = skip_query_cache_if_necessary { @klass.connection.select_all(relation.arel, nil, relation.bound_attributes) } if association key_ids = calculated_data.collect { |row| row[group_aliases.first] } diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index df8909379f..ac0b4f597e 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -315,7 +315,7 @@ module ActiveRecord relation = construct_relation_for_exists(relation, conditions) - connection.select_value(relation.arel, "#{name} Exists", relation.bound_attributes) ? true : false + skip_query_cache_if_necessary { connection.select_value(relation.arel, "#{name} Exists", relation.bound_attributes) } ? true : false rescue ::RangeError false end @@ -334,14 +334,14 @@ module ActiveRecord name = @klass.name if ids.nil? - error = "Couldn't find #{name}" + error = "Couldn't find #{name}".dup error << " with#{conditions}" if conditions raise RecordNotFound.new(error, name) 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}': " + error = "Couldn't find all #{name.pluralize} with '#{key}': ".dup error << "(#{ids.join(", ")})#{conditions} (found #{result_size} results, but was looking for #{expected_size})" raise RecordNotFound.new(error, name, primary_key, ids) @@ -376,7 +376,7 @@ module ActiveRecord if ActiveRecord::NullRelation === relation [] else - rows = connection.select_all(relation.arel, "SQL", relation.bound_attributes) + rows = skip_query_cache_if_necessary { connection.select_all(relation.arel, "SQL", relation.bound_attributes) } join_dependency.instantiate(rows, aliases) end end @@ -424,7 +424,7 @@ module ActiveRecord relation = relation.except(:select).select(values).distinct! - id_rows = @klass.connection.select_all(relation.arel, "SQL", relation.bound_attributes) + id_rows = skip_query_cache_if_necessary { @klass.connection.select_all(relation.arel, "SQL", relation.bound_attributes) } id_rows.map { |row| row[primary_key] } end diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb index 7dea5deec5..eb80c9a00d 100644 --- a/activerecord/lib/active_record/relation/predicate_builder.rb +++ b/activerecord/lib/active_record/relation/predicate_builder.rb @@ -175,11 +175,11 @@ module ActiveRecord end end -require "active_record/relation/predicate_builder/array_handler" -require "active_record/relation/predicate_builder/base_handler" -require "active_record/relation/predicate_builder/basic_object_handler" -require "active_record/relation/predicate_builder/range_handler" -require "active_record/relation/predicate_builder/relation_handler" - -require "active_record/relation/predicate_builder/association_query_value" -require "active_record/relation/predicate_builder/polymorphic_array_value" +require_relative "predicate_builder/array_handler" +require_relative "predicate_builder/base_handler" +require_relative "predicate_builder/basic_object_handler" +require_relative "predicate_builder/range_handler" +require_relative "predicate_builder/relation_handler" + +require_relative "predicate_builder/association_query_value" +require_relative "predicate_builder/polymorphic_array_value" diff --git a/activerecord/lib/active_record/relation/query_attribute.rb b/activerecord/lib/active_record/relation/query_attribute.rb index a68e508fcc..0e1f64775d 100644 --- a/activerecord/lib/active_record/relation/query_attribute.rb +++ b/activerecord/lib/active_record/relation/query_attribute.rb @@ -1,4 +1,4 @@ -require "active_record/attribute" +require_relative "../attribute" module ActiveRecord class Relation diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index d44f6fd572..79495ead91 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -1,7 +1,7 @@ -require "active_record/relation/from_clause" -require "active_record/relation/query_attribute" -require "active_record/relation/where_clause" -require "active_record/relation/where_clause_factory" +require_relative "from_clause" +require_relative "query_attribute" +require_relative "where_clause" +require_relative "where_clause_factory" require "active_model/forbidden_attributes_protection" module ActiveRecord @@ -913,6 +913,11 @@ module ActiveRecord self end + def skip_query_cache! # :nodoc: + self.skip_query_cache_value = true + self + end + # Returns the Arel object associated with the relation. def arel # :nodoc: @arel ||= build_arel diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index ada89b5ec3..ddf7f825c1 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -1,6 +1,6 @@ require "active_support/core_ext/hash/except" require "active_support/core_ext/hash/slice" -require "active_record/relation/merger" +require_relative "merger" module ActiveRecord module SpawnMethods diff --git a/activerecord/lib/active_record/schema_migration.rb b/activerecord/lib/active_record/schema_migration.rb index f59737afb0..6dbabd69a1 100644 --- a/activerecord/lib/active_record/schema_migration.rb +++ b/activerecord/lib/active_record/schema_migration.rb @@ -1,5 +1,5 @@ -require "active_record/scoping/default" -require "active_record/scoping/named" +require_relative "scoping/default" +require_relative "scoping/named" module ActiveRecord # This class is used to create a table that keeps track of which migrations diff --git a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb index c25d87dd3e..ff6745f7b5 100644 --- a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb +++ b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb @@ -99,7 +99,7 @@ module ActiveRecord def error_class if configuration["adapter"].include?("jdbc") - require "active_record/railties/jdbcmysql_error" + require_relative "../railties/jdbcmysql_error" ArJdbcMySQL::Error elsif defined?(Mysql2) Mysql2::Error @@ -151,7 +151,7 @@ IDENTIFIED BY '#{configuration['password']}' WITH GRANT OPTION; end def run_cmd_error(cmd, args, action) - msg = "failed to execute: `#{cmd}`\n" + msg = "failed to execute: `#{cmd}`\n".dup 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 diff --git a/activerecord/lib/active_record/timestamp.rb b/activerecord/lib/active_record/timestamp.rb index dc4540eea6..26eea0bc24 100644 --- a/activerecord/lib/active_record/timestamp.rb +++ b/activerecord/lib/active_record/timestamp.rb @@ -86,7 +86,7 @@ module ActiveRecord all_timestamp_attributes_in_model.each do |column| if !attribute_present?(column) - write_attribute(column, current_time) + _write_attribute(column, current_time) end end end @@ -100,7 +100,7 @@ module ActiveRecord timestamp_attributes_for_update_in_model.each do |column| next if will_save_change_to_attribute?(column) - write_attribute(column, current_time) + _write_attribute(column, current_time) end end super(*args) diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index 45795fa287..463bb1f314 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -490,7 +490,7 @@ module ActiveRecord def update_attributes_from_transaction_state(transaction_state) if transaction_state && transaction_state.finalized? restore_transaction_record_state if transaction_state.rolledback? - clear_transaction_record_state + clear_transaction_record_state if transaction_state.fully_completed? end end end diff --git a/activerecord/lib/active_record/type.rb b/activerecord/lib/active_record/type.rb index 9ed6c95bf9..6f4e35b159 100644 --- a/activerecord/lib/active_record/type.rb +++ b/activerecord/lib/active_record/type.rb @@ -1,20 +1,20 @@ require "active_model/type" -require "active_record/type/internal/timezone" +require_relative "type/internal/timezone" -require "active_record/type/date" -require "active_record/type/date_time" -require "active_record/type/decimal_without_scale" -require "active_record/type/json" -require "active_record/type/time" -require "active_record/type/text" -require "active_record/type/unsigned_integer" +require_relative "type/date" +require_relative "type/date_time" +require_relative "type/decimal_without_scale" +require_relative "type/json" +require_relative "type/time" +require_relative "type/text" +require_relative "type/unsigned_integer" -require "active_record/type/serialized" -require "active_record/type/adapter_specific_registry" +require_relative "type/serialized" +require_relative "type/adapter_specific_registry" -require "active_record/type/type_map" -require "active_record/type/hash_lookup_type_map" +require_relative "type/type_map" +require_relative "type/hash_lookup_type_map" module ActiveRecord module Type diff --git a/activerecord/lib/active_record/type_caster.rb b/activerecord/lib/active_record/type_caster.rb index f1686e4913..8b12a30c6a 100644 --- a/activerecord/lib/active_record/type_caster.rb +++ b/activerecord/lib/active_record/type_caster.rb @@ -1,5 +1,5 @@ -require "active_record/type_caster/map" -require "active_record/type_caster/connection" +require_relative "type_caster/map" +require_relative "type_caster/connection" module ActiveRecord module TypeCaster # :nodoc: diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index 9633f226f0..046b69bee2 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -84,8 +84,8 @@ module ActiveRecord end end -require "active_record/validations/associated" -require "active_record/validations/uniqueness" -require "active_record/validations/presence" -require "active_record/validations/absence" -require "active_record/validations/length" +require_relative "validations/associated" +require_relative "validations/uniqueness" +require_relative "validations/presence" +require_relative "validations/absence" +require_relative "validations/length" diff --git a/activerecord/test/cases/adapter_test.rb b/activerecord/test/cases/adapter_test.rb index a1fb6427f9..827bcba121 100644 --- a/activerecord/test/cases/adapter_test.rb +++ b/activerecord/test/cases/adapter_test.rb @@ -211,6 +211,28 @@ module ActiveRecord end end + def test_exceptions_from_notifications_are_not_translated + original_error = StandardError.new("This StandardError shouldn't get translated") + subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") { raise original_error } + actual_error = assert_raises(StandardError) do + @connection.execute("SELECT * FROM posts") + end + + assert_equal original_error, actual_error + + ensure + ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber + end + + def test_database_related_exceptions_are_translated_to_statement_invalid + error = assert_raises(ActiveRecord::StatementInvalid) do + @connection.execute("This is a syntax error") + end + + assert_instance_of ActiveRecord::StatementInvalid, error + assert_kind_of Exception, error.cause + end + def test_select_all_always_return_activerecord_result result = @connection.select_all "SELECT * FROM posts" assert result.is_a?(ActiveRecord::Result) diff --git a/activerecord/test/cases/adapters/mysql2/virtual_column_test.rb b/activerecord/test/cases/adapters/mysql2/virtual_column_test.rb index 442a4fb7b5..1c5ef2aa41 100644 --- a/activerecord/test/cases/adapters/mysql2/virtual_column_test.rb +++ b/activerecord/test/cases/adapters/mysql2/virtual_column_test.rb @@ -52,7 +52,7 @@ if ActiveRecord::Base.connection.supports_virtual_columns? def test_schema_dumping output = dump_table_schema("virtual_columns") - assert_match(/t\.virtual\s+"upper_name",\s+type: :string,\s+as: "UPPER\(`name`\)"$/i, output) + assert_match(/t\.virtual\s+"upper_name",\s+type: :string,\s+as: "(?:UPPER|UCASE)\(`name`\)"$/i, output) assert_match(/t\.virtual\s+"name_length",\s+type: :integer,\s+as: "LENGTH\(`name`\)",\s+stored: true$/i, output) end end diff --git a/activerecord/test/cases/adapters/postgresql/bytea_test.rb b/activerecord/test/cases/adapters/postgresql/bytea_test.rb index 539c90f0bc..65baed34e9 100644 --- a/activerecord/test/cases/adapters/postgresql/bytea_test.rb +++ b/activerecord/test/cases/adapters/postgresql/bytea_test.rb @@ -47,7 +47,7 @@ class PostgresqlByteaTest < ActiveRecord::PostgreSQLTestCase end def test_type_cast_binary_value - data = "\u001F\x8B".force_encoding("BINARY") + data = "\u001F\x8B".dup.force_encoding("BINARY") assert_equal(data, @type.deserialize(data)) end diff --git a/activerecord/test/cases/adapters/postgresql/money_test.rb b/activerecord/test/cases/adapters/postgresql/money_test.rb index 1b5d8362af..ea060345a7 100644 --- a/activerecord/test/cases/adapters/postgresql/money_test.rb +++ b/activerecord/test/cases/adapters/postgresql/money_test.rb @@ -47,10 +47,10 @@ class PostgresqlMoneyTest < ActiveRecord::PostgreSQLTestCase def test_money_type_cast type = PostgresqlMoney.type_for_attribute("wealth") - 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)")) + 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)) end def test_schema_dumping @@ -60,7 +60,7 @@ class PostgresqlMoneyTest < ActiveRecord::PostgreSQLTestCase end def test_create_and_update_money - money = PostgresqlMoney.create(wealth: "987.65") + money = PostgresqlMoney.create(wealth: "987.65".dup) assert_equal 987.65, money.wealth new_value = BigDecimal.new("123.45") diff --git a/activerecord/test/cases/adapters/postgresql/uuid_test.rb b/activerecord/test/cases/adapters/postgresql/uuid_test.rb index 8eddd81c38..00de92cdfd 100644 --- a/activerecord/test/cases/adapters/postgresql/uuid_test.rb +++ b/activerecord/test/cases/adapters/postgresql/uuid_test.rb @@ -124,7 +124,9 @@ class PostgresqlUUIDTest < ActiveRecord::PostgreSQLTestCase "Z0000C99-9C0B-4EF8-BB6D-6BB9BD380A11", "a0eebc999r0b4ef8ab6d6bb9bd380a11", "a0ee-bc99------4ef8-bb6d-6bb9-bd38-0a11", - "{a0eebc99-bb6d6bb9-bd380a11}"].each do |invalid_uuid| + "{a0eebc99-bb6d6bb9-bd380a11}", + "{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11", + "a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}"].each do |invalid_uuid| uuid = UUIDType.new guid: invalid_uuid assert_nil uuid.guid end diff --git a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb index 9a812e325e..cf0c37f70c 100644 --- a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +++ b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb @@ -165,7 +165,7 @@ module ActiveRecord data binary ) eosql - str = "\x80".force_encoding("ASCII-8BIT") + str = "\x80".dup.force_encoding("ASCII-8BIT") binary = DualEncoding.new name: "いただきます!", data: str binary.save! assert_equal str, binary.data @@ -174,7 +174,7 @@ module ActiveRecord end def test_type_cast_should_not_mutate_encoding - name = "hello".force_encoding(Encoding::ASCII_8BIT) + name = "hello".dup.force_encoding(Encoding::ASCII_8BIT) Owner.create(name: name) assert_equal Encoding::ASCII_8BIT, name.encoding ensure diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 55b294cfaa..c0bab19e82 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -68,6 +68,11 @@ class EagerAssociationTest < ActiveRecord::TestCase "expected to find only david's posts" end + def test_loading_with_scope_including_joins + assert_equal clubs(:boring_club), Member.preload(:general_club).find(1).general_club + assert_equal clubs(:boring_club), Member.eager_load(:general_club).find(1).general_club + end + def test_with_ordering list = Post.all.merge!(includes: :comments, order: "posts.id DESC").to_a [:other_by_mary, :other_by_bob, :misc_by_mary, :misc_by_bob, :eager_other, diff --git a/activerecord/test/cases/associations/inverse_associations_test.rb b/activerecord/test/cases/associations/inverse_associations_test.rb index 8e3087e7ca..9fbaa43274 100644 --- a/activerecord/test/cases/associations/inverse_associations_test.rb +++ b/activerecord/test/cases/associations/inverse_associations_test.rb @@ -24,11 +24,9 @@ class AutomaticInverseFindingTests < ActiveRecord::TestCase monkey_reflection = MixedCaseMonkey.reflect_on_association(:man) man_reflection = Man.reflect_on_association(:mixed_case_monkey) - assert_respond_to monkey_reflection, :has_inverse? assert monkey_reflection.has_inverse?, "The monkey reflection should have an inverse" assert_equal man_reflection, monkey_reflection.inverse_of, "The monkey reflection's inverse should be the man reflection" - assert_respond_to man_reflection, :has_inverse? assert man_reflection.has_inverse?, "The man reflection should have an inverse" assert_equal monkey_reflection, man_reflection.inverse_of, "The man reflection's inverse should be the monkey reflection" end @@ -37,7 +35,6 @@ class AutomaticInverseFindingTests < ActiveRecord::TestCase account_reflection = Admin::Account.reflect_on_association(:users) user_reflection = Admin::User.reflect_on_association(:account) - assert_respond_to account_reflection, :has_inverse? assert account_reflection.has_inverse?, "The Admin::Account reflection should have an inverse" assert_equal user_reflection, account_reflection.inverse_of, "The Admin::Account reflection's inverse should be the Admin::User reflection" end @@ -46,11 +43,9 @@ class AutomaticInverseFindingTests < ActiveRecord::TestCase car_reflection = Car.reflect_on_association(:bulb) bulb_reflection = Bulb.reflect_on_association(:car) - assert_respond_to car_reflection, :has_inverse? assert car_reflection.has_inverse?, "The Car reflection should have an inverse" assert_equal bulb_reflection, car_reflection.inverse_of, "The Car reflection's inverse should be the Bulb reflection" - assert_respond_to bulb_reflection, :has_inverse? assert bulb_reflection.has_inverse?, "The Bulb reflection should have an inverse" assert_equal car_reflection, bulb_reflection.inverse_of, "The Bulb reflection's inverse should be the Car reflection" end @@ -59,7 +54,6 @@ class AutomaticInverseFindingTests < ActiveRecord::TestCase comment_reflection = Comment.reflect_on_association(:ratings) rating_reflection = Rating.reflect_on_association(:comment) - assert_respond_to comment_reflection, :has_inverse? assert comment_reflection.has_inverse?, "The Comment reflection should have an inverse" assert_equal rating_reflection, comment_reflection.inverse_of, "The Comment reflection's inverse should be the Rating reflection" end @@ -107,19 +101,16 @@ class AutomaticInverseFindingTests < ActiveRecord::TestCase def test_polymorphic_and_has_many_through_relationships_should_not_have_inverses sponsor_reflection = Sponsor.reflect_on_association(:sponsorable) - assert_respond_to sponsor_reflection, :has_inverse? assert !sponsor_reflection.has_inverse?, "A polymorphic association should not find an inverse automatically" club_reflection = Club.reflect_on_association(:members) - assert_respond_to club_reflection, :has_inverse? assert !club_reflection.has_inverse?, "A has_many_through association should not find an inverse automatically" end def test_polymorphic_has_one_should_find_inverse_automatically man_reflection = Man.reflect_on_association(:polymorphic_face_without_inverse) - assert_respond_to man_reflection, :has_inverse? assert man_reflection.has_inverse? end end @@ -141,41 +132,24 @@ class InverseAssociationTests < ActiveRecord::TestCase def test_should_be_able_to_ask_a_reflection_if_it_has_an_inverse has_one_with_inverse_ref = Man.reflect_on_association(:face) - assert_respond_to has_one_with_inverse_ref, :has_inverse? assert has_one_with_inverse_ref.has_inverse? has_many_with_inverse_ref = Man.reflect_on_association(:interests) - assert_respond_to has_many_with_inverse_ref, :has_inverse? assert has_many_with_inverse_ref.has_inverse? belongs_to_with_inverse_ref = Face.reflect_on_association(:man) - assert_respond_to belongs_to_with_inverse_ref, :has_inverse? assert belongs_to_with_inverse_ref.has_inverse? has_one_without_inverse_ref = Club.reflect_on_association(:sponsor) - assert_respond_to has_one_without_inverse_ref, :has_inverse? assert !has_one_without_inverse_ref.has_inverse? has_many_without_inverse_ref = Club.reflect_on_association(:memberships) - assert_respond_to has_many_without_inverse_ref, :has_inverse? assert !has_many_without_inverse_ref.has_inverse? belongs_to_without_inverse_ref = Sponsor.reflect_on_association(:sponsor_club) - assert_respond_to belongs_to_without_inverse_ref, :has_inverse? assert !belongs_to_without_inverse_ref.has_inverse? end - def test_should_be_able_to_ask_a_reflection_what_it_is_the_inverse_of - has_one_ref = Man.reflect_on_association(:face) - assert_respond_to has_one_ref, :inverse_of - - has_many_ref = Man.reflect_on_association(:interests) - assert_respond_to has_many_ref, :inverse_of - - belongs_to_ref = Face.reflect_on_association(:man) - assert_respond_to belongs_to_ref, :inverse_of - end - def test_inverse_of_method_should_supply_the_actual_reflection_instance_it_is_the_inverse_of has_one_ref = Man.reflect_on_association(:face) assert_equal Face.reflect_on_association(:man), has_one_ref.inverse_of diff --git a/activerecord/test/cases/attribute_test.rb b/activerecord/test/cases/attribute_test.rb index 7cf6b498c9..e856d551c0 100644 --- a/activerecord/test/cases/attribute_test.rb +++ b/activerecord/test/cases/attribute_test.rb @@ -76,7 +76,7 @@ module ActiveRecord end test "duping dups the value" do - @type.expect(:deserialize, "type cast", ["a value"]) + @type.expect(:deserialize, "type cast".dup, ["a value"]) attribute = Attribute.from_database(nil, "a value", @type) value_from_orig = attribute.value @@ -244,7 +244,7 @@ module ActiveRecord end test "with_type preserves mutations" do - attribute = Attribute.from_database(:foo, "", Type::Value.new) + attribute = Attribute.from_database(:foo, "".dup, Type::Value.new) attribute.value << "1" assert_equal 1, attribute.with_type(Type::Integer.new).value diff --git a/activerecord/test/cases/batches_test.rb b/activerecord/test/cases/batches_test.rb index fbc3fbb44f..dcd3af487b 100644 --- a/activerecord/test/cases/batches_test.rb +++ b/activerecord/test/cases/batches_test.rb @@ -1,4 +1,5 @@ require "cases/helper" +require "models/comment" require "models/post" require "models/subscriber" @@ -152,7 +153,7 @@ class EachTest < ActiveRecord::TestCase 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" + not_a_post = "not a post".dup 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 @@ -417,7 +418,7 @@ class EachTest < ActiveRecord::TestCase end def test_in_batches_should_not_use_records_after_yielding_them_in_case_original_array_is_modified - not_a_post = "not a post" + not_a_post = "not a post".dup def not_a_post.id raise StandardError.new("not_a_post had #id called on it") end @@ -610,4 +611,64 @@ class EachTest < ActiveRecord::TestCase end assert_equal expected, actual end + + test ".find_each bypasses the query cache for its own queries" do + Post.cache do + assert_queries(2) do + Post.find_each {} + Post.find_each {} + end + end + end + + test ".find_each does not disable the query cache inside the given block" do + Post.cache do + Post.find_each(start: 1, finish: 1) do |post| + assert_queries(1) do + post.comments.count + post.comments.count + end + end + end + end + + test ".find_in_batches bypasses the query cache for its own queries" do + Post.cache do + assert_queries(2) do + Post.find_in_batches {} + Post.find_in_batches {} + end + end + end + + test ".find_in_batches does not disable the query cache inside the given block" do + Post.cache do + Post.find_in_batches(start: 1, finish: 1) do |batch| + assert_queries(1) do + batch.first.comments.count + batch.first.comments.count + end + end + end + end + + test ".in_batches bypasses the query cache for its own queries" do + Post.cache do + assert_queries(2) do + Post.in_batches {} + Post.in_batches {} + end + end + end + + test ".in_batches does not disable the query cache inside the given block" do + Post.cache do + Post.in_batches(start: 1, finish: 1) do |relation| + assert_queries(1) do + relation.count + relation.count + end + end + end + end end diff --git a/activerecord/test/cases/binary_test.rb b/activerecord/test/cases/binary_test.rb index 1fc30e24d2..f6ac7990d1 100644 --- a/activerecord/test/cases/binary_test.rb +++ b/activerecord/test/cases/binary_test.rb @@ -10,7 +10,7 @@ unless current_adapter?(:DB2Adapter) FIXTURES = %w(flowers.jpg example.log test.txt) def test_mixed_encoding - str = "\x80" + str = "\x80".dup str.force_encoding("ASCII-8BIT") binary = Binary.new name: "いただきます!", data: str diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index 80baaac30a..7d6dc21e34 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -817,4 +817,46 @@ class CalculationsTest < ActiveRecord::TestCase assert_equal 6, Account.sum(:firm_id) { 1 } end end + + test "#skip_query_cache! for #pluck" do + Account.cache do + assert_queries(1) do + Account.pluck(:credit_limit) + Account.pluck(:credit_limit) + end + + assert_queries(2) do + Account.all.skip_query_cache!.pluck(:credit_limit) + Account.all.skip_query_cache!.pluck(:credit_limit) + end + end + end + + test "#skip_query_cache! for a simple calculation" do + Account.cache do + assert_queries(1) do + Account.calculate(:sum, :credit_limit) + Account.calculate(:sum, :credit_limit) + end + + assert_queries(2) do + Account.all.skip_query_cache!.calculate(:sum, :credit_limit) + Account.all.skip_query_cache!.calculate(:sum, :credit_limit) + end + end + end + + test "#skip_query_cache! for a grouped calculation" do + Account.cache do + assert_queries(1) do + Account.group(:firm_id).calculate(:sum, :credit_limit) + Account.group(:firm_id).calculate(:sum, :credit_limit) + end + + assert_queries(2) do + Account.all.skip_query_cache!.group(:firm_id).calculate(:sum, :credit_limit) + Account.all.skip_query_cache!.group(:firm_id).calculate(:sum, :credit_limit) + end + end + end end diff --git a/activerecord/test/cases/core_test.rb b/activerecord/test/cases/core_test.rb index 3735572898..936f26ce04 100644 --- a/activerecord/test/cases/core_test.rb +++ b/activerecord/test/cases/core_test.rb @@ -35,7 +35,7 @@ class CoreTest < ActiveRecord::TestCase def test_pretty_print_new topic = Topic.new - actual = "" + actual = "".dup PP.pp(topic, StringIO.new(actual)) expected = <<-PRETTY.strip_heredoc #<Topic:0xXXXXXX @@ -64,7 +64,7 @@ class CoreTest < ActiveRecord::TestCase def test_pretty_print_persisted topic = topics(:first) - actual = "" + actual = "".dup PP.pp(topic, StringIO.new(actual)) expected = <<-PRETTY.strip_heredoc #<Topic:0x\\w+ @@ -92,7 +92,7 @@ class CoreTest < ActiveRecord::TestCase def test_pretty_print_uninitialized topic = Topic.allocate - actual = "" + actual = "".dup PP.pp(topic, StringIO.new(actual)) expected = "#<Topic:XXXXXX not initialized>\n" assert actual.start_with?(expected.split("XXXXXX").first) @@ -105,7 +105,7 @@ class CoreTest < ActiveRecord::TestCase "inspecting topic" end end - actual = "" + actual = "".dup PP.pp(subtopic.new, StringIO.new(actual)) assert_equal "inspecting topic\n", actual end diff --git a/activerecord/test/cases/date_time_test.rb b/activerecord/test/cases/date_time_test.rb index ad7da9de70..6cd98fe254 100644 --- a/activerecord/test/cases/date_time_test.rb +++ b/activerecord/test/cases/date_time_test.rb @@ -58,4 +58,17 @@ class DateTimeTest < ActiveRecord::TestCase assert_equal now, task.starting end end + + def test_date_time_with_string_value_with_subsecond_precision + skip unless subsecond_precision_supported? + string_value = "2017-07-04 14:19:00.5" + topic = Topic.create(written_on: string_value) + assert_equal topic, Topic.find_by(written_on: string_value) + end + + def test_date_time_with_string_value_with_non_iso_format + string_value = "04/07/2017 2:19pm" + topic = Topic.create(written_on: string_value) + assert_equal topic, Topic.find_by(written_on: string_value) + end end diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 420f552ef6..af21cd529f 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -1232,6 +1232,34 @@ class FinderTest < ActiveRecord::TestCase assert_equal tyre2, zyke.tyres.custom_find_by(id: tyre2.id) end + test "#skip_query_cache! for #exists?" do + Topic.cache do + assert_queries(1) do + Topic.exists? + Topic.exists? + end + + assert_queries(2) do + Topic.all.skip_query_cache!.exists? + Topic.all.skip_query_cache!.exists? + end + end + end + + test "#skip_query_cache! for #exists? with a limited eager load" do + Topic.cache do + assert_queries(2) do + Topic.eager_load(:replies).limit(1).exists? + Topic.eager_load(:replies).limit(1).exists? + end + + assert_queries(4) do + Topic.eager_load(:replies).limit(1).skip_query_cache!.exists? + Topic.eager_load(:replies).limit(1).skip_query_cache!.exists? + end + end + end + private def table_with_custom_primary_key yield(Class.new(Toy) do diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 3a49a41580..eff6e09eb7 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1015,8 +1015,8 @@ class CopyMigrationsTest < ActiveRecord::TestCase assert File.exist?(@migrations_path + "/4_currencies_have_symbols.bukkits.rb") assert_equal [@migrations_path + "/4_currencies_have_symbols.bukkits.rb"], copied.map(&:filename) - expected = "# coding: ISO-8859-15\n# This migration comes from bukkits (originally 1)" - assert_equal expected, IO.readlines(@migrations_path + "/4_currencies_have_symbols.bukkits.rb")[0..1].join.chomp + expected = "# frozen_string_literal: true\n# coding: ISO-8859-15\n# This migration comes from bukkits (originally 1)" + assert_equal expected, IO.readlines(@migrations_path + "/4_currencies_have_symbols.bukkits.rb")[0..2].join.chomp files_count = Dir[@migrations_path + "/*.rb"].length copied = ActiveRecord::Migration.copy(@migrations_path, bukkits: MIGRATIONS_ROOT + "/magic") diff --git a/activerecord/test/cases/relation/mutation_test.rb b/activerecord/test/cases/relation/mutation_test.rb index dea787c07f..8e73baa70a 100644 --- a/activerecord/test/cases/relation/mutation_test.rb +++ b/activerecord/test/cases/relation/mutation_test.rb @@ -90,7 +90,7 @@ module ActiveRecord assert_equal [], relation.extending_values end - (Relation::SINGLE_VALUE_METHODS - [:lock, :reordering, :reverse_order, :create_with]).each do |method| + (Relation::SINGLE_VALUE_METHODS - [:lock, :reordering, :reverse_order, :create_with, :skip_query_cache]).each do |method| test "##{method}!" do assert relation.public_send("#{method}!", :foo).equal?(relation) assert_equal :foo, relation.public_send("#{method}_value") @@ -162,5 +162,10 @@ module ActiveRecord relation.distinct! :foo assert_equal :foo, relation.distinct_value end + + test "skip_query_cache!" do + relation.skip_query_cache! + assert relation.skip_query_cache_value + end end end diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 5767dec315..eb3449b331 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -2034,4 +2034,46 @@ class RelationTest < ActiveRecord::TestCase assert_equal 2, posts.to_a.length end + + test "#skip_query_cache!" do + Post.cache do + assert_queries(1) do + Post.all.load + Post.all.load + end + + assert_queries(2) do + Post.all.skip_query_cache!.load + Post.all.skip_query_cache!.load + end + end + end + + test "#skip_query_cache! with an eager load" do + Post.cache do + assert_queries(1) do + Post.eager_load(:comments).load + Post.eager_load(:comments).load + end + + assert_queries(2) do + Post.eager_load(:comments).skip_query_cache!.load + Post.eager_load(:comments).skip_query_cache!.load + end + end + end + + test "#skip_query_cache! with a preload" do + Post.cache do + assert_queries(2) do + Post.preload(:comments).load + Post.preload(:comments).load + end + + assert_queries(4) do + Post.preload(:comments).skip_query_cache!.load + Post.preload(:comments).skip_query_cache!.load + end + end + end end diff --git a/activerecord/test/cases/transactions_test.rb b/activerecord/test/cases/transactions_test.rb index 79ba306ef5..76a997ba8b 100644 --- a/activerecord/test/cases/transactions_test.rb +++ b/activerecord/test/cases/transactions_test.rb @@ -304,6 +304,76 @@ class TransactionTest < ActiveRecord::TestCase assert !Topic.find(2).approved?, "Second should have been unapproved" end + def test_nested_transaction_with_new_transaction_applies_parent_state_on_rollback + topic_one = Topic.new(title: "A new topic") + topic_two = Topic.new(title: "Another new topic") + + Topic.transaction do + topic_one.save + + Topic.transaction(requires_new: true) do + topic_two.save + + assert_predicate topic_one, :persisted? + assert_predicate topic_two, :persisted? + end + + raise ActiveRecord::Rollback + end + + refute_predicate topic_one, :persisted? + refute_predicate topic_two, :persisted? + end + + def test_nested_transaction_without_new_transaction_applies_parent_state_on_rollback + topic_one = Topic.new(title: "A new topic") + topic_two = Topic.new(title: "Another new topic") + + Topic.transaction do + topic_one.save + + Topic.transaction do + topic_two.save + + assert_predicate topic_one, :persisted? + assert_predicate topic_two, :persisted? + end + + raise ActiveRecord::Rollback + end + + refute_predicate topic_one, :persisted? + refute_predicate topic_two, :persisted? + end + + def test_double_nested_transaction_applies_parent_state_on_rollback + topic_one = Topic.new(title: "A new topic") + topic_two = Topic.new(title: "Another new topic") + topic_three = Topic.new(title: "Another new topic of course") + + Topic.transaction do + topic_one.save + + Topic.transaction do + topic_two.save + + Topic.transaction do + topic_three.save + end + end + + assert_predicate topic_one, :persisted? + assert_predicate topic_two, :persisted? + assert_predicate topic_three, :persisted? + + raise ActiveRecord::Rollback + end + + refute_predicate topic_one, :persisted? + refute_predicate topic_two, :persisted? + refute_predicate topic_three, :persisted? + end + def test_manually_rolling_back_a_transaction Topic.transaction do @first.approved = true @@ -725,6 +795,44 @@ class TransactionTest < ActiveRecord::TestCase assert transaction.state.committed? end + def test_set_state_method_is_deprecated + connection = Topic.connection + transaction = ActiveRecord::ConnectionAdapters::TransactionManager.new(connection).begin_transaction + + transaction.commit + + assert_deprecated do + transaction.state.set_state(:rolledback) + end + end + + def test_mark_transaction_state_as_committed + connection = Topic.connection + transaction = ActiveRecord::ConnectionAdapters::TransactionManager.new(connection).begin_transaction + + transaction.rollback + + assert_equal :committed, transaction.state.commit! + end + + def test_mark_transaction_state_as_rolledback + connection = Topic.connection + transaction = ActiveRecord::ConnectionAdapters::TransactionManager.new(connection).begin_transaction + + transaction.commit + + assert_equal :rolledback, transaction.state.rollback! + end + + def test_mark_transaction_state_as_nil + connection = Topic.connection + transaction = ActiveRecord::ConnectionAdapters::TransactionManager.new(connection).begin_transaction + + transaction.commit + + assert_nil transaction.state.nullify! + end + def test_transaction_rollback_with_primarykeyless_tables connection = ActiveRecord::Base.connection connection.create_table(:transaction_without_primary_keys, force: true, id: false) do |t| diff --git a/activerecord/test/migrations/magic/1_currencies_have_symbols.rb b/activerecord/test/migrations/magic/1_currencies_have_symbols.rb index d4b0e6cd95..2ba2875751 100644 --- a/activerecord/test/migrations/magic/1_currencies_have_symbols.rb +++ b/activerecord/test/migrations/magic/1_currencies_have_symbols.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # coding: ISO-8859-15 class CurrenciesHaveSymbols < ActiveRecord::Migration::Current diff --git a/activerecord/test/models/club.rb b/activerecord/test/models/club.rb index 49d7b24a3b..3d441b1d48 100644 --- a/activerecord/test/models/club.rb +++ b/activerecord/test/models/club.rb @@ -8,6 +8,8 @@ class Club < ActiveRecord::Base has_many :favourites, -> { where(memberships: { favourite: true }) }, through: :memberships, source: :member + scope :general, -> { left_joins(:category).where(categories: { name: "General" }) } + private def private_method diff --git a/activerecord/test/models/member.rb b/activerecord/test/models/member.rb index 36f2461b84..b9597c6b9a 100644 --- a/activerecord/test/models/member.rb +++ b/activerecord/test/models/member.rb @@ -22,6 +22,7 @@ class Member < ActiveRecord::Base has_many :organization_member_details_2, through: :organization, source: :member_details has_one :club_category, through: :club, source: :category + has_one :general_club, -> { general }, through: :current_membership, source: :club has_many :current_memberships, -> { where favourite: true } has_many :clubs, through: :current_memberships diff --git a/activesupport/Rakefile b/activesupport/Rakefile index 2e1c50cc3d..8691a34035 100644 --- a/activesupport/Rakefile +++ b/activesupport/Rakefile @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "rake/testtask" task default: :test diff --git a/activesupport/activesupport.gemspec b/activesupport/activesupport.gemspec index 16e912694c..4470de7ec1 100644 --- a/activesupport/activesupport.gemspec +++ b/activesupport/activesupport.gemspec @@ -1,3 +1,4 @@ +# frozen_string_literal: true version = File.read(File.expand_path("../RAILS_VERSION", __dir__)).strip Gem::Specification.new do |s| diff --git a/activesupport/bin/generate_tables b/activesupport/bin/generate_tables index 6f62593f14..18199b2171 100755 --- a/activesupport/bin/generate_tables +++ b/activesupport/bin/generate_tables @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true begin $:.unshift(File.expand_path("../lib", __dir__)) diff --git a/activesupport/bin/test b/activesupport/bin/test index 470ce93f10..c53377cc97 100755 --- a/activesupport/bin/test +++ b/activesupport/bin/test @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true COMPONENT_ROOT = File.expand_path("..", __dir__) require_relative "../../tools/test" diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb index a667fbb54a..65e903aeb9 100644 --- a/activesupport/lib/active_support.rb +++ b/activesupport/lib/active_support.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true #-- # Copyright (c) 2005-2017 David Heinemeier Hansson # @@ -22,11 +23,11 @@ #++ require "securerandom" -require "active_support/dependencies/autoload" -require "active_support/version" -require "active_support/logger" -require "active_support/lazy_load_hooks" -require "active_support/core_ext/date_and_time/compatibility" +require_relative "active_support/dependencies/autoload" +require_relative "active_support/version" +require_relative "active_support/logger" +require_relative "active_support/lazy_load_hooks" +require_relative "active_support/core_ext/date_and_time/compatibility" module ActiveSupport extend ActiveSupport::Autoload diff --git a/activesupport/lib/active_support/all.rb b/activesupport/lib/active_support/all.rb index 72a23075af..89f5d2b258 100644 --- a/activesupport/lib/active_support/all.rb +++ b/activesupport/lib/active_support/all.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "active_support" -require "active_support/time" -require "active_support/core_ext" +require_relative "time" +require_relative "core_ext" diff --git a/activesupport/lib/active_support/array_inquirer.rb b/activesupport/lib/active_support/array_inquirer.rb index befa1746c6..6dad208e43 100644 --- a/activesupport/lib/active_support/array_inquirer.rb +++ b/activesupport/lib/active_support/array_inquirer.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport # Wrapping an array in an +ArrayInquirer+ gives a friendlier way to check # its string-like contents: diff --git a/activesupport/lib/active_support/backtrace_cleaner.rb b/activesupport/lib/active_support/backtrace_cleaner.rb index e47c90597f..1ffa2c05a2 100644 --- a/activesupport/lib/active_support/backtrace_cleaner.rb +++ b/activesupport/lib/active_support/backtrace_cleaner.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport # Backtraces often include many lines that are not relevant for the context # under review. This makes it hard to find the signal amongst the backtrace diff --git a/activesupport/lib/active_support/benchmarkable.rb b/activesupport/lib/active_support/benchmarkable.rb index 70493c8da7..a201b43fdc 100644 --- a/activesupport/lib/active_support/benchmarkable.rb +++ b/activesupport/lib/active_support/benchmarkable.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/benchmark" -require "active_support/core_ext/hash/keys" +# frozen_string_literal: true +require_relative "core_ext/benchmark" +require_relative "core_ext/hash/keys" module ActiveSupport module Benchmarkable diff --git a/activesupport/lib/active_support/builder.rb b/activesupport/lib/active_support/builder.rb index 0f010c5d96..a7582a4f00 100644 --- a/activesupport/lib/active_support/builder.rb +++ b/activesupport/lib/active_support/builder.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true begin require "builder" rescue LoadError => e diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index 3847d8b7ae..2ced73a0a6 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -1,11 +1,12 @@ +# frozen_string_literal: true require "zlib" -require "active_support/core_ext/array/extract_options" -require "active_support/core_ext/array/wrap" -require "active_support/core_ext/module/attribute_accessors" -require "active_support/core_ext/numeric/bytes" -require "active_support/core_ext/numeric/time" -require "active_support/core_ext/object/to_param" -require "active_support/core_ext/string/inflections" +require_relative "core_ext/array/extract_options" +require_relative "core_ext/array/wrap" +require_relative "core_ext/module/attribute_accessors" +require_relative "core_ext/numeric/bytes" +require_relative "core_ext/numeric/time" +require_relative "core_ext/object/to_param" +require_relative "core_ext/string/inflections" module ActiveSupport # See ActiveSupport::Cache::Store for documentation. @@ -75,7 +76,7 @@ module ActiveSupport # # The +key+ argument can also respond to +cache_key+ or +to_param+. def expand_cache_key(key, namespace = nil) - expanded_cache_key = namespace ? "#{namespace}/" : "" + expanded_cache_key = (namespace ? "#{namespace}/" : "").dup if prefix = ENV["RAILS_CACHE_ID"] || ENV["RAILS_APP_VERSION"] expanded_cache_key << "#{prefix}/" @@ -99,7 +100,7 @@ module ActiveSupport # Obtains the specified cache store class, given the name of the +store+. # Raises an error when the store class cannot be found. def retrieve_store_class(store) - require "active_support/cache/#{store}" + require_relative "cache/#{store}" rescue LoadError => e raise "Could not find cache store adapter for #{store} (#{e})" else diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index 945f50a56e..87182e0254 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -1,6 +1,7 @@ -require "active_support/core_ext/marshal" -require "active_support/core_ext/file/atomic" -require "active_support/core_ext/string/conversions" +# frozen_string_literal: true +require_relative "../core_ext/marshal" +require_relative "../core_ext/file/atomic" +require_relative "../core_ext/string/conversions" require "uri/common" module ActiveSupport diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb index 06fa9f67ad..de05dde8d4 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/mem_cache_store.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true begin require "dalli" rescue LoadError => e @@ -6,8 +7,8 @@ rescue LoadError => e end require "digest/md5" -require "active_support/core_ext/marshal" -require "active_support/core_ext/array/extract_options" +require_relative "../core_ext/marshal" +require_relative "../core_ext/array/extract_options" module ActiveSupport module Cache diff --git a/activesupport/lib/active_support/cache/memory_store.rb b/activesupport/lib/active_support/cache/memory_store.rb index 56fe1457d0..e1fee72595 100644 --- a/activesupport/lib/active_support/cache/memory_store.rb +++ b/activesupport/lib/active_support/cache/memory_store.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "monitor" module ActiveSupport diff --git a/activesupport/lib/active_support/cache/null_store.rb b/activesupport/lib/active_support/cache/null_store.rb index 550659fc56..10ffbb84ea 100644 --- a/activesupport/lib/active_support/cache/null_store.rb +++ b/activesupport/lib/active_support/cache/null_store.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport module Cache # A cache store implementation which doesn't actually store anything. Useful in diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb index 69b3a93a05..f3b65bcdef 100644 --- a/activesupport/lib/active_support/cache/strategy/local_cache.rb +++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb @@ -1,6 +1,7 @@ -require "active_support/core_ext/object/duplicable" -require "active_support/core_ext/string/inflections" -require "active_support/per_thread_registry" +# frozen_string_literal: true +require_relative "../../core_ext/object/duplicable" +require_relative "../../core_ext/string/inflections" +require_relative "../../per_thread_registry" module ActiveSupport module Cache diff --git a/activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb b/activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb index 4c3679e4bf..a53e268a92 100644 --- a/activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb +++ b/activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "rack/body_proxy" require "rack/utils" diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index df18c35199..5cf8dbea90 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -1,11 +1,12 @@ -require "active_support/concern" -require "active_support/descendants_tracker" -require "active_support/core_ext/array/extract_options" -require "active_support/core_ext/class/attribute" -require "active_support/core_ext/kernel/reporting" -require "active_support/core_ext/kernel/singleton_class" -require "active_support/core_ext/string/filters" -require "active_support/deprecation" +# frozen_string_literal: true +require_relative "concern" +require_relative "descendants_tracker" +require_relative "core_ext/array/extract_options" +require_relative "core_ext/class/attribute" +require_relative "core_ext/kernel/reporting" +require_relative "core_ext/kernel/singleton_class" +require_relative "core_ext/string/filters" +require_relative "deprecation" require "thread" module ActiveSupport diff --git a/activesupport/lib/active_support/concern.rb b/activesupport/lib/active_support/concern.rb index 0403eb70ca..f1dcda7dfa 100644 --- a/activesupport/lib/active_support/concern.rb +++ b/activesupport/lib/active_support/concern.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport # A typical module looks like this: # diff --git a/activesupport/lib/active_support/concurrency/share_lock.rb b/activesupport/lib/active_support/concurrency/share_lock.rb index 4318523b07..060b16f2d6 100644 --- a/activesupport/lib/active_support/concurrency/share_lock.rb +++ b/activesupport/lib/active_support/concurrency/share_lock.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "thread" require "monitor" diff --git a/activesupport/lib/active_support/configurable.rb b/activesupport/lib/active_support/configurable.rb index f72a893bcc..490925f37e 100644 --- a/activesupport/lib/active_support/configurable.rb +++ b/activesupport/lib/active_support/configurable.rb @@ -1,7 +1,8 @@ -require "active_support/concern" -require "active_support/ordered_options" -require "active_support/core_ext/array/extract_options" -require "active_support/core_ext/regexp" +# frozen_string_literal: true +require_relative "concern" +require_relative "ordered_options" +require_relative "core_ext/array/extract_options" +require_relative "core_ext/regexp" module ActiveSupport # Configurable provides a <tt>config</tt> method to store and retrieve diff --git a/activesupport/lib/active_support/core_ext.rb b/activesupport/lib/active_support/core_ext.rb index 42e0acf66a..784cdc4a78 100644 --- a/activesupport/lib/active_support/core_ext.rb +++ b/activesupport/lib/active_support/core_ext.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true Dir.glob(File.expand_path("core_ext/*.rb", __dir__)).each do |path| require path end diff --git a/activesupport/lib/active_support/core_ext/array.rb b/activesupport/lib/active_support/core_ext/array.rb index e908386a1c..c2876785dc 100644 --- a/activesupport/lib/active_support/core_ext/array.rb +++ b/activesupport/lib/active_support/core_ext/array.rb @@ -1,7 +1,8 @@ -require "active_support/core_ext/array/wrap" -require "active_support/core_ext/array/access" -require "active_support/core_ext/array/conversions" -require "active_support/core_ext/array/extract_options" -require "active_support/core_ext/array/grouping" -require "active_support/core_ext/array/prepend_and_append" -require "active_support/core_ext/array/inquiry" +# frozen_string_literal: true +require_relative "array/wrap" +require_relative "array/access" +require_relative "array/conversions" +require_relative "array/extract_options" +require_relative "array/grouping" +require_relative "array/prepend_and_append" +require_relative "array/inquiry" diff --git a/activesupport/lib/active_support/core_ext/array/access.rb b/activesupport/lib/active_support/core_ext/array/access.rb index fca33c9d69..b6e576ad29 100644 --- a/activesupport/lib/active_support/core_ext/array/access.rb +++ b/activesupport/lib/active_support/core_ext/array/access.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Array # Returns the tail of the array from +position+. # diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb index cac15e1100..eeafde78a4 100644 --- a/activesupport/lib/active_support/core_ext/array/conversions.rb +++ b/activesupport/lib/active_support/core_ext/array/conversions.rb @@ -1,8 +1,9 @@ -require "active_support/xml_mini" -require "active_support/core_ext/hash/keys" -require "active_support/core_ext/string/inflections" -require "active_support/core_ext/object/to_param" -require "active_support/core_ext/object/to_query" +# frozen_string_literal: true +require_relative "../../xml_mini" +require_relative "../hash/keys" +require_relative "../string/inflections" +require_relative "../object/to_param" +require_relative "../object/to_query" class Array # Converts the array to a comma-separated sentence where the last element is @@ -179,7 +180,7 @@ class Array # </messages> # def to_xml(options = {}) - require "active_support/builder" unless defined?(Builder) + require_relative "../../builder" unless defined?(Builder) options = options.dup options[:indent] ||= 2 diff --git a/activesupport/lib/active_support/core_ext/array/extract_options.rb b/activesupport/lib/active_support/core_ext/array/extract_options.rb index 9008a0df2a..8204d42caf 100644 --- a/activesupport/lib/active_support/core_ext/array/extract_options.rb +++ b/activesupport/lib/active_support/core_ext/array/extract_options.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Hash # By default, only instances of Hash itself are extractable. # Subclasses of Hash may implement this method and return diff --git a/activesupport/lib/active_support/core_ext/array/grouping.rb b/activesupport/lib/active_support/core_ext/array/grouping.rb index 0d798e5c4e..706c576691 100644 --- a/activesupport/lib/active_support/core_ext/array/grouping.rb +++ b/activesupport/lib/active_support/core_ext/array/grouping.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Array # Splits or iterates over the array in groups of size +number+, # padding any remaining slots with +fill_with+ unless it is +false+. diff --git a/activesupport/lib/active_support/core_ext/array/inquiry.rb b/activesupport/lib/active_support/core_ext/array/inquiry.rb index 66fa5fcd0c..b8a1bbdbc7 100644 --- a/activesupport/lib/active_support/core_ext/array/inquiry.rb +++ b/activesupport/lib/active_support/core_ext/array/inquiry.rb @@ -1,4 +1,5 @@ -require "active_support/array_inquirer" +# frozen_string_literal: true +require_relative "../../array_inquirer" class Array # Wraps the array in an +ArrayInquirer+ object, which gives a friendlier way diff --git a/activesupport/lib/active_support/core_ext/array/prepend_and_append.rb b/activesupport/lib/active_support/core_ext/array/prepend_and_append.rb index 88a34128c9..2dd1547765 100644 --- a/activesupport/lib/active_support/core_ext/array/prepend_and_append.rb +++ b/activesupport/lib/active_support/core_ext/array/prepend_and_append.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Array # The human way of thinking about adding stuff to the end of a list is with append. alias_method :append, :push unless [].respond_to?(:append) diff --git a/activesupport/lib/active_support/core_ext/array/wrap.rb b/activesupport/lib/active_support/core_ext/array/wrap.rb index b611d34c27..adb25718e4 100644 --- a/activesupport/lib/active_support/core_ext/array/wrap.rb +++ b/activesupport/lib/active_support/core_ext/array/wrap.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Array # Wraps its argument in an array unless it is already an array (or array-like). # diff --git a/activesupport/lib/active_support/core_ext/benchmark.rb b/activesupport/lib/active_support/core_ext/benchmark.rb index 2300953860..2db6e5f1c5 100644 --- a/activesupport/lib/active_support/core_ext/benchmark.rb +++ b/activesupport/lib/active_support/core_ext/benchmark.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "benchmark" class << Benchmark diff --git a/activesupport/lib/active_support/core_ext/big_decimal.rb b/activesupport/lib/active_support/core_ext/big_decimal.rb index 7b4f87f10e..fd860f6fbd 100644 --- a/activesupport/lib/active_support/core_ext/big_decimal.rb +++ b/activesupport/lib/active_support/core_ext/big_decimal.rb @@ -1 +1,2 @@ -require "active_support/core_ext/big_decimal/conversions" +# frozen_string_literal: true +require_relative "big_decimal/conversions" diff --git a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb index decd4e1699..1729f00530 100644 --- a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb +++ b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "bigdecimal" require "bigdecimal/util" diff --git a/activesupport/lib/active_support/core_ext/class.rb b/activesupport/lib/active_support/core_ext/class.rb index 6a19e862d0..882102831f 100644 --- a/activesupport/lib/active_support/core_ext/class.rb +++ b/activesupport/lib/active_support/core_ext/class.rb @@ -1,2 +1,3 @@ -require "active_support/core_ext/class/attribute" -require "active_support/core_ext/class/subclasses" +# frozen_string_literal: true +require_relative "class/attribute" +require_relative "class/subclasses" diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb index 8caddcd5c3..a6da65e96d 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute.rb @@ -1,6 +1,7 @@ -require "active_support/core_ext/kernel/singleton_class" -require "active_support/core_ext/module/remove_method" -require "active_support/core_ext/array/extract_options" +# frozen_string_literal: true +require_relative "../kernel/singleton_class" +require_relative "../module/remove_method" +require_relative "../array/extract_options" class Class # Declare a class-level attribute whose value is inheritable by subclasses. diff --git a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb index 0f767925ed..0345478c59 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb @@ -1,4 +1,5 @@ +# frozen_string_literal: true # cattr_* became mattr_* aliases in 7dfbd91b0780fbd6a1dd9bfbc176e10894871d2d, # but we keep this around for libraries that directly require it knowing they # want cattr_*. No need to deprecate. -require "active_support/core_ext/module/attribute_accessors" +require_relative "../module/attribute_accessors" diff --git a/activesupport/lib/active_support/core_ext/class/subclasses.rb b/activesupport/lib/active_support/core_ext/class/subclasses.rb index 62397d9508..ce7b422cfb 100644 --- a/activesupport/lib/active_support/core_ext/class/subclasses.rb +++ b/activesupport/lib/active_support/core_ext/class/subclasses.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/module/anonymous" -require "active_support/core_ext/module/reachable" +# frozen_string_literal: true +require_relative "../module/anonymous" +require_relative "../module/reachable" class Class begin diff --git a/activesupport/lib/active_support/core_ext/date.rb b/activesupport/lib/active_support/core_ext/date.rb index 4f66804da2..88bae739b6 100644 --- a/activesupport/lib/active_support/core_ext/date.rb +++ b/activesupport/lib/active_support/core_ext/date.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/date/acts_like" -require "active_support/core_ext/date/blank" -require "active_support/core_ext/date/calculations" -require "active_support/core_ext/date/conversions" -require "active_support/core_ext/date/zones" +# frozen_string_literal: true +require_relative "date/acts_like" +require_relative "date/blank" +require_relative "date/calculations" +require_relative "date/conversions" +require_relative "date/zones" diff --git a/activesupport/lib/active_support/core_ext/date/acts_like.rb b/activesupport/lib/active_support/core_ext/date/acts_like.rb index 46fe99ad47..c8ab7b5241 100644 --- a/activesupport/lib/active_support/core_ext/date/acts_like.rb +++ b/activesupport/lib/active_support/core_ext/date/acts_like.rb @@ -1,4 +1,5 @@ -require "active_support/core_ext/object/acts_like" +# frozen_string_literal: true +require_relative "../object/acts_like" class Date # Duck-types as a Date-like class. See Object#acts_like?. diff --git a/activesupport/lib/active_support/core_ext/date/blank.rb b/activesupport/lib/active_support/core_ext/date/blank.rb index edd2847126..a28e726902 100644 --- a/activesupport/lib/active_support/core_ext/date/blank.rb +++ b/activesupport/lib/active_support/core_ext/date/blank.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "date" class Date #:nodoc: diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb index d6f60cac04..d0ac71210a 100644 --- a/activesupport/lib/active_support/core_ext/date/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date/calculations.rb @@ -1,9 +1,10 @@ +# frozen_string_literal: true require "date" -require "active_support/duration" -require "active_support/core_ext/object/acts_like" -require "active_support/core_ext/date/zones" -require "active_support/core_ext/time/zones" -require "active_support/core_ext/date_and_time/calculations" +require_relative "../../duration" +require_relative "../object/acts_like" +require_relative "zones" +require_relative "../time/zones" +require_relative "../date_and_time/calculations" class Date include DateAndTime::Calculations diff --git a/activesupport/lib/active_support/core_ext/date/conversions.rb b/activesupport/lib/active_support/core_ext/date/conversions.rb index 0f59c754fe..6c493dc2c8 100644 --- a/activesupport/lib/active_support/core_ext/date/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date/conversions.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true require "date" -require "active_support/inflector/methods" -require "active_support/core_ext/date/zones" -require "active_support/core_ext/module/remove_method" +require_relative "../../inflector/methods" +require_relative "zones" +require_relative "../module/remove_method" class Date DATE_FORMATS = { diff --git a/activesupport/lib/active_support/core_ext/date/zones.rb b/activesupport/lib/active_support/core_ext/date/zones.rb index da23fe4892..f9bb6f733b 100644 --- a/activesupport/lib/active_support/core_ext/date/zones.rb +++ b/activesupport/lib/active_support/core_ext/date/zones.rb @@ -1,5 +1,6 @@ +# frozen_string_literal: true require "date" -require "active_support/core_ext/date_and_time/zones" +require_relative "../date_and_time/zones" class Date include DateAndTime::Zones diff --git a/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb index e2e1d3e359..4e93851259 100644 --- a/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb @@ -1,4 +1,5 @@ -require "active_support/core_ext/object/try" +# frozen_string_literal: true +require_relative "../object/try" module DateAndTime module Calculations diff --git a/activesupport/lib/active_support/core_ext/date_and_time/compatibility.rb b/activesupport/lib/active_support/core_ext/date_and_time/compatibility.rb index 2d45e16546..ffb1cbd6e5 100644 --- a/activesupport/lib/active_support/core_ext/date_and_time/compatibility.rb +++ b/activesupport/lib/active_support/core_ext/date_and_time/compatibility.rb @@ -1,4 +1,5 @@ -require "active_support/core_ext/module/attribute_accessors" +# frozen_string_literal: true +require_relative "../module/attribute_accessors" module DateAndTime module Compatibility diff --git a/activesupport/lib/active_support/core_ext/date_and_time/zones.rb b/activesupport/lib/active_support/core_ext/date_and_time/zones.rb index edd724f1d0..4cc94d4ece 100644 --- a/activesupport/lib/active_support/core_ext/date_and_time/zones.rb +++ b/activesupport/lib/active_support/core_ext/date_and_time/zones.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module DateAndTime module Zones # Returns the simultaneous time in <tt>Time.zone</tt> if a zone is given or diff --git a/activesupport/lib/active_support/core_ext/date_time.rb b/activesupport/lib/active_support/core_ext/date_time.rb index 6fd498f864..fba37a5169 100644 --- a/activesupport/lib/active_support/core_ext/date_time.rb +++ b/activesupport/lib/active_support/core_ext/date_time.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/date_time/acts_like" -require "active_support/core_ext/date_time/blank" -require "active_support/core_ext/date_time/calculations" -require "active_support/core_ext/date_time/compatibility" -require "active_support/core_ext/date_time/conversions" +# frozen_string_literal: true +require_relative "date_time/acts_like" +require_relative "date_time/blank" +require_relative "date_time/calculations" +require_relative "date_time/compatibility" +require_relative "date_time/conversions" diff --git a/activesupport/lib/active_support/core_ext/date_time/acts_like.rb b/activesupport/lib/active_support/core_ext/date_time/acts_like.rb index 6f50f55a53..74a2758830 100644 --- a/activesupport/lib/active_support/core_ext/date_time/acts_like.rb +++ b/activesupport/lib/active_support/core_ext/date_time/acts_like.rb @@ -1,5 +1,6 @@ +# frozen_string_literal: true require "date" -require "active_support/core_ext/object/acts_like" +require_relative "../object/acts_like" class DateTime # Duck-types as a Date-like class. See Object#acts_like?. diff --git a/activesupport/lib/active_support/core_ext/date_time/blank.rb b/activesupport/lib/active_support/core_ext/date_time/blank.rb index b475fd926d..874c7554a3 100644 --- a/activesupport/lib/active_support/core_ext/date_time/blank.rb +++ b/activesupport/lib/active_support/core_ext/date_time/blank.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "date" class DateTime #:nodoc: diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb index 7a9eb8c266..91289175ed 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "date" class DateTime diff --git a/activesupport/lib/active_support/core_ext/date_time/compatibility.rb b/activesupport/lib/active_support/core_ext/date_time/compatibility.rb index 870391aeaa..e2bb02d855 100644 --- a/activesupport/lib/active_support/core_ext/date_time/compatibility.rb +++ b/activesupport/lib/active_support/core_ext/date_time/compatibility.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/date_and_time/compatibility" -require "active_support/core_ext/module/remove_method" +# frozen_string_literal: true +require_relative "../date_and_time/compatibility" +require_relative "../module/remove_method" class DateTime include DateAndTime::Compatibility diff --git a/activesupport/lib/active_support/core_ext/date_time/conversions.rb b/activesupport/lib/active_support/core_ext/date_time/conversions.rb index d9b3743858..2a35f9dbfb 100644 --- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true require "date" -require "active_support/inflector/methods" -require "active_support/core_ext/time/conversions" -require "active_support/core_ext/date_time/calculations" -require "active_support/values/time_zone" +require_relative "../../inflector/methods" +require_relative "../time/conversions" +require_relative "calculations" +require_relative "../../values/time_zone" class DateTime # Convert to a formatted string. See Time::DATE_FORMATS for predefined formats. diff --git a/activesupport/lib/active_support/core_ext/digest/uuid.rb b/activesupport/lib/active_support/core_ext/digest/uuid.rb index e6d60e3267..26a300feb6 100644 --- a/activesupport/lib/active_support/core_ext/digest/uuid.rb +++ b/activesupport/lib/active_support/core_ext/digest/uuid.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "securerandom" module Digest diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index 3a4ae6cb8b..a744b78e1c 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Enumerable # Enumerable#sum was added in Ruby 2.4, but it only works with Numeric elements # when we omit an identity. diff --git a/activesupport/lib/active_support/core_ext/file.rb b/activesupport/lib/active_support/core_ext/file.rb index 6d99bad2af..9de5fbb63c 100644 --- a/activesupport/lib/active_support/core_ext/file.rb +++ b/activesupport/lib/active_support/core_ext/file.rb @@ -1 +1,2 @@ -require "active_support/core_ext/file/atomic" +# frozen_string_literal: true +require_relative "file/atomic" diff --git a/activesupport/lib/active_support/core_ext/file/atomic.rb b/activesupport/lib/active_support/core_ext/file/atomic.rb index 8d6c0d3685..5b30e93357 100644 --- a/activesupport/lib/active_support/core_ext/file/atomic.rb +++ b/activesupport/lib/active_support/core_ext/file/atomic.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "fileutils" class File diff --git a/activesupport/lib/active_support/core_ext/hash.rb b/activesupport/lib/active_support/core_ext/hash.rb index c819307e8a..24b6adeb5f 100644 --- a/activesupport/lib/active_support/core_ext/hash.rb +++ b/activesupport/lib/active_support/core_ext/hash.rb @@ -1,9 +1,10 @@ -require "active_support/core_ext/hash/compact" -require "active_support/core_ext/hash/conversions" -require "active_support/core_ext/hash/deep_merge" -require "active_support/core_ext/hash/except" -require "active_support/core_ext/hash/indifferent_access" -require "active_support/core_ext/hash/keys" -require "active_support/core_ext/hash/reverse_merge" -require "active_support/core_ext/hash/slice" -require "active_support/core_ext/hash/transform_values" +# frozen_string_literal: true +require_relative "hash/compact" +require_relative "hash/conversions" +require_relative "hash/deep_merge" +require_relative "hash/except" +require_relative "hash/indifferent_access" +require_relative "hash/keys" +require_relative "hash/reverse_merge" +require_relative "hash/slice" +require_relative "hash/transform_values" diff --git a/activesupport/lib/active_support/core_ext/hash/compact.rb b/activesupport/lib/active_support/core_ext/hash/compact.rb index e357284be0..ddccbe7d16 100644 --- a/activesupport/lib/active_support/core_ext/hash/compact.rb +++ b/activesupport/lib/active_support/core_ext/hash/compact.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Hash unless Hash.instance_methods(false).include?(:compact) # Returns a hash with non +nil+ values. diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index 2a58a7f1ca..193004608a 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -1,11 +1,12 @@ -require "active_support/xml_mini" -require "active_support/time" -require "active_support/core_ext/object/blank" -require "active_support/core_ext/object/to_param" -require "active_support/core_ext/object/to_query" -require "active_support/core_ext/array/wrap" -require "active_support/core_ext/hash/reverse_merge" -require "active_support/core_ext/string/inflections" +# frozen_string_literal: true +require_relative "../../xml_mini" +require_relative "../../time" +require_relative "../object/blank" +require_relative "../object/to_param" +require_relative "../object/to_query" +require_relative "../array/wrap" +require_relative "reverse_merge" +require_relative "../string/inflections" class Hash # Returns a string containing an XML representation of its receiver: @@ -71,7 +72,7 @@ class Hash # configure your own builder with the <tt>:builder</tt> option. The method also accepts # options like <tt>:dasherize</tt> and friends, they are forwarded to the builder. def to_xml(options = {}) - require "active_support/builder" unless defined?(Builder) + require_relative "../../builder" unless defined?(Builder) options = options.dup options[:indent] ||= 2 diff --git a/activesupport/lib/active_support/core_ext/hash/deep_merge.rb b/activesupport/lib/active_support/core_ext/hash/deep_merge.rb index 9c9faf67ea..1c6627a597 100644 --- a/activesupport/lib/active_support/core_ext/hash/deep_merge.rb +++ b/activesupport/lib/active_support/core_ext/hash/deep_merge.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Hash # Returns a new hash with +self+ and +other_hash+ merged recursively. # diff --git a/activesupport/lib/active_support/core_ext/hash/except.rb b/activesupport/lib/active_support/core_ext/hash/except.rb index 2f6d38c1f6..e31c7c61e4 100644 --- a/activesupport/lib/active_support/core_ext/hash/except.rb +++ b/activesupport/lib/active_support/core_ext/hash/except.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Hash # Returns a hash that includes everything except given keys. # hash = { a: true, b: false, c: nil } diff --git a/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb b/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb index 3e1ccecb6c..7727f0751e 100644 --- a/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb +++ b/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb @@ -1,4 +1,5 @@ -require "active_support/hash_with_indifferent_access" +# frozen_string_literal: true +require_relative "../../hash_with_indifferent_access" class Hash # Returns an <tt>ActiveSupport::HashWithIndifferentAccess</tt> out of its receiver: diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb index b7089357a8..b38ea9ba50 100644 --- a/activesupport/lib/active_support/core_ext/hash/keys.rb +++ b/activesupport/lib/active_support/core_ext/hash/keys.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Hash # Returns a new hash with all keys converted using the +block+ operation. # diff --git a/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb b/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb index 061c959442..2055d06385 100644 --- a/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb +++ b/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Hash # Merges the caller into +other_hash+. For example, # diff --git a/activesupport/lib/active_support/core_ext/hash/slice.rb b/activesupport/lib/active_support/core_ext/hash/slice.rb index 161b00dfb3..bd370931e4 100644 --- a/activesupport/lib/active_support/core_ext/hash/slice.rb +++ b/activesupport/lib/active_support/core_ext/hash/slice.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Hash # Slices a hash to include only the given keys. Returns a hash containing # the given keys. diff --git a/activesupport/lib/active_support/core_ext/hash/transform_values.rb b/activesupport/lib/active_support/core_ext/hash/transform_values.rb index 2f693bff0c..b6e2734193 100644 --- a/activesupport/lib/active_support/core_ext/hash/transform_values.rb +++ b/activesupport/lib/active_support/core_ext/hash/transform_values.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Hash # Returns a new hash with the results of running +block+ once for every value. # The keys are unchanged. diff --git a/activesupport/lib/active_support/core_ext/integer.rb b/activesupport/lib/active_support/core_ext/integer.rb index 8f0c55f9d3..2042b5d311 100644 --- a/activesupport/lib/active_support/core_ext/integer.rb +++ b/activesupport/lib/active_support/core_ext/integer.rb @@ -1,3 +1,4 @@ -require "active_support/core_ext/integer/multiple" -require "active_support/core_ext/integer/inflections" -require "active_support/core_ext/integer/time" +# frozen_string_literal: true +require_relative "integer/multiple" +require_relative "integer/inflections" +require_relative "integer/time" diff --git a/activesupport/lib/active_support/core_ext/integer/inflections.rb b/activesupport/lib/active_support/core_ext/integer/inflections.rb index bc21b65533..de756446ba 100644 --- a/activesupport/lib/active_support/core_ext/integer/inflections.rb +++ b/activesupport/lib/active_support/core_ext/integer/inflections.rb @@ -1,4 +1,5 @@ -require "active_support/inflector" +# frozen_string_literal: true +require_relative "../../inflector" class Integer # Ordinalize turns a number into an ordinal string used to denote the diff --git a/activesupport/lib/active_support/core_ext/integer/multiple.rb b/activesupport/lib/active_support/core_ext/integer/multiple.rb index c668c7c2eb..2e4d78e66c 100644 --- a/activesupport/lib/active_support/core_ext/integer/multiple.rb +++ b/activesupport/lib/active_support/core_ext/integer/multiple.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Integer # Check whether the integer is evenly divisible by the argument. # diff --git a/activesupport/lib/active_support/core_ext/integer/time.rb b/activesupport/lib/active_support/core_ext/integer/time.rb index 74baae3639..583ef456f3 100644 --- a/activesupport/lib/active_support/core_ext/integer/time.rb +++ b/activesupport/lib/active_support/core_ext/integer/time.rb @@ -1,5 +1,6 @@ -require "active_support/duration" -require "active_support/core_ext/numeric/time" +# frozen_string_literal: true +require_relative "../../duration" +require_relative "../numeric/time" class Integer # Enables the use of time calculations and declarations, like <tt>45.minutes + diff --git a/activesupport/lib/active_support/core_ext/kernel.rb b/activesupport/lib/active_support/core_ext/kernel.rb index 3d41ff7876..9ac0ba3749 100644 --- a/activesupport/lib/active_support/core_ext/kernel.rb +++ b/activesupport/lib/active_support/core_ext/kernel.rb @@ -1,4 +1,5 @@ -require "active_support/core_ext/kernel/agnostics" -require "active_support/core_ext/kernel/concern" -require "active_support/core_ext/kernel/reporting" -require "active_support/core_ext/kernel/singleton_class" +# frozen_string_literal: true +require_relative "kernel/agnostics" +require_relative "kernel/concern" +require_relative "kernel/reporting" +require_relative "kernel/singleton_class" diff --git a/activesupport/lib/active_support/core_ext/kernel/agnostics.rb b/activesupport/lib/active_support/core_ext/kernel/agnostics.rb index 64837d87aa..84a48979c4 100644 --- a/activesupport/lib/active_support/core_ext/kernel/agnostics.rb +++ b/activesupport/lib/active_support/core_ext/kernel/agnostics.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Object # Makes backticks behave (somewhat more) similarly on all platforms. # On win32 `nonexistent_command` raises Errno::ENOENT; on Unix, the diff --git a/activesupport/lib/active_support/core_ext/kernel/concern.rb b/activesupport/lib/active_support/core_ext/kernel/concern.rb index 307a7f7a63..e6df8aa46e 100644 --- a/activesupport/lib/active_support/core_ext/kernel/concern.rb +++ b/activesupport/lib/active_support/core_ext/kernel/concern.rb @@ -1,4 +1,5 @@ -require "active_support/core_ext/module/concerning" +# frozen_string_literal: true +require_relative "../module/concerning" module Kernel module_function diff --git a/activesupport/lib/active_support/core_ext/kernel/reporting.rb b/activesupport/lib/active_support/core_ext/kernel/reporting.rb index c02618d5f3..822efb5aae 100644 --- a/activesupport/lib/active_support/core_ext/kernel/reporting.rb +++ b/activesupport/lib/active_support/core_ext/kernel/reporting.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Kernel module_function diff --git a/activesupport/lib/active_support/core_ext/kernel/singleton_class.rb b/activesupport/lib/active_support/core_ext/kernel/singleton_class.rb index 9bbf1bbd73..5f9c008f6e 100644 --- a/activesupport/lib/active_support/core_ext/kernel/singleton_class.rb +++ b/activesupport/lib/active_support/core_ext/kernel/singleton_class.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Kernel # class_eval on an object acts like singleton_class.class_eval. def class_eval(*args, &block) diff --git a/activesupport/lib/active_support/core_ext/load_error.rb b/activesupport/lib/active_support/core_ext/load_error.rb index d273487010..55177efdaf 100644 --- a/activesupport/lib/active_support/core_ext/load_error.rb +++ b/activesupport/lib/active_support/core_ext/load_error.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class LoadError REGEXPS = [ /^no such file to load -- (.+)$/i, diff --git a/activesupport/lib/active_support/core_ext/marshal.rb b/activesupport/lib/active_support/core_ext/marshal.rb index bba2b3be2e..13b1d0cf95 100644 --- a/activesupport/lib/active_support/core_ext/marshal.rb +++ b/activesupport/lib/active_support/core_ext/marshal.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport module MarshalWithAutoloading # :nodoc: def load(source, proc = nil) diff --git a/activesupport/lib/active_support/core_ext/module.rb b/activesupport/lib/active_support/core_ext/module.rb index 2930255557..6c304292eb 100644 --- a/activesupport/lib/active_support/core_ext/module.rb +++ b/activesupport/lib/active_support/core_ext/module.rb @@ -1,11 +1,12 @@ -require "active_support/core_ext/module/aliasing" -require "active_support/core_ext/module/introspection" -require "active_support/core_ext/module/anonymous" -require "active_support/core_ext/module/reachable" -require "active_support/core_ext/module/attribute_accessors" -require "active_support/core_ext/module/attribute_accessors_per_thread" -require "active_support/core_ext/module/attr_internal" -require "active_support/core_ext/module/concerning" -require "active_support/core_ext/module/delegation" -require "active_support/core_ext/module/deprecation" -require "active_support/core_ext/module/remove_method" +# frozen_string_literal: true +require_relative "module/aliasing" +require_relative "module/introspection" +require_relative "module/anonymous" +require_relative "module/reachable" +require_relative "module/attribute_accessors" +require_relative "module/attribute_accessors_per_thread" +require_relative "module/attr_internal" +require_relative "module/concerning" +require_relative "module/delegation" +require_relative "module/deprecation" +require_relative "module/remove_method" diff --git a/activesupport/lib/active_support/core_ext/module/aliasing.rb b/activesupport/lib/active_support/core_ext/module/aliasing.rb index c48bd3354a..62eb9e4c76 100644 --- a/activesupport/lib/active_support/core_ext/module/aliasing.rb +++ b/activesupport/lib/active_support/core_ext/module/aliasing.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Module # Allows you to make aliases for attributes, which includes # getter, setter, and a predicate. diff --git a/activesupport/lib/active_support/core_ext/module/anonymous.rb b/activesupport/lib/active_support/core_ext/module/anonymous.rb index 510c9a5430..7d10240199 100644 --- a/activesupport/lib/active_support/core_ext/module/anonymous.rb +++ b/activesupport/lib/active_support/core_ext/module/anonymous.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Module # A module may or may not have a name. # diff --git a/activesupport/lib/active_support/core_ext/module/attr_internal.rb b/activesupport/lib/active_support/core_ext/module/attr_internal.rb index 5081d5f7a3..8d37460dbc 100644 --- a/activesupport/lib/active_support/core_ext/module/attr_internal.rb +++ b/activesupport/lib/active_support/core_ext/module/attr_internal.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Module # Declares an attribute reader backed by an internally-named instance variable. def attr_internal_reader(*attrs) diff --git a/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb index 9244cfa157..430b1accbc 100644 --- a/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb +++ b/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/array/extract_options" -require "active_support/core_ext/regexp" +# frozen_string_literal: true +require_relative "../array/extract_options" +require_relative "../regexp" # Extends the module object with class/module and instance accessors for # class/module attributes, just like the native attr* accessors for instance diff --git a/activesupport/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb b/activesupport/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb index 1e82b4acc2..bc5d4b6dda 100644 --- a/activesupport/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +++ b/activesupport/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/array/extract_options" -require "active_support/core_ext/regexp" +# frozen_string_literal: true +require_relative "../array/extract_options" +require_relative "../regexp" # Extends the module object with class/module and instance accessors for # class/module attributes, just like the native attr* accessors for instance diff --git a/activesupport/lib/active_support/core_ext/module/concerning.rb b/activesupport/lib/active_support/core_ext/module/concerning.rb index 97b0a382ce..e4e49746b6 100644 --- a/activesupport/lib/active_support/core_ext/module/concerning.rb +++ b/activesupport/lib/active_support/core_ext/module/concerning.rb @@ -1,4 +1,5 @@ -require "active_support/concern" +# frozen_string_literal: true +require_relative "../../concern" class Module # = Bite-sized separation of concerns diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index 13f3894e6c..46c84eb509 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -1,5 +1,6 @@ +# frozen_string_literal: true require "set" -require "active_support/core_ext/regexp" +require_relative "../regexp" class Module # Error generated by +delegate+ when a method is called on +nil+ and +allow_nil+ @@ -174,7 +175,7 @@ class Module to = to.to_s to = "self.#{to}" if DELEGATION_RESERVED_METHOD_NAMES.include?(to) - methods.each do |method| + methods.map do |method| # Attribute writer methods only accept one argument. Makes sure []= # methods still accept two arguments. definition = /[^\]]=$/.match?(method) ? "arg" : "*args, &block" diff --git a/activesupport/lib/active_support/core_ext/module/deprecation.rb b/activesupport/lib/active_support/core_ext/module/deprecation.rb index f3f2e7f5fc..98dfaad760 100644 --- a/activesupport/lib/active_support/core_ext/module/deprecation.rb +++ b/activesupport/lib/active_support/core_ext/module/deprecation.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Module # deprecate :foo # deprecate bar: 'message' diff --git a/activesupport/lib/active_support/core_ext/module/introspection.rb b/activesupport/lib/active_support/core_ext/module/introspection.rb index ca20a6d4c5..69122885ec 100644 --- a/activesupport/lib/active_support/core_ext/module/introspection.rb +++ b/activesupport/lib/active_support/core_ext/module/introspection.rb @@ -1,4 +1,5 @@ -require "active_support/inflector" +# frozen_string_literal: true +require_relative "../../inflector" class Module # Returns the name of the module containing this one. diff --git a/activesupport/lib/active_support/core_ext/module/reachable.rb b/activesupport/lib/active_support/core_ext/module/reachable.rb index b89a38f26c..023894055f 100644 --- a/activesupport/lib/active_support/core_ext/module/reachable.rb +++ b/activesupport/lib/active_support/core_ext/module/reachable.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/module/anonymous" -require "active_support/core_ext/string/inflections" +# frozen_string_literal: true +require_relative "anonymous" +require_relative "../string/inflections" class Module def reachable? #:nodoc: diff --git a/activesupport/lib/active_support/core_ext/module/remove_method.rb b/activesupport/lib/active_support/core_ext/module/remove_method.rb index d5ec16d68a..c17808b244 100644 --- a/activesupport/lib/active_support/core_ext/module/remove_method.rb +++ b/activesupport/lib/active_support/core_ext/module/remove_method.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Module # Removes the named method, if it exists. def remove_possible_method(method) diff --git a/activesupport/lib/active_support/core_ext/name_error.rb b/activesupport/lib/active_support/core_ext/name_error.rb index 6b447d772b..1bcb6ded3c 100644 --- a/activesupport/lib/active_support/core_ext/name_error.rb +++ b/activesupport/lib/active_support/core_ext/name_error.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class NameError # Extract the name of the missing constant from the exception message. # diff --git a/activesupport/lib/active_support/core_ext/numeric.rb b/activesupport/lib/active_support/core_ext/numeric.rb index 6062f9e3a8..6c407bc1ff 100644 --- a/activesupport/lib/active_support/core_ext/numeric.rb +++ b/activesupport/lib/active_support/core_ext/numeric.rb @@ -1,4 +1,5 @@ -require "active_support/core_ext/numeric/bytes" -require "active_support/core_ext/numeric/time" -require "active_support/core_ext/numeric/inquiry" -require "active_support/core_ext/numeric/conversions" +# frozen_string_literal: true +require_relative "numeric/bytes" +require_relative "numeric/time" +require_relative "numeric/inquiry" +require_relative "numeric/conversions" diff --git a/activesupport/lib/active_support/core_ext/numeric/bytes.rb b/activesupport/lib/active_support/core_ext/numeric/bytes.rb index dfbca32474..23e1e39dd8 100644 --- a/activesupport/lib/active_support/core_ext/numeric/bytes.rb +++ b/activesupport/lib/active_support/core_ext/numeric/bytes.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Numeric KILOBYTE = 1024 MEGABYTE = KILOBYTE * 1024 diff --git a/activesupport/lib/active_support/core_ext/numeric/conversions.rb b/activesupport/lib/active_support/core_ext/numeric/conversions.rb index 4f6621693e..b8cff9aeb9 100644 --- a/activesupport/lib/active_support/core_ext/numeric/conversions.rb +++ b/activesupport/lib/active_support/core_ext/numeric/conversions.rb @@ -1,6 +1,7 @@ -require "active_support/core_ext/big_decimal/conversions" -require "active_support/number_helper" -require "active_support/core_ext/module/deprecation" +# frozen_string_literal: true +require_relative "../big_decimal/conversions" +require_relative "../../number_helper" +require_relative "../module/deprecation" module ActiveSupport::NumericWithFormat # Provides options for converting numbers into formatted strings. diff --git a/activesupport/lib/active_support/core_ext/numeric/inquiry.rb b/activesupport/lib/active_support/core_ext/numeric/inquiry.rb index ec79701189..baccf87848 100644 --- a/activesupport/lib/active_support/core_ext/numeric/inquiry.rb +++ b/activesupport/lib/active_support/core_ext/numeric/inquiry.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true unless 1.respond_to?(:positive?) # TODO: Remove this file when we drop support to ruby < 2.3 class Numeric # Returns true if the number is positive. diff --git a/activesupport/lib/active_support/core_ext/numeric/time.rb b/activesupport/lib/active_support/core_ext/numeric/time.rb index 2e6c70d418..382a8cd162 100644 --- a/activesupport/lib/active_support/core_ext/numeric/time.rb +++ b/activesupport/lib/active_support/core_ext/numeric/time.rb @@ -1,8 +1,9 @@ -require "active_support/duration" -require "active_support/core_ext/time/calculations" -require "active_support/core_ext/time/acts_like" -require "active_support/core_ext/date/calculations" -require "active_support/core_ext/date/acts_like" +# frozen_string_literal: true +require_relative "../../duration" +require_relative "../time/calculations" +require_relative "../time/acts_like" +require_relative "../date/calculations" +require_relative "../date/acts_like" class Numeric # Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years. diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb index 58bbf78601..cd350d5c45 100644 --- a/activesupport/lib/active_support/core_ext/object.rb +++ b/activesupport/lib/active_support/core_ext/object.rb @@ -1,14 +1,15 @@ -require "active_support/core_ext/object/acts_like" -require "active_support/core_ext/object/blank" -require "active_support/core_ext/object/duplicable" -require "active_support/core_ext/object/deep_dup" -require "active_support/core_ext/object/try" -require "active_support/core_ext/object/inclusion" +# frozen_string_literal: true +require_relative "object/acts_like" +require_relative "object/blank" +require_relative "object/duplicable" +require_relative "object/deep_dup" +require_relative "object/try" +require_relative "object/inclusion" -require "active_support/core_ext/object/conversions" -require "active_support/core_ext/object/instance_variables" +require_relative "object/conversions" +require_relative "object/instance_variables" -require "active_support/core_ext/object/json" -require "active_support/core_ext/object/to_param" -require "active_support/core_ext/object/to_query" -require "active_support/core_ext/object/with_options" +require_relative "object/json" +require_relative "object/to_param" +require_relative "object/to_query" +require_relative "object/with_options" diff --git a/activesupport/lib/active_support/core_ext/object/acts_like.rb b/activesupport/lib/active_support/core_ext/object/acts_like.rb index 3912cc5ace..b856e1ba16 100644 --- a/activesupport/lib/active_support/core_ext/object/acts_like.rb +++ b/activesupport/lib/active_support/core_ext/object/acts_like.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Object # A duck-type assistant method. For example, Active Support extends Date # to define an <tt>acts_like_date?</tt> method, and extends Time to define diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index bdb50ee291..fd10e1bf72 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -1,4 +1,5 @@ -require "active_support/core_ext/regexp" +# frozen_string_literal: true +require_relative "../regexp" class Object # An object is blank if it's false, empty, or a whitespace string. diff --git a/activesupport/lib/active_support/core_ext/object/conversions.rb b/activesupport/lib/active_support/core_ext/object/conversions.rb index 918ebcdc9f..846e3a4fa7 100644 --- a/activesupport/lib/active_support/core_ext/object/conversions.rb +++ b/activesupport/lib/active_support/core_ext/object/conversions.rb @@ -1,4 +1,5 @@ -require "active_support/core_ext/object/to_param" -require "active_support/core_ext/object/to_query" -require "active_support/core_ext/array/conversions" -require "active_support/core_ext/hash/conversions" +# frozen_string_literal: true +require_relative "to_param" +require_relative "to_query" +require_relative "../array/conversions" +require_relative "../hash/conversions" diff --git a/activesupport/lib/active_support/core_ext/object/deep_dup.rb b/activesupport/lib/active_support/core_ext/object/deep_dup.rb index 5ac649e552..ac7537b500 100644 --- a/activesupport/lib/active_support/core_ext/object/deep_dup.rb +++ b/activesupport/lib/active_support/core_ext/object/deep_dup.rb @@ -1,4 +1,5 @@ -require "active_support/core_ext/object/duplicable" +# frozen_string_literal: true +require_relative "duplicable" class Object # Returns a deep copy of object if it's duplicable. If it's diff --git a/activesupport/lib/active_support/core_ext/object/duplicable.rb b/activesupport/lib/active_support/core_ext/object/duplicable.rb index b028df97ee..0838b1fb70 100644 --- a/activesupport/lib/active_support/core_ext/object/duplicable.rb +++ b/activesupport/lib/active_support/core_ext/object/duplicable.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true #-- # Most objects are cloneable, but not all. For example you can't dup methods: # diff --git a/activesupport/lib/active_support/core_ext/object/inclusion.rb b/activesupport/lib/active_support/core_ext/object/inclusion.rb index 98bf820d36..525ddcb575 100644 --- a/activesupport/lib/active_support/core_ext/object/inclusion.rb +++ b/activesupport/lib/active_support/core_ext/object/inclusion.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Object # Returns true if this object is included in the argument. Argument must be # any object which responds to +#include?+. Usage: diff --git a/activesupport/lib/active_support/core_ext/object/instance_variables.rb b/activesupport/lib/active_support/core_ext/object/instance_variables.rb index 593a7a4940..0a06125210 100644 --- a/activesupport/lib/active_support/core_ext/object/instance_variables.rb +++ b/activesupport/lib/active_support/core_ext/object/instance_variables.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Object # Returns a hash with string keys that maps instance variable names without "@" to their # corresponding values. diff --git a/activesupport/lib/active_support/core_ext/object/json.rb b/activesupport/lib/active_support/core_ext/object/json.rb index 1c4d181443..3c8846029f 100644 --- a/activesupport/lib/active_support/core_ext/object/json.rb +++ b/activesupport/lib/active_support/core_ext/object/json.rb @@ -1,16 +1,17 @@ +# frozen_string_literal: true # Hack to load json gem first so we can overwrite its to_json. require "json" require "bigdecimal" require "uri/generic" require "pathname" -require "active_support/core_ext/big_decimal/conversions" # for #to_s -require "active_support/core_ext/hash/except" -require "active_support/core_ext/hash/slice" -require "active_support/core_ext/object/instance_variables" +require_relative "../big_decimal/conversions" # for #to_s +require_relative "../hash/except" +require_relative "../hash/slice" +require_relative "instance_variables" require "time" -require "active_support/core_ext/time/conversions" -require "active_support/core_ext/date_time/conversions" -require "active_support/core_ext/date/conversions" +require_relative "../time/conversions" +require_relative "../date_time/conversions" +require_relative "../date/conversions" # The JSON gem adds a few modules to Ruby core classes containing :to_json definition, overwriting # their default behavior. That said, we need to define the basic to_json method in all of them, diff --git a/activesupport/lib/active_support/core_ext/object/to_param.rb b/activesupport/lib/active_support/core_ext/object/to_param.rb index 5eeaf03163..0b172829db 100644 --- a/activesupport/lib/active_support/core_ext/object/to_param.rb +++ b/activesupport/lib/active_support/core_ext/object/to_param.rb @@ -1 +1,2 @@ -require "active_support/core_ext/object/to_query" +# frozen_string_literal: true +require_relative "to_query" diff --git a/activesupport/lib/active_support/core_ext/object/to_query.rb b/activesupport/lib/active_support/core_ext/object/to_query.rb index a3a3abacbb..f85e0eaa6f 100644 --- a/activesupport/lib/active_support/core_ext/object/to_query.rb +++ b/activesupport/lib/active_support/core_ext/object/to_query.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "cgi" class Object diff --git a/activesupport/lib/active_support/core_ext/object/try.rb b/activesupport/lib/active_support/core_ext/object/try.rb index b2be619b2d..952fba4541 100644 --- a/activesupport/lib/active_support/core_ext/object/try.rb +++ b/activesupport/lib/active_support/core_ext/object/try.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "delegate" module ActiveSupport diff --git a/activesupport/lib/active_support/core_ext/object/with_options.rb b/activesupport/lib/active_support/core_ext/object/with_options.rb index 3a44e08630..22a0034d7d 100644 --- a/activesupport/lib/active_support/core_ext/object/with_options.rb +++ b/activesupport/lib/active_support/core_ext/object/with_options.rb @@ -1,4 +1,5 @@ -require "active_support/option_merger" +# frozen_string_literal: true +require_relative "../../option_merger" class Object # An elegant way to factor duplication out of options passed to a series of diff --git a/activesupport/lib/active_support/core_ext/range.rb b/activesupport/lib/active_support/core_ext/range.rb index 3190e3ff76..db4c63380b 100644 --- a/activesupport/lib/active_support/core_ext/range.rb +++ b/activesupport/lib/active_support/core_ext/range.rb @@ -1,4 +1,5 @@ -require "active_support/core_ext/range/conversions" -require "active_support/core_ext/range/include_range" -require "active_support/core_ext/range/overlaps" -require "active_support/core_ext/range/each" +# frozen_string_literal: true +require_relative "range/conversions" +require_relative "range/include_range" +require_relative "range/overlaps" +require_relative "range/each" diff --git a/activesupport/lib/active_support/core_ext/range/conversions.rb b/activesupport/lib/active_support/core_ext/range/conversions.rb index 69ea046cb6..5038a15cdf 100644 --- a/activesupport/lib/active_support/core_ext/range/conversions.rb +++ b/activesupport/lib/active_support/core_ext/range/conversions.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport::RangeWithFormat RANGE_FORMATS = { db: Proc.new { |start, stop| "BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'" } diff --git a/activesupport/lib/active_support/core_ext/range/each.rb b/activesupport/lib/active_support/core_ext/range/each.rb index dc6dad5ced..aeea8c867b 100644 --- a/activesupport/lib/active_support/core_ext/range/each.rb +++ b/activesupport/lib/active_support/core_ext/range/each.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport module EachTimeWithZone #:nodoc: def each(&block) diff --git a/activesupport/lib/active_support/core_ext/range/include_range.rb b/activesupport/lib/active_support/core_ext/range/include_range.rb index c69e1e3fb9..d307750a23 100644 --- a/activesupport/lib/active_support/core_ext/range/include_range.rb +++ b/activesupport/lib/active_support/core_ext/range/include_range.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport module IncludeWithRange #:nodoc: # Extends the default Range#include? to support range comparisons. diff --git a/activesupport/lib/active_support/core_ext/range/overlaps.rb b/activesupport/lib/active_support/core_ext/range/overlaps.rb index 603657c180..ecdfbd803b 100644 --- a/activesupport/lib/active_support/core_ext/range/overlaps.rb +++ b/activesupport/lib/active_support/core_ext/range/overlaps.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Range # Compare two ranges and see if they overlap each other # (1..5).overlaps?(4..6) # => true diff --git a/activesupport/lib/active_support/core_ext/regexp.rb b/activesupport/lib/active_support/core_ext/regexp.rb index d77d01bf42..23b337ba67 100644 --- a/activesupport/lib/active_support/core_ext/regexp.rb +++ b/activesupport/lib/active_support/core_ext/regexp.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Regexp #:nodoc: def multiline? options & MULTILINE == MULTILINE diff --git a/activesupport/lib/active_support/core_ext/securerandom.rb b/activesupport/lib/active_support/core_ext/securerandom.rb index a57685bea1..033ac356bd 100644 --- a/activesupport/lib/active_support/core_ext/securerandom.rb +++ b/activesupport/lib/active_support/core_ext/securerandom.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "securerandom" module SecureRandom diff --git a/activesupport/lib/active_support/core_ext/string.rb b/activesupport/lib/active_support/core_ext/string.rb index 4cb3200875..cefd82fa20 100644 --- a/activesupport/lib/active_support/core_ext/string.rb +++ b/activesupport/lib/active_support/core_ext/string.rb @@ -1,13 +1,14 @@ -require "active_support/core_ext/string/conversions" -require "active_support/core_ext/string/filters" -require "active_support/core_ext/string/multibyte" -require "active_support/core_ext/string/starts_ends_with" -require "active_support/core_ext/string/inflections" -require "active_support/core_ext/string/access" -require "active_support/core_ext/string/behavior" -require "active_support/core_ext/string/output_safety" -require "active_support/core_ext/string/exclude" -require "active_support/core_ext/string/strip" -require "active_support/core_ext/string/inquiry" -require "active_support/core_ext/string/indent" -require "active_support/core_ext/string/zones" +# frozen_string_literal: true +require_relative "string/conversions" +require_relative "string/filters" +require_relative "string/multibyte" +require_relative "string/starts_ends_with" +require_relative "string/inflections" +require_relative "string/access" +require_relative "string/behavior" +require_relative "string/output_safety" +require_relative "string/exclude" +require_relative "string/strip" +require_relative "string/inquiry" +require_relative "string/indent" +require_relative "string/zones" diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb index 6133826f37..11f4bf8052 100644 --- a/activesupport/lib/active_support/core_ext/string/access.rb +++ b/activesupport/lib/active_support/core_ext/string/access.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class String # If you pass a single integer, returns a substring of one character at that # position. The first character of the string is at position 0, the next at diff --git a/activesupport/lib/active_support/core_ext/string/behavior.rb b/activesupport/lib/active_support/core_ext/string/behavior.rb index 710f1f4670..e63888991d 100644 --- a/activesupport/lib/active_support/core_ext/string/behavior.rb +++ b/activesupport/lib/active_support/core_ext/string/behavior.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class String # Enables more predictable duck-typing on String-like classes. See <tt>Object#acts_like?</tt>. def acts_like_string? diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index 221b4969cc..a0b771f41e 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -1,5 +1,6 @@ +# frozen_string_literal: true require "date" -require "active_support/core_ext/time/calculations" +require_relative "../time/calculations" class String # Converts a string to a Time value. diff --git a/activesupport/lib/active_support/core_ext/string/exclude.rb b/activesupport/lib/active_support/core_ext/string/exclude.rb index 0ac684f6ee..2893a6eeed 100644 --- a/activesupport/lib/active_support/core_ext/string/exclude.rb +++ b/activesupport/lib/active_support/core_ext/string/exclude.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class String # The inverse of <tt>String#include?</tt>. Returns true if the string # does not include the other string. diff --git a/activesupport/lib/active_support/core_ext/string/filters.rb b/activesupport/lib/active_support/core_ext/string/filters.rb index a9ec2eb842..e05cf024f6 100644 --- a/activesupport/lib/active_support/core_ext/string/filters.rb +++ b/activesupport/lib/active_support/core_ext/string/filters.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class String # Returns the string, first removing all whitespace on both ends of # the string, and then changing remaining consecutive whitespace diff --git a/activesupport/lib/active_support/core_ext/string/indent.rb b/activesupport/lib/active_support/core_ext/string/indent.rb index d7b58301d3..a38198a8e6 100644 --- a/activesupport/lib/active_support/core_ext/string/indent.rb +++ b/activesupport/lib/active_support/core_ext/string/indent.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class String # Same as +indent+, except it indents the receiver in-place. # diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb index b27cfe53f4..78caa0832f 100644 --- a/activesupport/lib/active_support/core_ext/string/inflections.rb +++ b/activesupport/lib/active_support/core_ext/string/inflections.rb @@ -1,5 +1,6 @@ -require "active_support/inflector/methods" -require "active_support/inflector/transliterate" +# frozen_string_literal: true +require_relative "../../inflector/methods" +require_relative "../../inflector/transliterate" # String inflections define new methods on the String class to transform names for different purposes. # For instance, you can figure out the name of a table from the name of a class. diff --git a/activesupport/lib/active_support/core_ext/string/inquiry.rb b/activesupport/lib/active_support/core_ext/string/inquiry.rb index c95d83beae..0fe532fb8c 100644 --- a/activesupport/lib/active_support/core_ext/string/inquiry.rb +++ b/activesupport/lib/active_support/core_ext/string/inquiry.rb @@ -1,4 +1,5 @@ -require "active_support/string_inquirer" +# frozen_string_literal: true +require_relative "../../string_inquirer" class String # Wraps the current string in the <tt>ActiveSupport::StringInquirer</tt> class, diff --git a/activesupport/lib/active_support/core_ext/string/multibyte.rb b/activesupport/lib/active_support/core_ext/string/multibyte.rb index 1c73182259..403e4be011 100644 --- a/activesupport/lib/active_support/core_ext/string/multibyte.rb +++ b/activesupport/lib/active_support/core_ext/string/multibyte.rb @@ -1,4 +1,5 @@ -require "active_support/multibyte" +# frozen_string_literal: true +require_relative "../../multibyte" class String # == Multibyte proxy diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index 94ce3f6a61..4bfc582eb5 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require "erb" -require "active_support/core_ext/kernel/singleton_class" -require "active_support/multibyte/unicode" +require_relative "../kernel/singleton_class" +require_relative "../../multibyte/unicode" class ERB module Util diff --git a/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb b/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb index 641acf62d0..f072fbf7d7 100644 --- a/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb +++ b/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class String alias_method :starts_with?, :start_with? alias_method :ends_with?, :end_with? diff --git a/activesupport/lib/active_support/core_ext/string/strip.rb b/activesupport/lib/active_support/core_ext/string/strip.rb index bb62e6c0ba..979b6bd767 100644 --- a/activesupport/lib/active_support/core_ext/string/strip.rb +++ b/activesupport/lib/active_support/core_ext/string/strip.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class String # Strips indentation in heredocs. # diff --git a/activesupport/lib/active_support/core_ext/string/zones.rb b/activesupport/lib/active_support/core_ext/string/zones.rb index de5a28e4f7..a911fdab3c 100644 --- a/activesupport/lib/active_support/core_ext/string/zones.rb +++ b/activesupport/lib/active_support/core_ext/string/zones.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/string/conversions" -require "active_support/core_ext/time/zones" +# frozen_string_literal: true +require_relative "conversions" +require_relative "../time/zones" class String # Converts String to a TimeWithZone in the current zone if Time.zone or Time.zone_default diff --git a/activesupport/lib/active_support/core_ext/time.rb b/activesupport/lib/active_support/core_ext/time.rb index b1ae4a45d9..cfa9b82b06 100644 --- a/activesupport/lib/active_support/core_ext/time.rb +++ b/activesupport/lib/active_support/core_ext/time.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/time/acts_like" -require "active_support/core_ext/time/calculations" -require "active_support/core_ext/time/compatibility" -require "active_support/core_ext/time/conversions" -require "active_support/core_ext/time/zones" +# frozen_string_literal: true +require_relative "time/acts_like" +require_relative "time/calculations" +require_relative "time/compatibility" +require_relative "time/conversions" +require_relative "time/zones" diff --git a/activesupport/lib/active_support/core_ext/time/acts_like.rb b/activesupport/lib/active_support/core_ext/time/acts_like.rb index cf4b2539c5..776456506c 100644 --- a/activesupport/lib/active_support/core_ext/time/acts_like.rb +++ b/activesupport/lib/active_support/core_ext/time/acts_like.rb @@ -1,4 +1,5 @@ -require "active_support/core_ext/object/acts_like" +# frozen_string_literal: true +require_relative "../object/acts_like" class Time # Duck-types as a Time-like class. See Object#acts_like?. diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index d3f23f4663..4cfb702674 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -1,9 +1,10 @@ -require "active_support/duration" -require "active_support/core_ext/time/conversions" -require "active_support/time_with_zone" -require "active_support/core_ext/time/zones" -require "active_support/core_ext/date_and_time/calculations" -require "active_support/core_ext/date/calculations" +# frozen_string_literal: true +require_relative "../../duration" +require_relative "conversions" +require_relative "../../time_with_zone" +require_relative "zones" +require_relative "../date_and_time/calculations" +require_relative "../date/calculations" class Time include DateAndTime::Calculations diff --git a/activesupport/lib/active_support/core_ext/time/compatibility.rb b/activesupport/lib/active_support/core_ext/time/compatibility.rb index 45e86b77ce..ce69e5f478 100644 --- a/activesupport/lib/active_support/core_ext/time/compatibility.rb +++ b/activesupport/lib/active_support/core_ext/time/compatibility.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/date_and_time/compatibility" -require "active_support/core_ext/module/remove_method" +# frozen_string_literal: true +require_relative "../date_and_time/compatibility" +require_relative "../module/remove_method" class Time include DateAndTime::Compatibility diff --git a/activesupport/lib/active_support/core_ext/time/conversions.rb b/activesupport/lib/active_support/core_ext/time/conversions.rb index 595bda6b4f..5cb0f9c980 100644 --- a/activesupport/lib/active_support/core_ext/time/conversions.rb +++ b/activesupport/lib/active_support/core_ext/time/conversions.rb @@ -1,5 +1,6 @@ -require "active_support/inflector/methods" -require "active_support/values/time_zone" +# frozen_string_literal: true +require_relative "../../inflector/methods" +require_relative "../../values/time_zone" class Time DATE_FORMATS = { diff --git a/activesupport/lib/active_support/core_ext/time/zones.rb b/activesupport/lib/active_support/core_ext/time/zones.rb index 87b5ad903a..3794eab3f5 100644 --- a/activesupport/lib/active_support/core_ext/time/zones.rb +++ b/activesupport/lib/active_support/core_ext/time/zones.rb @@ -1,6 +1,7 @@ -require "active_support/time_with_zone" -require "active_support/core_ext/time/acts_like" -require "active_support/core_ext/date_and_time/zones" +# frozen_string_literal: true +require_relative "../../time_with_zone" +require_relative "acts_like" +require_relative "../date_and_time/zones" class Time include DateAndTime::Zones diff --git a/activesupport/lib/active_support/core_ext/uri.rb b/activesupport/lib/active_support/core_ext/uri.rb index 342a5fcd52..f93dbdf2cd 100644 --- a/activesupport/lib/active_support/core_ext/uri.rb +++ b/activesupport/lib/active_support/core_ext/uri.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "uri" str = "\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E" # Ni-ho-nn-go in UTF-8, means Japanese. parser = URI::Parser.new diff --git a/activesupport/lib/active_support/current_attributes.rb b/activesupport/lib/active_support/current_attributes.rb index 872b0663c7..1857700486 100644 --- a/activesupport/lib/active_support/current_attributes.rb +++ b/activesupport/lib/active_support/current_attributes.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport # Abstract super class that provides a thread-isolated attributes singleton, which resets automatically # before and after each request. This allows you to keep all the per-request attributes easily diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 3cd8f3d0ac..a11d4a834b 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -1,18 +1,19 @@ +# frozen_string_literal: true require "set" require "thread" require "concurrent/map" require "pathname" -require "active_support/core_ext/module/aliasing" -require "active_support/core_ext/module/attribute_accessors" -require "active_support/core_ext/module/introspection" -require "active_support/core_ext/module/anonymous" -require "active_support/core_ext/object/blank" -require "active_support/core_ext/kernel/reporting" -require "active_support/core_ext/load_error" -require "active_support/core_ext/name_error" -require "active_support/core_ext/string/starts_ends_with" -require "active_support/dependencies/interlock" -require "active_support/inflector" +require_relative "core_ext/module/aliasing" +require_relative "core_ext/module/attribute_accessors" +require_relative "core_ext/module/introspection" +require_relative "core_ext/module/anonymous" +require_relative "core_ext/object/blank" +require_relative "core_ext/kernel/reporting" +require_relative "core_ext/load_error" +require_relative "core_ext/name_error" +require_relative "core_ext/string/starts_ends_with" +require_relative "dependencies/interlock" +require_relative "inflector" module ActiveSupport #:nodoc: module Dependencies #:nodoc: diff --git a/activesupport/lib/active_support/dependencies/autoload.rb b/activesupport/lib/active_support/dependencies/autoload.rb index 13036d521d..fcf550be3d 100644 --- a/activesupport/lib/active_support/dependencies/autoload.rb +++ b/activesupport/lib/active_support/dependencies/autoload.rb @@ -1,4 +1,5 @@ -require "active_support/inflector/methods" +# frozen_string_literal: true +require_relative "../inflector/methods" module ActiveSupport # Autoload and eager load conveniences for your library. diff --git a/activesupport/lib/active_support/dependencies/interlock.rb b/activesupport/lib/active_support/dependencies/interlock.rb index e4e18439c5..0d80484c00 100644 --- a/activesupport/lib/active_support/dependencies/interlock.rb +++ b/activesupport/lib/active_support/dependencies/interlock.rb @@ -1,4 +1,5 @@ -require "active_support/concurrency/share_lock" +# frozen_string_literal: true +require_relative "../concurrency/share_lock" module ActiveSupport #:nodoc: module Dependencies #:nodoc: diff --git a/activesupport/lib/active_support/deprecation.rb b/activesupport/lib/active_support/deprecation.rb index d1e6502669..3e914de316 100644 --- a/activesupport/lib/active_support/deprecation.rb +++ b/activesupport/lib/active_support/deprecation.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "singleton" module ActiveSupport @@ -12,13 +13,13 @@ module ActiveSupport # a circular require warning for active_support/deprecation.rb. # # So, we define the constant first, and load dependencies later. - require "active_support/deprecation/instance_delegator" - require "active_support/deprecation/behaviors" - require "active_support/deprecation/reporting" - require "active_support/deprecation/constant_accessor" - require "active_support/deprecation/method_wrappers" - require "active_support/deprecation/proxy_wrappers" - require "active_support/core_ext/module/deprecation" + require_relative "deprecation/instance_delegator" + require_relative "deprecation/behaviors" + require_relative "deprecation/reporting" + require_relative "deprecation/constant_accessor" + require_relative "deprecation/method_wrappers" + require_relative "deprecation/proxy_wrappers" + require_relative "core_ext/module/deprecation" include Singleton include InstanceDelegator diff --git a/activesupport/lib/active_support/deprecation/behaviors.rb b/activesupport/lib/active_support/deprecation/behaviors.rb index a9a182f212..5b7f67db53 100644 --- a/activesupport/lib/active_support/deprecation/behaviors.rb +++ b/activesupport/lib/active_support/deprecation/behaviors.rb @@ -1,4 +1,5 @@ -require "active_support/notifications" +# frozen_string_literal: true +require_relative "../notifications" module ActiveSupport # Raised when <tt>ActiveSupport::Deprecation::Behavior#behavior</tt> is set with <tt>:raise</tt>. @@ -25,7 +26,7 @@ module ActiveSupport if defined?(Rails.logger) && Rails.logger Rails.logger else - require "active_support/logger" + require_relative "../logger" ActiveSupport::Logger.new($stderr) end logger.warn message diff --git a/activesupport/lib/active_support/deprecation/constant_accessor.rb b/activesupport/lib/active_support/deprecation/constant_accessor.rb index 2b19de365f..17850a2b39 100644 --- a/activesupport/lib/active_support/deprecation/constant_accessor.rb +++ b/activesupport/lib/active_support/deprecation/constant_accessor.rb @@ -1,4 +1,5 @@ -require "active_support/inflector/methods" +# frozen_string_literal: true +require_relative "../inflector/methods" module ActiveSupport class Deprecation diff --git a/activesupport/lib/active_support/deprecation/instance_delegator.rb b/activesupport/lib/active_support/deprecation/instance_delegator.rb index 6d390f3b37..4a62df4714 100644 --- a/activesupport/lib/active_support/deprecation/instance_delegator.rb +++ b/activesupport/lib/active_support/deprecation/instance_delegator.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/kernel/singleton_class" -require "active_support/core_ext/module/delegation" +# frozen_string_literal: true +require_relative "../core_ext/kernel/singleton_class" +require_relative "../core_ext/module/delegation" module ActiveSupport class Deprecation diff --git a/activesupport/lib/active_support/deprecation/method_wrappers.rb b/activesupport/lib/active_support/deprecation/method_wrappers.rb index 930d71e8d2..94c7960a9d 100644 --- a/activesupport/lib/active_support/deprecation/method_wrappers.rb +++ b/activesupport/lib/active_support/deprecation/method_wrappers.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/module/aliasing" -require "active_support/core_ext/array/extract_options" +# frozen_string_literal: true +require_relative "../core_ext/module/aliasing" +require_relative "../core_ext/array/extract_options" module ActiveSupport class Deprecation diff --git a/activesupport/lib/active_support/deprecation/proxy_wrappers.rb b/activesupport/lib/active_support/deprecation/proxy_wrappers.rb index ce39e9a232..cd3d7dcad4 100644 --- a/activesupport/lib/active_support/deprecation/proxy_wrappers.rb +++ b/activesupport/lib/active_support/deprecation/proxy_wrappers.rb @@ -1,5 +1,6 @@ -require "active_support/inflector/methods" -require "active_support/core_ext/regexp" +# frozen_string_literal: true +require_relative "../inflector/methods" +require_relative "../core_ext/regexp" module ActiveSupport class Deprecation diff --git a/activesupport/lib/active_support/deprecation/reporting.rb b/activesupport/lib/active_support/deprecation/reporting.rb index 140bdccbb3..f190e47b64 100644 --- a/activesupport/lib/active_support/deprecation/reporting.rb +++ b/activesupport/lib/active_support/deprecation/reporting.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "rbconfig" module ActiveSupport diff --git a/activesupport/lib/active_support/descendants_tracker.rb b/activesupport/lib/active_support/descendants_tracker.rb index 27861e01d0..4f759f2f26 100644 --- a/activesupport/lib/active_support/descendants_tracker.rb +++ b/activesupport/lib/active_support/descendants_tracker.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport # This module provides an internal implementation to track descendants # which is faster than iterating through ObjectSpace. diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index 39deb2313f..15d550e3ee 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -1,8 +1,9 @@ -require "active_support/core_ext/array/conversions" -require "active_support/core_ext/module/delegation" -require "active_support/core_ext/object/acts_like" -require "active_support/core_ext/string/filters" -require "active_support/deprecation" +# frozen_string_literal: true +require_relative "core_ext/array/conversions" +require_relative "core_ext/module/delegation" +require_relative "core_ext/object/acts_like" +require_relative "core_ext/string/filters" +require_relative "deprecation" module ActiveSupport # Provides accurate date and time measurements using Date#advance and diff --git a/activesupport/lib/active_support/duration/iso8601_parser.rb b/activesupport/lib/active_support/duration/iso8601_parser.rb index e96cb8e883..10f9e1fd0f 100644 --- a/activesupport/lib/active_support/duration/iso8601_parser.rb +++ b/activesupport/lib/active_support/duration/iso8601_parser.rb @@ -1,5 +1,6 @@ +# frozen_string_literal: true require "strscan" -require "active_support/core_ext/regexp" +require_relative "../core_ext/regexp" module ActiveSupport class Duration diff --git a/activesupport/lib/active_support/duration/iso8601_serializer.rb b/activesupport/lib/active_support/duration/iso8601_serializer.rb index e5d458b3ab..829f935e3a 100644 --- a/activesupport/lib/active_support/duration/iso8601_serializer.rb +++ b/activesupport/lib/active_support/duration/iso8601_serializer.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/object/blank" -require "active_support/core_ext/hash/transform_values" +# frozen_string_literal: true +require_relative "../core_ext/object/blank" +require_relative "../core_ext/hash/transform_values" module ActiveSupport class Duration @@ -15,12 +16,12 @@ module ActiveSupport parts, sign = normalize return "PT0S".freeze if parts.empty? - output = "P" + output = "P".dup 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 = "" + time = "".dup time << "#{parts[:hours]}H" if parts.key?(:hours) time << "#{parts[:minutes]}M" if parts.key?(:minutes) if parts.key?(:seconds) diff --git a/activesupport/lib/active_support/evented_file_update_checker.rb b/activesupport/lib/active_support/evented_file_update_checker.rb index f59f5d17dc..3c456beac6 100644 --- a/activesupport/lib/active_support/evented_file_update_checker.rb +++ b/activesupport/lib/active_support/evented_file_update_checker.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "set" require "pathname" require "concurrent/atomic/atomic_boolean" diff --git a/activesupport/lib/active_support/execution_wrapper.rb b/activesupport/lib/active_support/execution_wrapper.rb index ca88e7876b..189c06b811 100644 --- a/activesupport/lib/active_support/execution_wrapper.rb +++ b/activesupport/lib/active_support/execution_wrapper.rb @@ -1,4 +1,5 @@ -require "active_support/callbacks" +# frozen_string_literal: true +require_relative "callbacks" module ActiveSupport class ExecutionWrapper diff --git a/activesupport/lib/active_support/executor.rb b/activesupport/lib/active_support/executor.rb index a6400cae0a..2fd6325993 100644 --- a/activesupport/lib/active_support/executor.rb +++ b/activesupport/lib/active_support/executor.rb @@ -1,4 +1,5 @@ -require "active_support/execution_wrapper" +# frozen_string_literal: true +require_relative "execution_wrapper" module ActiveSupport class Executor < ExecutionWrapper diff --git a/activesupport/lib/active_support/file_update_checker.rb b/activesupport/lib/active_support/file_update_checker.rb index 2b5e3c1350..0201e86d1e 100644 --- a/activesupport/lib/active_support/file_update_checker.rb +++ b/activesupport/lib/active_support/file_update_checker.rb @@ -1,4 +1,5 @@ -require "active_support/core_ext/time/calculations" +# frozen_string_literal: true +require_relative "core_ext/time/calculations" module ActiveSupport # FileUpdateChecker specifies the API used by Rails to watch files diff --git a/activesupport/lib/active_support/gem_version.rb b/activesupport/lib/active_support/gem_version.rb index 371a39a5e6..d6015b0161 100644 --- a/activesupport/lib/active_support/gem_version.rb +++ b/activesupport/lib/active_support/gem_version.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport # Returns the version of the currently loaded Active Support as a <tt>Gem::Version</tt>. def self.gem_version diff --git a/activesupport/lib/active_support/gzip.rb b/activesupport/lib/active_support/gzip.rb index 95a86889ec..fd9263500c 100644 --- a/activesupport/lib/active_support/gzip.rb +++ b/activesupport/lib/active_support/gzip.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "zlib" require "stringio" diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index 3b185dd86b..6ede4559ba 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/hash/keys" -require "active_support/core_ext/hash/reverse_merge" +# frozen_string_literal: true +require_relative "core_ext/hash/keys" +require_relative "core_ext/hash/reverse_merge" module ActiveSupport # Implements a hash where keys <tt>:foo</tt> and <tt>"foo"</tt> are considered diff --git a/activesupport/lib/active_support/i18n.rb b/activesupport/lib/active_support/i18n.rb index 1a1f1a1257..4548c89cbb 100644 --- a/activesupport/lib/active_support/i18n.rb +++ b/activesupport/lib/active_support/i18n.rb @@ -1,13 +1,14 @@ -require "active_support/core_ext/hash/deep_merge" -require "active_support/core_ext/hash/except" -require "active_support/core_ext/hash/slice" +# frozen_string_literal: true +require_relative "core_ext/hash/deep_merge" +require_relative "core_ext/hash/except" +require_relative "core_ext/hash/slice" begin require "i18n" rescue LoadError => e $stderr.puts "The i18n gem is not available. Please add it to your Gemfile and run bundle install" raise e end -require "active_support/lazy_load_hooks" +require_relative "lazy_load_hooks" ActiveSupport.run_load_hooks(:i18n) I18n.load_path << File.expand_path("locale/en.yml", __dir__) diff --git a/activesupport/lib/active_support/i18n_railtie.rb b/activesupport/lib/active_support/i18n_railtie.rb index 51fe6f3418..6a249e3906 100644 --- a/activesupport/lib/active_support/i18n_railtie.rb +++ b/activesupport/lib/active_support/i18n_railtie.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require "active_support" -require "active_support/file_update_checker" -require "active_support/core_ext/array/wrap" +require_relative "file_update_checker" +require_relative "core_ext/array/wrap" # :enddoc: diff --git a/activesupport/lib/active_support/inflections.rb b/activesupport/lib/active_support/inflections.rb index afa7d1f325..339931b865 100644 --- a/activesupport/lib/active_support/inflections.rb +++ b/activesupport/lib/active_support/inflections.rb @@ -1,4 +1,5 @@ -require "active_support/inflector/inflections" +# frozen_string_literal: true +require_relative "inflector/inflections" #-- # Defines the standard inflection rules. These are the starting point for diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb index 48631b16a8..abfce1c17c 100644 --- a/activesupport/lib/active_support/inflector.rb +++ b/activesupport/lib/active_support/inflector.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true # in case active_support/inflector is required without the rest of active_support -require "active_support/inflector/inflections" -require "active_support/inflector/transliterate" -require "active_support/inflector/methods" +require_relative "inflector/inflections" +require_relative "inflector/transliterate" +require_relative "inflector/methods" -require "active_support/inflections" -require "active_support/core_ext/string/inflections" +require_relative "inflections" +require_relative "core_ext/string/inflections" diff --git a/activesupport/lib/active_support/inflector/inflections.rb b/activesupport/lib/active_support/inflector/inflections.rb index c47a2e34e1..b8f7cc4c6d 100644 --- a/activesupport/lib/active_support/inflector/inflections.rb +++ b/activesupport/lib/active_support/inflector/inflections.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true require "concurrent/map" -require "active_support/core_ext/array/prepend_and_append" -require "active_support/core_ext/regexp" -require "active_support/i18n" +require_relative "../core_ext/array/prepend_and_append" +require_relative "../core_ext/regexp" +require_relative "../i18n" module ActiveSupport module Inflector diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index ff1a0cb8c7..0e6fd145a2 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -1,5 +1,6 @@ -require "active_support/inflections" -require "active_support/core_ext/regexp" +# frozen_string_literal: true +require_relative "../inflections" +require_relative "../core_ext/regexp" module ActiveSupport # The Inflector transforms words from singular to plural, class names to table diff --git a/activesupport/lib/active_support/inflector/transliterate.rb b/activesupport/lib/active_support/inflector/transliterate.rb index de6dd2720b..6267142628 100644 --- a/activesupport/lib/active_support/inflector/transliterate.rb +++ b/activesupport/lib/active_support/inflector/transliterate.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/string/multibyte" -require "active_support/i18n" +# frozen_string_literal: true +require_relative "../core_ext/string/multibyte" +require_relative "../i18n" module ActiveSupport module Inflector diff --git a/activesupport/lib/active_support/json.rb b/activesupport/lib/active_support/json.rb index da938d1555..043750e05c 100644 --- a/activesupport/lib/active_support/json.rb +++ b/activesupport/lib/active_support/json.rb @@ -1,2 +1,3 @@ -require "active_support/json/decoding" -require "active_support/json/encoding" +# frozen_string_literal: true +require_relative "json/decoding" +require_relative "json/encoding" diff --git a/activesupport/lib/active_support/json/decoding.rb b/activesupport/lib/active_support/json/decoding.rb index f487fa0c65..515a11edf1 100644 --- a/activesupport/lib/active_support/json/decoding.rb +++ b/activesupport/lib/active_support/json/decoding.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/module/attribute_accessors" -require "active_support/core_ext/module/delegation" +# frozen_string_literal: true +require_relative "../core_ext/module/attribute_accessors" +require_relative "../core_ext/module/delegation" require "json" module ActiveSupport diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index defaf3f395..153f1fdbd2 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/object/json" -require "active_support/core_ext/module/delegation" +# frozen_string_literal: true +require_relative "../core_ext/object/json" +require_relative "../core_ext/module/delegation" module ActiveSupport class << self diff --git a/activesupport/lib/active_support/key_generator.rb b/activesupport/lib/active_support/key_generator.rb index 23ab804eb1..a0b2a70ee3 100644 --- a/activesupport/lib/active_support/key_generator.rb +++ b/activesupport/lib/active_support/key_generator.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "concurrent/map" require "openssl" diff --git a/activesupport/lib/active_support/lazy_load_hooks.rb b/activesupport/lib/active_support/lazy_load_hooks.rb index 720ed47331..b1fc6b331b 100644 --- a/activesupport/lib/active_support/lazy_load_hooks.rb +++ b/activesupport/lib/active_support/lazy_load_hooks.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport # lazy_load_hooks allows Rails to lazily load a lot of components and thus # making the app boot faster. Because of this feature now there is no need to diff --git a/activesupport/lib/active_support/log_subscriber.rb b/activesupport/lib/active_support/log_subscriber.rb index a05758d6aa..a5b502a30e 100644 --- a/activesupport/lib/active_support/log_subscriber.rb +++ b/activesupport/lib/active_support/log_subscriber.rb @@ -1,6 +1,7 @@ -require "active_support/core_ext/module/attribute_accessors" -require "active_support/core_ext/class/attribute" -require "active_support/subscriber" +# frozen_string_literal: true +require_relative "core_ext/module/attribute_accessors" +require_relative "core_ext/class/attribute" +require_relative "subscriber" module ActiveSupport # ActiveSupport::LogSubscriber is an object set to consume diff --git a/activesupport/lib/active_support/log_subscriber/test_helper.rb b/activesupport/lib/active_support/log_subscriber/test_helper.rb index 953ee77c2a..7f25d6b0b3 100644 --- a/activesupport/lib/active_support/log_subscriber/test_helper.rb +++ b/activesupport/lib/active_support/log_subscriber/test_helper.rb @@ -1,6 +1,7 @@ -require "active_support/log_subscriber" -require "active_support/logger" -require "active_support/notifications" +# frozen_string_literal: true +require_relative "../log_subscriber" +require_relative "../logger" +require_relative "../notifications" module ActiveSupport class LogSubscriber diff --git a/activesupport/lib/active_support/logger.rb b/activesupport/lib/active_support/logger.rb index ea09d7d2df..2bbff5892d 100644 --- a/activesupport/lib/active_support/logger.rb +++ b/activesupport/lib/active_support/logger.rb @@ -1,5 +1,6 @@ -require "active_support/logger_silence" -require "active_support/logger_thread_safe_level" +# frozen_string_literal: true +require_relative "logger_silence" +require_relative "logger_thread_safe_level" require "logger" module ActiveSupport diff --git a/activesupport/lib/active_support/logger_silence.rb b/activesupport/lib/active_support/logger_silence.rb index 9c64afaaca..5c8d4dba5e 100644 --- a/activesupport/lib/active_support/logger_silence.rb +++ b/activesupport/lib/active_support/logger_silence.rb @@ -1,5 +1,6 @@ -require "active_support/concern" -require "active_support/core_ext/module/attribute_accessors" +# frozen_string_literal: true +require_relative "concern" +require_relative "core_ext/module/attribute_accessors" require "concurrent" module LoggerSilence diff --git a/activesupport/lib/active_support/logger_thread_safe_level.rb b/activesupport/lib/active_support/logger_thread_safe_level.rb index 7fb175dea6..4b5f2e7fb3 100644 --- a/activesupport/lib/active_support/logger_thread_safe_level.rb +++ b/activesupport/lib/active_support/logger_thread_safe_level.rb @@ -1,4 +1,5 @@ -require "active_support/concern" +# frozen_string_literal: true +require_relative "concern" module ActiveSupport module LoggerThreadSafeLevel # :nodoc: diff --git a/activesupport/lib/active_support/message_encryptor.rb b/activesupport/lib/active_support/message_encryptor.rb index a1e1dc9a8c..03e7d5b436 100644 --- a/activesupport/lib/active_support/message_encryptor.rb +++ b/activesupport/lib/active_support/message_encryptor.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true require "openssl" require "base64" -require "active_support/core_ext/array/extract_options" -require "active_support/message_verifier" +require_relative "core_ext/array/extract_options" +require_relative "message_verifier" module ActiveSupport # MessageEncryptor is a simple way to encrypt values which get stored @@ -115,7 +116,7 @@ module ActiveSupport encrypted_data << cipher.final blob = "#{::Base64.strict_encode64 encrypted_data}--#{::Base64.strict_encode64 iv}" - blob << "--#{::Base64.strict_encode64 cipher.auth_tag}" if aead_mode? + blob = "#{blob}--#{::Base64.strict_encode64 cipher.auth_tag}" if aead_mode? blob end diff --git a/activesupport/lib/active_support/message_verifier.rb b/activesupport/lib/active_support/message_verifier.rb index 8419e858c6..2eb09e41e0 100644 --- a/activesupport/lib/active_support/message_verifier.rb +++ b/activesupport/lib/active_support/message_verifier.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require "base64" -require "active_support/core_ext/object/blank" -require "active_support/security_utils" +require_relative "core_ext/object/blank" +require_relative "security_utils" module ActiveSupport # +MessageVerifier+ makes it easy to generate and verify messages which are diff --git a/activesupport/lib/active_support/multibyte.rb b/activesupport/lib/active_support/multibyte.rb index f7c7befee0..0a3418ae95 100644 --- a/activesupport/lib/active_support/multibyte.rb +++ b/activesupport/lib/active_support/multibyte.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport #:nodoc: module Multibyte autoload :Chars, "active_support/multibyte/chars" diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb index 8c58466556..7bd1200fa6 100644 --- a/activesupport/lib/active_support/multibyte/chars.rb +++ b/activesupport/lib/active_support/multibyte/chars.rb @@ -1,8 +1,9 @@ -require "active_support/json" -require "active_support/core_ext/string/access" -require "active_support/core_ext/string/behavior" -require "active_support/core_ext/module/delegation" -require "active_support/core_ext/regexp" +# frozen_string_literal: true +require_relative "../json" +require_relative "../core_ext/string/access" +require_relative "../core_ext/string/behavior" +require_relative "../core_ext/module/delegation" +require_relative "../core_ext/regexp" module ActiveSupport #:nodoc: module Multibyte #:nodoc: diff --git a/activesupport/lib/active_support/multibyte/unicode.rb b/activesupport/lib/active_support/multibyte/unicode.rb index 8223e45e5a..92575b1c9b 100644 --- a/activesupport/lib/active_support/multibyte/unicode.rb +++ b/activesupport/lib/active_support/multibyte/unicode.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport module Multibyte module Unicode diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index 37dfdc0422..88ba85d8c7 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -1,6 +1,7 @@ -require "active_support/notifications/instrumenter" -require "active_support/notifications/fanout" -require "active_support/per_thread_registry" +# frozen_string_literal: true +require_relative "notifications/instrumenter" +require_relative "notifications/fanout" +require_relative "per_thread_registry" module ActiveSupport # = Notifications diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 9da115f552..b69d1bcd25 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "mutex_m" require "concurrent/map" diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index e11e2e0689..00936f5b9e 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "securerandom" module ActiveSupport diff --git a/activesupport/lib/active_support/number_helper.rb b/activesupport/lib/active_support/number_helper.rb index 9cb2821cb6..965664eb65 100644 --- a/activesupport/lib/active_support/number_helper.rb +++ b/activesupport/lib/active_support/number_helper.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport module NumberHelper extend ActiveSupport::Autoload diff --git a/activesupport/lib/active_support/number_helper/number_converter.rb b/activesupport/lib/active_support/number_helper/number_converter.rb index ce363287cf..d2be18ce27 100644 --- a/activesupport/lib/active_support/number_helper/number_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_converter.rb @@ -1,8 +1,9 @@ -require "active_support/core_ext/big_decimal/conversions" -require "active_support/core_ext/object/blank" -require "active_support/core_ext/hash/keys" -require "active_support/i18n" -require "active_support/core_ext/class/attribute" +# frozen_string_literal: true +require_relative "../core_ext/big_decimal/conversions" +require_relative "../core_ext/object/blank" +require_relative "../core_ext/hash/keys" +require_relative "../i18n" +require_relative "../core_ext/class/attribute" module ActiveSupport module NumberHelper diff --git a/activesupport/lib/active_support/number_helper/number_to_currency_converter.rb b/activesupport/lib/active_support/number_helper/number_to_currency_converter.rb index 0f9dce722f..c260b5b126 100644 --- a/activesupport/lib/active_support/number_helper/number_to_currency_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_currency_converter.rb @@ -1,4 +1,5 @@ -require "active_support/core_ext/numeric/inquiry" +# frozen_string_literal: true +require_relative "../core_ext/numeric/inquiry" module ActiveSupport module NumberHelper diff --git a/activesupport/lib/active_support/number_helper/number_to_delimited_converter.rb b/activesupport/lib/active_support/number_helper/number_to_delimited_converter.rb index e3b35531b1..620e6b4282 100644 --- a/activesupport/lib/active_support/number_helper/number_to_delimited_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_delimited_converter.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport module NumberHelper class NumberToDelimitedConverter < NumberConverter #:nodoc: diff --git a/activesupport/lib/active_support/number_helper/number_to_human_converter.rb b/activesupport/lib/active_support/number_helper/number_to_human_converter.rb index 040343b5dd..852a76fbb6 100644 --- a/activesupport/lib/active_support/number_helper/number_to_human_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_human_converter.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport module NumberHelper class NumberToHumanConverter < NumberConverter # :nodoc: diff --git a/activesupport/lib/active_support/number_helper/number_to_human_size_converter.rb b/activesupport/lib/active_support/number_helper/number_to_human_size_converter.rb index f263dbe9f8..a1ebb92fe7 100644 --- a/activesupport/lib/active_support/number_helper/number_to_human_size_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_human_size_converter.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport module NumberHelper class NumberToHumanSizeConverter < NumberConverter #:nodoc: diff --git a/activesupport/lib/active_support/number_helper/number_to_percentage_converter.rb b/activesupport/lib/active_support/number_helper/number_to_percentage_converter.rb index ac647ca9b7..9285d7d93f 100644 --- a/activesupport/lib/active_support/number_helper/number_to_percentage_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_percentage_converter.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport module NumberHelper class NumberToPercentageConverter < NumberConverter # :nodoc: diff --git a/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb b/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb index 1de9f50f34..e1f2fec55b 100644 --- a/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true module ActiveSupport module NumberHelper class NumberToPhoneConverter < NumberConverter #:nodoc: def convert - str = country_code(opts[:country_code]) + str = country_code(opts[:country_code]).dup str << convert_to_phone_number(number.to_s.strip) str << phone_ext(opts[:extension]) end diff --git a/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb b/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb index c32d85a45f..6e8b5ee653 100644 --- a/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport module NumberHelper class NumberToRoundedConverter < NumberConverter # :nodoc: diff --git a/activesupport/lib/active_support/number_helper/rounding_helper.rb b/activesupport/lib/active_support/number_helper/rounding_helper.rb index 63b48444a6..f5d5f4664b 100644 --- a/activesupport/lib/active_support/number_helper/rounding_helper.rb +++ b/activesupport/lib/active_support/number_helper/rounding_helper.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport module NumberHelper class RoundingHelper # :nodoc: diff --git a/activesupport/lib/active_support/option_merger.rb b/activesupport/lib/active_support/option_merger.rb index 0f2caa98f2..5788332349 100644 --- a/activesupport/lib/active_support/option_merger.rb +++ b/activesupport/lib/active_support/option_merger.rb @@ -1,4 +1,5 @@ -require "active_support/core_ext/hash/deep_merge" +# frozen_string_literal: true +require_relative "core_ext/hash/deep_merge" module ActiveSupport class OptionMerger #:nodoc: diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb index 3aa0a14f04..b07b89447e 100644 --- a/activesupport/lib/active_support/ordered_hash.rb +++ b/activesupport/lib/active_support/ordered_hash.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "yaml" YAML.add_builtin_type("omap") do |type, val| diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb index 04d6dfaf9c..457418a79a 100644 --- a/activesupport/lib/active_support/ordered_options.rb +++ b/activesupport/lib/active_support/ordered_options.rb @@ -1,4 +1,5 @@ -require "active_support/core_ext/object/blank" +# frozen_string_literal: true +require_relative "core_ext/object/blank" module ActiveSupport # Usually key value pairs are handled something like this: diff --git a/activesupport/lib/active_support/per_thread_registry.rb b/activesupport/lib/active_support/per_thread_registry.rb index 02431704d3..662c88d17d 100644 --- a/activesupport/lib/active_support/per_thread_registry.rb +++ b/activesupport/lib/active_support/per_thread_registry.rb @@ -1,4 +1,5 @@ -require "active_support/core_ext/module/delegation" +# frozen_string_literal: true +require_relative "core_ext/module/delegation" module ActiveSupport # NOTE: This approach has been deprecated for end-user code in favor of {thread_mattr_accessor}[rdoc-ref:Module#thread_mattr_accessor] and friends. diff --git a/activesupport/lib/active_support/proxy_object.rb b/activesupport/lib/active_support/proxy_object.rb index 20a0fd8e62..df84ab6225 100644 --- a/activesupport/lib/active_support/proxy_object.rb +++ b/activesupport/lib/active_support/proxy_object.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport # A class with no predefined methods that behaves similarly to Builder's # BlankSlate. Used for proxy classes. diff --git a/activesupport/lib/active_support/rails.rb b/activesupport/lib/active_support/rails.rb index f6b018f0d3..c4fae94d5e 100644 --- a/activesupport/lib/active_support/rails.rb +++ b/activesupport/lib/active_support/rails.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # This is private interface. # # Rails components cherry pick from Active Support as needed, but there are a @@ -9,25 +10,25 @@ # Rails and can change anytime. # Defines Object#blank? and Object#present?. -require "active_support/core_ext/object/blank" +require_relative "core_ext/object/blank" # Rails own autoload, eager_load, etc. -require "active_support/dependencies/autoload" +require_relative "dependencies/autoload" # Support for ClassMethods and the included macro. -require "active_support/concern" +require_relative "concern" # Defines Class#class_attribute. -require "active_support/core_ext/class/attribute" +require_relative "core_ext/class/attribute" # Defines Module#delegate. -require "active_support/core_ext/module/delegation" +require_relative "core_ext/module/delegation" # Defines ActiveSupport::Deprecation. -require "active_support/deprecation" +require_relative "deprecation" # Defines Regexp#match?. # # This should be removed when Rails needs Ruby 2.4 or later, and the require # added where other Regexp extensions are being used (easy to grep). -require "active_support/core_ext/regexp" +require_relative "core_ext/regexp" diff --git a/activesupport/lib/active_support/railtie.rb b/activesupport/lib/active_support/railtie.rb index 45bc51311b..7903d229c0 100644 --- a/activesupport/lib/active_support/railtie.rb +++ b/activesupport/lib/active_support/railtie.rb @@ -1,5 +1,6 @@ +# frozen_string_literal: true require "active_support" -require "active_support/i18n_railtie" +require_relative "i18n_railtie" module ActiveSupport class Railtie < Rails::Railtie # :nodoc: @@ -34,14 +35,14 @@ module ActiveSupport rescue TZInfo::DataSourceNotFound => e raise e.exception "tzinfo-data is not present. Please add gem 'tzinfo-data' to your Gemfile and run bundle install" end - require "active_support/core_ext/time/zones" + require_relative "core_ext/time/zones" Time.zone_default = Time.find_zone!(app.config.time_zone) end # Sets the default week start # If assigned value is not a valid day symbol (e.g. :sunday, :monday, ...), an exception will be raised. initializer "active_support.initialize_beginning_of_week" do |app| - require "active_support/core_ext/date/calculations" + require_relative "core_ext/date/calculations" beginning_of_week_default = Date.find_beginning_of_week!(app.config.beginning_of_week) Date.beginning_of_week_default = beginning_of_week_default diff --git a/activesupport/lib/active_support/reloader.rb b/activesupport/lib/active_support/reloader.rb index 9558146201..6e81c95961 100644 --- a/activesupport/lib/active_support/reloader.rb +++ b/activesupport/lib/active_support/reloader.rb @@ -1,4 +1,5 @@ -require "active_support/execution_wrapper" +# frozen_string_literal: true +require_relative "execution_wrapper" module ActiveSupport #-- diff --git a/activesupport/lib/active_support/rescuable.rb b/activesupport/lib/active_support/rescuable.rb index 826832ba7d..db736f5c23 100644 --- a/activesupport/lib/active_support/rescuable.rb +++ b/activesupport/lib/active_support/rescuable.rb @@ -1,6 +1,7 @@ -require "active_support/concern" -require "active_support/core_ext/class/attribute" -require "active_support/core_ext/string/inflections" +# frozen_string_literal: true +require_relative "concern" +require_relative "core_ext/class/attribute" +require_relative "core_ext/string/inflections" module ActiveSupport # Rescuable module adds support for easier exception handling. diff --git a/activesupport/lib/active_support/security_utils.rb b/activesupport/lib/active_support/security_utils.rb index b655d64449..2e61a72213 100644 --- a/activesupport/lib/active_support/security_utils.rb +++ b/activesupport/lib/active_support/security_utils.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "digest" module ActiveSupport diff --git a/activesupport/lib/active_support/string_inquirer.rb b/activesupport/lib/active_support/string_inquirer.rb index 90eac89c9e..03bcbb2555 100644 --- a/activesupport/lib/active_support/string_inquirer.rb +++ b/activesupport/lib/active_support/string_inquirer.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport # Wrapping a string in this class gives you a prettier way to test # for equality. The value returned by <tt>Rails.env</tt> is wrapped diff --git a/activesupport/lib/active_support/subscriber.rb b/activesupport/lib/active_support/subscriber.rb index 2924139755..23268e990a 100644 --- a/activesupport/lib/active_support/subscriber.rb +++ b/activesupport/lib/active_support/subscriber.rb @@ -1,5 +1,6 @@ -require "active_support/per_thread_registry" -require "active_support/notifications" +# frozen_string_literal: true +require_relative "per_thread_registry" +require_relative "notifications" module ActiveSupport # ActiveSupport::Subscriber is an object set to consume diff --git a/activesupport/lib/active_support/tagged_logging.rb b/activesupport/lib/active_support/tagged_logging.rb index ad134c49b6..7c06c0579f 100644 --- a/activesupport/lib/active_support/tagged_logging.rb +++ b/activesupport/lib/active_support/tagged_logging.rb @@ -1,7 +1,8 @@ -require "active_support/core_ext/module/delegation" -require "active_support/core_ext/object/blank" +# frozen_string_literal: true +require_relative "core_ext/module/delegation" +require_relative "core_ext/object/blank" require "logger" -require "active_support/logger" +require_relative "logger" module ActiveSupport # Wraps any standard Logger object to provide tagging capabilities. diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index 3de4ccc1da..df2d3002c9 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -1,15 +1,16 @@ +# frozen_string_literal: true gem "minitest" # make sure we get the gem, not stdlib require "minitest" -require "active_support/testing/tagged_logging" -require "active_support/testing/setup_and_teardown" -require "active_support/testing/assertions" -require "active_support/testing/deprecation" -require "active_support/testing/declarative" -require "active_support/testing/isolation" -require "active_support/testing/constant_lookup" -require "active_support/testing/time_helpers" -require "active_support/testing/file_fixtures" -require "active_support/core_ext/kernel/reporting" +require_relative "testing/tagged_logging" +require_relative "testing/setup_and_teardown" +require_relative "testing/assertions" +require_relative "testing/deprecation" +require_relative "testing/declarative" +require_relative "testing/isolation" +require_relative "testing/constant_lookup" +require_relative "testing/time_helpers" +require_relative "testing/file_fixtures" +require_relative "core_ext/kernel/reporting" module ActiveSupport class TestCase < ::Minitest::Test diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb index 28e1df8870..d7bb5e5bdf 100644 --- a/activesupport/lib/active_support/testing/assertions.rb +++ b/activesupport/lib/active_support/testing/assertions.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport module Testing module Assertions diff --git a/activesupport/lib/active_support/testing/autorun.rb b/activesupport/lib/active_support/testing/autorun.rb index a18788f38e..40ae696a34 100644 --- a/activesupport/lib/active_support/testing/autorun.rb +++ b/activesupport/lib/active_support/testing/autorun.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true gem "minitest" require "minitest" diff --git a/activesupport/lib/active_support/testing/constant_lookup.rb b/activesupport/lib/active_support/testing/constant_lookup.rb index 647395d2b3..a231697979 100644 --- a/activesupport/lib/active_support/testing/constant_lookup.rb +++ b/activesupport/lib/active_support/testing/constant_lookup.rb @@ -1,5 +1,6 @@ -require "active_support/concern" -require "active_support/inflector" +# frozen_string_literal: true +require_relative "../concern" +require_relative "../inflector" module ActiveSupport module Testing diff --git a/activesupport/lib/active_support/testing/declarative.rb b/activesupport/lib/active_support/testing/declarative.rb index 53ab3ebf78..601f6fb16d 100644 --- a/activesupport/lib/active_support/testing/declarative.rb +++ b/activesupport/lib/active_support/testing/declarative.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport module Testing module Declarative diff --git a/activesupport/lib/active_support/testing/deprecation.rb b/activesupport/lib/active_support/testing/deprecation.rb index 58911570e8..1145afceff 100644 --- a/activesupport/lib/active_support/testing/deprecation.rb +++ b/activesupport/lib/active_support/testing/deprecation.rb @@ -1,5 +1,6 @@ -require "active_support/deprecation" -require "active_support/core_ext/regexp" +# frozen_string_literal: true +require_relative "../deprecation" +require_relative "../core_ext/regexp" module ActiveSupport module Testing diff --git a/activesupport/lib/active_support/testing/file_fixtures.rb b/activesupport/lib/active_support/testing/file_fixtures.rb index affb84cda5..56f80fb547 100644 --- a/activesupport/lib/active_support/testing/file_fixtures.rb +++ b/activesupport/lib/active_support/testing/file_fixtures.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport module Testing # Adds simple access to sample files called file fixtures. diff --git a/activesupport/lib/active_support/testing/isolation.rb b/activesupport/lib/active_support/testing/isolation.rb index 54c3263efa..4d43c06085 100644 --- a/activesupport/lib/active_support/testing/isolation.rb +++ b/activesupport/lib/active_support/testing/isolation.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport module Testing module Isolation diff --git a/activesupport/lib/active_support/testing/method_call_assertions.rb b/activesupport/lib/active_support/testing/method_call_assertions.rb index 6b07416fdc..d33224e9c3 100644 --- a/activesupport/lib/active_support/testing/method_call_assertions.rb +++ b/activesupport/lib/active_support/testing/method_call_assertions.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "minitest/mock" module ActiveSupport diff --git a/activesupport/lib/active_support/testing/setup_and_teardown.rb b/activesupport/lib/active_support/testing/setup_and_teardown.rb index 358c79c321..e80b8d17ef 100644 --- a/activesupport/lib/active_support/testing/setup_and_teardown.rb +++ b/activesupport/lib/active_support/testing/setup_and_teardown.rb @@ -1,5 +1,6 @@ -require "active_support/concern" -require "active_support/callbacks" +# frozen_string_literal: true +require_relative "../concern" +require_relative "../callbacks" module ActiveSupport module Testing diff --git a/activesupport/lib/active_support/testing/stream.rb b/activesupport/lib/active_support/testing/stream.rb index 1d06b94559..4e8303f058 100644 --- a/activesupport/lib/active_support/testing/stream.rb +++ b/activesupport/lib/active_support/testing/stream.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport module Testing module Stream #:nodoc: diff --git a/activesupport/lib/active_support/testing/tagged_logging.rb b/activesupport/lib/active_support/testing/tagged_logging.rb index afdff87b45..3ca45b4ab5 100644 --- a/activesupport/lib/active_support/testing/tagged_logging.rb +++ b/activesupport/lib/active_support/testing/tagged_logging.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport module Testing # Logs a "PostsControllerTest: test name" heading before each test to diff --git a/activesupport/lib/active_support/testing/time_helpers.rb b/activesupport/lib/active_support/testing/time_helpers.rb index 3d9ff99729..eaccbb97eb 100644 --- a/activesupport/lib/active_support/testing/time_helpers.rb +++ b/activesupport/lib/active_support/testing/time_helpers.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/string/strip" # for strip_heredoc -require "active_support/core_ext/time/calculations" +# frozen_string_literal: true +require_relative "../core_ext/string/strip" # for strip_heredoc +require_relative "../core_ext/time/calculations" require "concurrent/map" module ActiveSupport diff --git a/activesupport/lib/active_support/time.rb b/activesupport/lib/active_support/time.rb index 7658228ca6..6004119717 100644 --- a/activesupport/lib/active_support/time.rb +++ b/activesupport/lib/active_support/time.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveSupport autoload :Duration, "active_support/duration" autoload :TimeWithZone, "active_support/time_with_zone" @@ -7,12 +8,12 @@ end require "date" require "time" -require "active_support/core_ext/time" -require "active_support/core_ext/date" -require "active_support/core_ext/date_time" +require_relative "core_ext/time" +require_relative "core_ext/date" +require_relative "core_ext/date_time" -require "active_support/core_ext/integer/time" -require "active_support/core_ext/numeric/time" +require_relative "core_ext/integer/time" +require_relative "core_ext/numeric/time" -require "active_support/core_ext/string/conversions" -require "active_support/core_ext/string/zones" +require_relative "core_ext/string/conversions" +require_relative "core_ext/string/zones" diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index ecb9fb6785..444a714d53 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -1,7 +1,8 @@ -require "active_support/duration" -require "active_support/values/time_zone" -require "active_support/core_ext/object/acts_like" -require "active_support/core_ext/date_and_time/compatibility" +# frozen_string_literal: true +require_relative "duration" +require_relative "values/time_zone" +require_relative "core_ext/object/acts_like" +require_relative "core_ext/date_and_time/compatibility" module ActiveSupport # A Time-like class that can represent a time in any time zone. Necessary diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 96a541a4ef..632f70f93c 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require "tzinfo" require "concurrent/map" -require "active_support/core_ext/object/blank" +require_relative "../core_ext/object/blank" module ActiveSupport # The TimeZone class serves as a wrapper around TZInfo::Timezone instances. @@ -359,7 +360,7 @@ module ActiveSupport # Time.zone.iso8601('1999-12-31') # => Fri, 31 Dec 1999 00:00:00 HST -10:00 # # If the string is invalid then an +ArgumentError+ will be raised unlike +parse+ - # which returns +nil+ when given an invalid date string. + # which usually returns +nil+ when given an invalid date string. def iso8601(str) parts = Date._iso8601(str) @@ -398,6 +399,8 @@ module ActiveSupport # components are supplied, then the day of the month defaults to 1: # # Time.zone.parse('Mar 2000') # => Wed, 01 Mar 2000 00:00:00 HST -10:00 + # + # If the string is invalid then an +ArgumentError+ could be raised. def parse(str, now = now()) parts_to_time(Date._parse(str, false), now) end diff --git a/activesupport/lib/active_support/version.rb b/activesupport/lib/active_support/version.rb index 20b91ac911..e2afb871e7 100644 --- a/activesupport/lib/active_support/version.rb +++ b/activesupport/lib/active_support/version.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require_relative "gem_version" module ActiveSupport diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb index 782fb41288..7163dee68a 100644 --- a/activesupport/lib/active_support/xml_mini.rb +++ b/activesupport/lib/active_support/xml_mini.rb @@ -1,9 +1,10 @@ +# frozen_string_literal: true require "time" require "base64" require "bigdecimal" -require "active_support/core_ext/module/delegation" -require "active_support/core_ext/string/inflections" -require "active_support/core_ext/date_time/calculations" +require_relative "core_ext/module/delegation" +require_relative "core_ext/string/inflections" +require_relative "core_ext/date_time/calculations" module ActiveSupport # = XmlMini @@ -197,7 +198,7 @@ module ActiveSupport if name.is_a?(Module) name else - require "active_support/xml_mini/#{name.downcase}" + require_relative "xml_mini/#{name.downcase}" ActiveSupport.const_get("XmlMini_#{name}") end end diff --git a/activesupport/lib/active_support/xml_mini/jdom.rb b/activesupport/lib/active_support/xml_mini/jdom.rb index a7939b3185..8529c5f73b 100644 --- a/activesupport/lib/active_support/xml_mini/jdom.rb +++ b/activesupport/lib/active_support/xml_mini/jdom.rb @@ -1,9 +1,10 @@ +# frozen_string_literal: true raise "JRuby is required to use the JDOM backend for XmlMini" unless RUBY_PLATFORM.include?("java") require "jruby" include Java -require "active_support/core_ext/object/blank" +require_relative "../core_ext/object/blank" java_import javax.xml.parsers.DocumentBuilder unless defined? DocumentBuilder java_import javax.xml.parsers.DocumentBuilderFactory unless defined? DocumentBuilderFactory diff --git a/activesupport/lib/active_support/xml_mini/libxml.rb b/activesupport/lib/active_support/xml_mini/libxml.rb index d849cdfa6b..2524d6aee2 100644 --- a/activesupport/lib/active_support/xml_mini/libxml.rb +++ b/activesupport/lib/active_support/xml_mini/libxml.rb @@ -1,5 +1,6 @@ +# frozen_string_literal: true require "libxml" -require "active_support/core_ext/object/blank" +require_relative "../core_ext/object/blank" require "stringio" module ActiveSupport @@ -53,7 +54,7 @@ module LibXML #:nodoc: if c.element? c.to_hash(node_hash) elsif c.text? || c.cdata? - node_hash[CONTENT_ROOT] ||= "" + node_hash[CONTENT_ROOT] ||= "".dup node_hash[CONTENT_ROOT] << c.content end end diff --git a/activesupport/lib/active_support/xml_mini/libxmlsax.rb b/activesupport/lib/active_support/xml_mini/libxmlsax.rb index f3d485da2f..8ea4e9b292 100644 --- a/activesupport/lib/active_support/xml_mini/libxmlsax.rb +++ b/activesupport/lib/active_support/xml_mini/libxmlsax.rb @@ -1,5 +1,6 @@ +# frozen_string_literal: true require "libxml" -require "active_support/core_ext/object/blank" +require_relative "../core_ext/object/blank" require "stringio" module ActiveSupport @@ -21,7 +22,7 @@ module ActiveSupport end def on_start_document - @hash = { CONTENT_KEY => "" } + @hash = { CONTENT_KEY => "".dup } @hash_stack = [@hash] end @@ -31,7 +32,7 @@ module ActiveSupport end def on_start_element(name, attrs = {}) - new_hash = { CONTENT_KEY => "" }.merge!(attrs) + new_hash = { CONTENT_KEY => "".dup }.merge!(attrs) new_hash[HASH_SIZE_KEY] = new_hash.size + 1 case current_hash[name] diff --git a/activesupport/lib/active_support/xml_mini/nokogiri.rb b/activesupport/lib/active_support/xml_mini/nokogiri.rb index 63466c08b2..087112830e 100644 --- a/activesupport/lib/active_support/xml_mini/nokogiri.rb +++ b/activesupport/lib/active_support/xml_mini/nokogiri.rb @@ -1,10 +1,11 @@ +# frozen_string_literal: true begin require "nokogiri" rescue LoadError => e $stderr.puts "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install" raise e end -require "active_support/core_ext/object/blank" +require_relative "../core_ext/object/blank" require "stringio" module ActiveSupport @@ -57,7 +58,7 @@ module ActiveSupport if c.element? c.to_hash(node_hash) elsif c.text? || c.cdata? - node_hash[CONTENT_ROOT] ||= "" + node_hash[CONTENT_ROOT] ||= "".dup node_hash[CONTENT_ROOT] << c.content end end diff --git a/activesupport/lib/active_support/xml_mini/nokogirisax.rb b/activesupport/lib/active_support/xml_mini/nokogirisax.rb index 54e15e6a5f..7a9cd88af7 100644 --- a/activesupport/lib/active_support/xml_mini/nokogirisax.rb +++ b/activesupport/lib/active_support/xml_mini/nokogirisax.rb @@ -1,10 +1,11 @@ +# frozen_string_literal: true begin require "nokogiri" rescue LoadError => e $stderr.puts "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install" raise e end -require "active_support/core_ext/object/blank" +require_relative "../core_ext/object/blank" require "stringio" module ActiveSupport @@ -37,7 +38,7 @@ module ActiveSupport end def start_element(name, attrs = []) - new_hash = { CONTENT_KEY => "" }.merge!(Hash[attrs]) + new_hash = { CONTENT_KEY => "".dup }.merge!(Hash[attrs]) new_hash[HASH_SIZE_KEY] = new_hash.size + 1 case current_hash[name] diff --git a/activesupport/lib/active_support/xml_mini/rexml.rb b/activesupport/lib/active_support/xml_mini/rexml.rb index 03fa910fa5..a5fea919a7 100644 --- a/activesupport/lib/active_support/xml_mini/rexml.rb +++ b/activesupport/lib/active_support/xml_mini/rexml.rb @@ -1,5 +1,6 @@ -require "active_support/core_ext/kernel/reporting" -require "active_support/core_ext/object/blank" +# frozen_string_literal: true +require_relative "../core_ext/kernel/reporting" +require_relative "../core_ext/object/blank" require "stringio" module ActiveSupport @@ -74,7 +75,7 @@ module ActiveSupport hash else # must use value to prevent double-escaping - texts = "" + texts = "".dup element.texts.each { |t| texts << t.value } merge!(hash, CONTENT_KEY, texts) end diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index c4f34c0abf..3004272629 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true ORIG_ARGV = ARGV.dup require "active_support/core_ext/kernel/reporting" diff --git a/activesupport/test/array_inquirer_test.rb b/activesupport/test/array_inquirer_test.rb index 5b2bc82905..c674a80d29 100644 --- a/activesupport/test/array_inquirer_test.rb +++ b/activesupport/test/array_inquirer_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/array" diff --git a/activesupport/test/autoload_test.rb b/activesupport/test/autoload_test.rb index 6c8aa3e055..65838041ea 100644 --- a/activesupport/test/autoload_test.rb +++ b/activesupport/test/autoload_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" class TestAutoloadModule < ActiveSupport::TestCase diff --git a/activesupport/test/autoloading_fixtures/a/b.rb b/activesupport/test/autoloading_fixtures/a/b.rb index 0dbbbbd181..8f2d83719d 100644 --- a/activesupport/test/autoloading_fixtures/a/b.rb +++ b/activesupport/test/autoloading_fixtures/a/b.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true class A::B end diff --git a/activesupport/test/autoloading_fixtures/a/c/d.rb b/activesupport/test/autoloading_fixtures/a/c/d.rb index 2c0ec5f182..fd50bb95c6 100644 --- a/activesupport/test/autoloading_fixtures/a/c/d.rb +++ b/activesupport/test/autoloading_fixtures/a/c/d.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true class A::C::D end diff --git a/activesupport/test/autoloading_fixtures/a/c/em/f.rb b/activesupport/test/autoloading_fixtures/a/c/em/f.rb index 3ff1b7efa0..298b63c916 100644 --- a/activesupport/test/autoloading_fixtures/a/c/em/f.rb +++ b/activesupport/test/autoloading_fixtures/a/c/em/f.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true class A::C::EM::F end diff --git a/activesupport/test/autoloading_fixtures/application.rb b/activesupport/test/autoloading_fixtures/application.rb index d7d3096dcb..ae3ccf487e 100644 --- a/activesupport/test/autoloading_fixtures/application.rb +++ b/activesupport/test/autoloading_fixtures/application.rb @@ -1 +1,2 @@ +# frozen_string_literal: true ApplicationController = 10 diff --git a/activesupport/test/autoloading_fixtures/circular1.rb b/activesupport/test/autoloading_fixtures/circular1.rb index a45761f066..f6041bde77 100644 --- a/activesupport/test/autoloading_fixtures/circular1.rb +++ b/activesupport/test/autoloading_fixtures/circular1.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true silence_warnings do Circular2 end diff --git a/activesupport/test/autoloading_fixtures/circular2.rb b/activesupport/test/autoloading_fixtures/circular2.rb index c847fa5001..178bbca3bd 100644 --- a/activesupport/test/autoloading_fixtures/circular2.rb +++ b/activesupport/test/autoloading_fixtures/circular2.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true Circular1 class Circular2 diff --git a/activesupport/test/autoloading_fixtures/class_folder.rb b/activesupport/test/autoloading_fixtures/class_folder.rb index 6ee8182214..48c2993600 100644 --- a/activesupport/test/autoloading_fixtures/class_folder.rb +++ b/activesupport/test/autoloading_fixtures/class_folder.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class ClassFolder ConstantInClassFolder = "indeed" end diff --git a/activesupport/test/autoloading_fixtures/class_folder/class_folder_subclass.rb b/activesupport/test/autoloading_fixtures/class_folder/class_folder_subclass.rb index 4df069cab6..866d3547f6 100644 --- a/activesupport/test/autoloading_fixtures/class_folder/class_folder_subclass.rb +++ b/activesupport/test/autoloading_fixtures/class_folder/class_folder_subclass.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class ClassFolder::ClassFolderSubclass < ClassFolder ConstantInClassFolder = "indeed" end diff --git a/activesupport/test/autoloading_fixtures/class_folder/inline_class.rb b/activesupport/test/autoloading_fixtures/class_folder/inline_class.rb index 8235e90724..6c20a3a9a7 100644 --- a/activesupport/test/autoloading_fixtures/class_folder/inline_class.rb +++ b/activesupport/test/autoloading_fixtures/class_folder/inline_class.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true class ClassFolder::InlineClass end diff --git a/activesupport/test/autoloading_fixtures/class_folder/nested_class.rb b/activesupport/test/autoloading_fixtures/class_folder/nested_class.rb index 57a13d89ea..ee35eac3fc 100644 --- a/activesupport/test/autoloading_fixtures/class_folder/nested_class.rb +++ b/activesupport/test/autoloading_fixtures/class_folder/nested_class.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class ClassFolder class NestedClass end diff --git a/activesupport/test/autoloading_fixtures/conflict.rb b/activesupport/test/autoloading_fixtures/conflict.rb index d7f42b5d5f..6731ea51d8 100644 --- a/activesupport/test/autoloading_fixtures/conflict.rb +++ b/activesupport/test/autoloading_fixtures/conflict.rb @@ -1 +1,2 @@ +# frozen_string_literal: true Conflict = 2 diff --git a/activesupport/test/autoloading_fixtures/counting_loader.rb b/activesupport/test/autoloading_fixtures/counting_loader.rb index 4225c4412c..2a4001b815 100644 --- a/activesupport/test/autoloading_fixtures/counting_loader.rb +++ b/activesupport/test/autoloading_fixtures/counting_loader.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true $counting_loaded_times ||= 0 $counting_loaded_times += 1 diff --git a/activesupport/test/autoloading_fixtures/cross_site_dependency.rb b/activesupport/test/autoloading_fixtures/cross_site_dependency.rb index de941bf271..4eff14e888 100644 --- a/activesupport/test/autoloading_fixtures/cross_site_dependency.rb +++ b/activesupport/test/autoloading_fixtures/cross_site_dependency.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true class CrossSiteDependency end diff --git a/activesupport/test/autoloading_fixtures/d.rb b/activesupport/test/autoloading_fixtures/d.rb index 52850e1e1a..c4217362d8 100644 --- a/activesupport/test/autoloading_fixtures/d.rb +++ b/activesupport/test/autoloading_fixtures/d.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true class D end diff --git a/activesupport/test/autoloading_fixtures/em.rb b/activesupport/test/autoloading_fixtures/em.rb index e47024999e..38bb323e9e 100644 --- a/activesupport/test/autoloading_fixtures/em.rb +++ b/activesupport/test/autoloading_fixtures/em.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true class EM end diff --git a/activesupport/test/autoloading_fixtures/html/some_class.rb b/activesupport/test/autoloading_fixtures/html/some_class.rb index b43d15d891..495372fef3 100644 --- a/activesupport/test/autoloading_fixtures/html/some_class.rb +++ b/activesupport/test/autoloading_fixtures/html/some_class.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module HTML class SomeClass end diff --git a/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb b/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb index d2c4f6b0c5..e5f73d9f0c 100644 --- a/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb +++ b/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true module LoadedConstant end diff --git a/activesupport/test/autoloading_fixtures/loads_constant.rb b/activesupport/test/autoloading_fixtures/loads_constant.rb index 0b30dc8bca..cb7b381de3 100644 --- a/activesupport/test/autoloading_fixtures/loads_constant.rb +++ b/activesupport/test/autoloading_fixtures/loads_constant.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module LoadsConstant end diff --git a/activesupport/test/autoloading_fixtures/module_folder/inline_class.rb b/activesupport/test/autoloading_fixtures/module_folder/inline_class.rb index ca83437046..5ed98cd4cf 100644 --- a/activesupport/test/autoloading_fixtures/module_folder/inline_class.rb +++ b/activesupport/test/autoloading_fixtures/module_folder/inline_class.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true class ModuleFolder::InlineClass end diff --git a/activesupport/test/autoloading_fixtures/module_folder/nested_class.rb b/activesupport/test/autoloading_fixtures/module_folder/nested_class.rb index fc4076bd0a..afed4b0a7e 100644 --- a/activesupport/test/autoloading_fixtures/module_folder/nested_class.rb +++ b/activesupport/test/autoloading_fixtures/module_folder/nested_class.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ModuleFolder class NestedClass end diff --git a/activesupport/test/autoloading_fixtures/module_folder/nested_sibling.rb b/activesupport/test/autoloading_fixtures/module_folder/nested_sibling.rb index 04c426833e..a16cc566dd 100644 --- a/activesupport/test/autoloading_fixtures/module_folder/nested_sibling.rb +++ b/activesupport/test/autoloading_fixtures/module_folder/nested_sibling.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true class ModuleFolder::NestedSibling end diff --git a/activesupport/test/autoloading_fixtures/module_with_custom_const_missing/a/b.rb b/activesupport/test/autoloading_fixtures/module_with_custom_const_missing/a/b.rb index 4f2020c503..a6ed49e0be 100644 --- a/activesupport/test/autoloading_fixtures/module_with_custom_const_missing/a/b.rb +++ b/activesupport/test/autoloading_fixtures/module_with_custom_const_missing/a/b.rb @@ -1 +1,2 @@ +# frozen_string_literal: true ModuleWithCustomConstMissing::A::B = "10" diff --git a/activesupport/test/autoloading_fixtures/multiple_constant_file.rb b/activesupport/test/autoloading_fixtures/multiple_constant_file.rb index a9ff4eb89c..33d371c830 100644 --- a/activesupport/test/autoloading_fixtures/multiple_constant_file.rb +++ b/activesupport/test/autoloading_fixtures/multiple_constant_file.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true MultipleConstantFile = 10 SiblingConstant = MultipleConstantFile * 2 diff --git a/activesupport/test/autoloading_fixtures/prepend.rb b/activesupport/test/autoloading_fixtures/prepend.rb index 3134d1df2b..1bef4ab5b3 100644 --- a/activesupport/test/autoloading_fixtures/prepend.rb +++ b/activesupport/test/autoloading_fixtures/prepend.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class SubClassConflict end diff --git a/activesupport/test/autoloading_fixtures/prepend/sub_class_conflict.rb b/activesupport/test/autoloading_fixtures/prepend/sub_class_conflict.rb index 090dda3043..d76b575b06 100644 --- a/activesupport/test/autoloading_fixtures/prepend/sub_class_conflict.rb +++ b/activesupport/test/autoloading_fixtures/prepend/sub_class_conflict.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true class Prepend::SubClassConflict end diff --git a/activesupport/test/autoloading_fixtures/raises_arbitrary_exception.rb b/activesupport/test/autoloading_fixtures/raises_arbitrary_exception.rb index e477ab21d0..814c41c004 100644 --- a/activesupport/test/autoloading_fixtures/raises_arbitrary_exception.rb +++ b/activesupport/test/autoloading_fixtures/raises_arbitrary_exception.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RaisesArbitraryException = 1 _ = A::B # Autoloading recursion, also expected to be watched and discarded. diff --git a/activesupport/test/autoloading_fixtures/raises_name_error.rb b/activesupport/test/autoloading_fixtures/raises_name_error.rb index a49960abf0..051f839994 100644 --- a/activesupport/test/autoloading_fixtures/raises_name_error.rb +++ b/activesupport/test/autoloading_fixtures/raises_name_error.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class RaisesNameError FooBarBaz end diff --git a/activesupport/test/autoloading_fixtures/raises_no_method_error.rb b/activesupport/test/autoloading_fixtures/raises_no_method_error.rb index e1b8fce24a..1db51879c7 100644 --- a/activesupport/test/autoloading_fixtures/raises_no_method_error.rb +++ b/activesupport/test/autoloading_fixtures/raises_no_method_error.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class RaisesNoMethodError self.foobar_method_doesnt_exist end diff --git a/activesupport/test/autoloading_fixtures/requires_constant.rb b/activesupport/test/autoloading_fixtures/requires_constant.rb index f04dcc4091..a26e265f71 100644 --- a/activesupport/test/autoloading_fixtures/requires_constant.rb +++ b/activesupport/test/autoloading_fixtures/requires_constant.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "loaded_constant" module RequiresConstant diff --git a/activesupport/test/autoloading_fixtures/should_not_be_required.rb b/activesupport/test/autoloading_fixtures/should_not_be_required.rb index 1fcf170cc5..c1fada8213 100644 --- a/activesupport/test/autoloading_fixtures/should_not_be_required.rb +++ b/activesupport/test/autoloading_fixtures/should_not_be_required.rb @@ -1 +1,2 @@ +# frozen_string_literal: true ShouldNotBeAutoloaded = 0 diff --git a/activesupport/test/autoloading_fixtures/throws.rb b/activesupport/test/autoloading_fixtures/throws.rb index e1d96cc512..431111afbe 100644 --- a/activesupport/test/autoloading_fixtures/throws.rb +++ b/activesupport/test/autoloading_fixtures/throws.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true Throws = 1 _ = A::B # Autoloading recursion, expected to be discarded. diff --git a/activesupport/test/autoloading_fixtures/typo.rb b/activesupport/test/autoloading_fixtures/typo.rb index 0ffe07c2b3..0b74d73f3f 100644 --- a/activesupport/test/autoloading_fixtures/typo.rb +++ b/activesupport/test/autoloading_fixtures/typo.rb @@ -1 +1,2 @@ +# frozen_string_literal: true TypO = 1 diff --git a/activesupport/test/benchmarkable_test.rb b/activesupport/test/benchmarkable_test.rb index 210b9cb9fd..cb8cb89a30 100644 --- a/activesupport/test/benchmarkable_test.rb +++ b/activesupport/test/benchmarkable_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" class BenchmarkableTest < ActiveSupport::TestCase diff --git a/activesupport/test/broadcast_logger_test.rb b/activesupport/test/broadcast_logger_test.rb index 184d0ebddd..c91e3f770f 100644 --- a/activesupport/test/broadcast_logger_test.rb +++ b/activesupport/test/broadcast_logger_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" module ActiveSupport diff --git a/activesupport/test/cache/behaviors.rb b/activesupport/test/cache/behaviors.rb index efd045ac5e..c94cbc1156 100644 --- a/activesupport/test/cache/behaviors.rb +++ b/activesupport/test/cache/behaviors.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require_relative "behaviors/autoloading_cache_behavior" require_relative "behaviors/cache_delete_matched_behavior" require_relative "behaviors/cache_increment_decrement_behavior" diff --git a/activesupport/test/cache/behaviors/autoloading_cache_behavior.rb b/activesupport/test/cache/behaviors/autoloading_cache_behavior.rb index 5f8af331f6..41a3a873b6 100644 --- a/activesupport/test/cache/behaviors/autoloading_cache_behavior.rb +++ b/activesupport/test/cache/behaviors/autoloading_cache_behavior.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "dependencies_test_helpers" module AutoloadingCacheBehavior diff --git a/activesupport/test/cache/behaviors/cache_delete_matched_behavior.rb b/activesupport/test/cache/behaviors/cache_delete_matched_behavior.rb index b872eb0279..b2cd919da9 100644 --- a/activesupport/test/cache/behaviors/cache_delete_matched_behavior.rb +++ b/activesupport/test/cache/behaviors/cache_delete_matched_behavior.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module CacheDeleteMatchedBehavior def test_delete_matched @cache.write("foo", "bar") diff --git a/activesupport/test/cache/behaviors/cache_increment_decrement_behavior.rb b/activesupport/test/cache/behaviors/cache_increment_decrement_behavior.rb index 0d32339565..45f92f10b2 100644 --- a/activesupport/test/cache/behaviors/cache_increment_decrement_behavior.rb +++ b/activesupport/test/cache/behaviors/cache_increment_decrement_behavior.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module CacheIncrementDecrementBehavior def test_increment @cache.write("foo", 1, raw: true) diff --git a/activesupport/test/cache/behaviors/cache_store_behavior.rb b/activesupport/test/cache/behaviors/cache_store_behavior.rb index 03c366e164..32373644cf 100644 --- a/activesupport/test/cache/behaviors/cache_store_behavior.rb +++ b/activesupport/test/cache/behaviors/cache_store_behavior.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Tests the base functionality that should be identical across all cache stores. module CacheStoreBehavior def test_should_read_and_write_strings @@ -196,7 +197,7 @@ module CacheStoreBehavior end def test_original_store_objects_should_not_be_immutable - bar = "bar" + bar = "bar".dup @cache.write("foo", bar) assert_nothing_raised { bar.gsub!(/.*/, "baz") } end @@ -285,7 +286,7 @@ module CacheStoreBehavior end def test_really_long_keys - key = "" + key = "".dup 900.times { key << "x" } assert @cache.write(key, "bar") assert_equal "bar", @cache.read(key) diff --git a/activesupport/test/cache/behaviors/cache_store_version_behavior.rb b/activesupport/test/cache/behaviors/cache_store_version_behavior.rb index a0170c896f..82f392c86a 100644 --- a/activesupport/test/cache/behaviors/cache_store_version_behavior.rb +++ b/activesupport/test/cache/behaviors/cache_store_version_behavior.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module CacheStoreVersionBehavior ModelWithKeyAndVersion = Struct.new(:cache_key, :cache_version) diff --git a/activesupport/test/cache/behaviors/encoded_key_cache_behavior.rb b/activesupport/test/cache/behaviors/encoded_key_cache_behavior.rb index 4d8e2946b2..361903ab82 100644 --- a/activesupport/test/cache/behaviors/encoded_key_cache_behavior.rb +++ b/activesupport/test/cache/behaviors/encoded_key_cache_behavior.rb @@ -1,10 +1,11 @@ +# frozen_string_literal: true # https://rails.lighthouseapp.com/projects/8994/tickets/6225-memcachestore-cant-deal-with-umlauts-and-special-characters # The error is caused by character encodings that can't be compared with ASCII-8BIT regular expressions and by special # characters like the umlaut in UTF-8. module EncodedKeyCacheBehavior Encoding.list.each do |encoding| define_method "test_#{encoding.name.underscore}_encoded_values" do - key = "foo".force_encoding(encoding) + key = "foo".dup.force_encoding(encoding) assert @cache.write(key, "1", raw: true) assert_equal "1", @cache.read(key) assert_equal "1", @cache.fetch(key) @@ -16,7 +17,7 @@ module EncodedKeyCacheBehavior end def test_common_utf8_values - key = "\xC3\xBCmlaut".force_encoding(Encoding::UTF_8) + key = "\xC3\xBCmlaut".dup.force_encoding(Encoding::UTF_8) assert @cache.write(key, "1", raw: true) assert_equal "1", @cache.read(key) assert_equal "1", @cache.fetch(key) @@ -27,7 +28,7 @@ module EncodedKeyCacheBehavior end def test_retains_encoding - key = "\xC3\xBCmlaut".force_encoding(Encoding::UTF_8) + key = "\xC3\xBCmlaut".dup.force_encoding(Encoding::UTF_8) assert @cache.write(key, "1", raw: true) assert_equal Encoding::UTF_8, key.encoding end diff --git a/activesupport/test/cache/behaviors/local_cache_behavior.rb b/activesupport/test/cache/behaviors/local_cache_behavior.rb index 8530296374..730f0306b8 100644 --- a/activesupport/test/cache/behaviors/local_cache_behavior.rb +++ b/activesupport/test/cache/behaviors/local_cache_behavior.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module LocalCacheBehavior def test_local_writes_are_persistent_on_the_remote_cache retval = @cache.with_local_cache do diff --git a/activesupport/test/cache/cache_entry_test.rb b/activesupport/test/cache/cache_entry_test.rb index e446e39b10..4a8fc5bed3 100644 --- a/activesupport/test/cache/cache_entry_test.rb +++ b/activesupport/test/cache/cache_entry_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/cache" diff --git a/activesupport/test/cache/cache_key_test.rb b/activesupport/test/cache/cache_key_test.rb index 149d0f66ee..19c40d44d6 100644 --- a/activesupport/test/cache/cache_key_test.rb +++ b/activesupport/test/cache/cache_key_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/cache" @@ -45,7 +46,7 @@ class CacheKeyTest < ActiveSupport::TestCase end def test_expand_cache_key_respond_to_cache_key - key = "foo" + key = "foo".dup def key.cache_key :foo_key end @@ -53,7 +54,7 @@ class CacheKeyTest < ActiveSupport::TestCase end def test_expand_cache_key_array_with_something_that_responds_to_cache_key - key = "foo" + key = "foo".dup def key.cache_key :foo_key end diff --git a/activesupport/test/cache/cache_store_logger_test.rb b/activesupport/test/cache/cache_store_logger_test.rb index 621cfebb10..3014c4d57f 100644 --- a/activesupport/test/cache/cache_store_logger_test.rb +++ b/activesupport/test/cache/cache_store_logger_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/cache" diff --git a/activesupport/test/cache/cache_store_namespace_test.rb b/activesupport/test/cache/cache_store_namespace_test.rb index e395c88271..8df048aad0 100644 --- a/activesupport/test/cache/cache_store_namespace_test.rb +++ b/activesupport/test/cache/cache_store_namespace_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/cache" diff --git a/activesupport/test/cache/cache_store_setting_test.rb b/activesupport/test/cache/cache_store_setting_test.rb index cb9b006abe..cc126ec930 100644 --- a/activesupport/test/cache/cache_store_setting_test.rb +++ b/activesupport/test/cache/cache_store_setting_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/cache" require "dalli" diff --git a/activesupport/test/cache/cache_store_write_multi_test.rb b/activesupport/test/cache/cache_store_write_multi_test.rb index 16e3f3b842..9355dde0f4 100644 --- a/activesupport/test/cache/cache_store_write_multi_test.rb +++ b/activesupport/test/cache/cache_store_write_multi_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/cache" diff --git a/activesupport/test/cache/local_cache_middleware_test.rb b/activesupport/test/cache/local_cache_middleware_test.rb index 352502fb43..3f0bd40fbd 100644 --- a/activesupport/test/cache/local_cache_middleware_test.rb +++ b/activesupport/test/cache/local_cache_middleware_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/cache" diff --git a/activesupport/test/cache/stores/file_store_test.rb b/activesupport/test/cache/stores/file_store_test.rb index 48b304fe6e..6ba25bbaec 100644 --- a/activesupport/test/cache/stores/file_store_test.rb +++ b/activesupport/test/cache/stores/file_store_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/cache" require_relative "../behaviors" diff --git a/activesupport/test/cache/stores/mem_cache_store_test.rb b/activesupport/test/cache/stores/mem_cache_store_test.rb index 2dd5264818..e188f5f881 100644 --- a/activesupport/test/cache/stores/mem_cache_store_test.rb +++ b/activesupport/test/cache/stores/mem_cache_store_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/cache" require_relative "../behaviors" diff --git a/activesupport/test/cache/stores/memory_store_test.rb b/activesupport/test/cache/stores/memory_store_test.rb index 3dd1646d56..e8dfe24a2f 100644 --- a/activesupport/test/cache/stores/memory_store_test.rb +++ b/activesupport/test/cache/stores/memory_store_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/cache" require_relative "../behaviors" diff --git a/activesupport/test/cache/stores/null_store_test.rb b/activesupport/test/cache/stores/null_store_test.rb index 23c4e64ee4..0945aceee3 100644 --- a/activesupport/test/cache/stores/null_store_test.rb +++ b/activesupport/test/cache/stores/null_store_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/cache" require_relative "../behaviors" diff --git a/activesupport/test/callback_inheritance_test.rb b/activesupport/test/callback_inheritance_test.rb index 9e2f7527e0..8872a16282 100644 --- a/activesupport/test/callback_inheritance_test.rb +++ b/activesupport/test/callback_inheritance_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" class GrandParent diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb index 4f00afb581..9d924cabb2 100644 --- a/activesupport/test/callbacks_test.rb +++ b/activesupport/test/callbacks_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" module CallbacksTest diff --git a/activesupport/test/class_cache_test.rb b/activesupport/test/class_cache_test.rb index 004b4dc9ce..b3ca3748c2 100644 --- a/activesupport/test/class_cache_test.rb +++ b/activesupport/test/class_cache_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/dependencies" diff --git a/activesupport/test/clean_backtrace_test.rb b/activesupport/test/clean_backtrace_test.rb index 5ed518cdb0..7bbc54dfcc 100644 --- a/activesupport/test/clean_backtrace_test.rb +++ b/activesupport/test/clean_backtrace_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" class BacktraceCleanerFilterTest < ActiveSupport::TestCase diff --git a/activesupport/test/clean_logger_test.rb b/activesupport/test/clean_logger_test.rb index cf37fc5639..923a1cb671 100644 --- a/activesupport/test/clean_logger_test.rb +++ b/activesupport/test/clean_logger_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "stringio" require "active_support/logger" diff --git a/activesupport/test/concern_test.rb b/activesupport/test/concern_test.rb index 7a5a5414a7..e05704393d 100644 --- a/activesupport/test/concern_test.rb +++ b/activesupport/test/concern_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/concern" diff --git a/activesupport/test/configurable_test.rb b/activesupport/test/configurable_test.rb index 3cd6d2d4d0..bd3452334a 100644 --- a/activesupport/test/configurable_test.rb +++ b/activesupport/test/configurable_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/configurable" diff --git a/activesupport/test/constantize_test_cases.rb b/activesupport/test/constantize_test_cases.rb index 32b720bcbb..fa23fd6b65 100644 --- a/activesupport/test/constantize_test_cases.rb +++ b/activesupport/test/constantize_test_cases.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "dependencies_test_helpers" module Ace diff --git a/activesupport/test/core_ext/array/access_test.rb b/activesupport/test/core_ext/array/access_test.rb index a38ea36d00..08af9e1b55 100644 --- a/activesupport/test/core_ext/array/access_test.rb +++ b/activesupport/test/core_ext/array/access_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/array" diff --git a/activesupport/test/core_ext/array/conversions_test.rb b/activesupport/test/core_ext/array/conversions_test.rb index 29e661a99b..5a073344d9 100644 --- a/activesupport/test/core_ext/array/conversions_test.rb +++ b/activesupport/test/core_ext/array/conversions_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/array" require "active_support/core_ext/big_decimal" @@ -58,7 +59,7 @@ class ToSentenceTest < ActiveSupport::TestCase ["one", "two"].to_sentence(passing: "invalid option") end - assert_equal exception.message, "Unknown key: :passing. Valid keys are: :words_connector, :two_words_connector, :last_word_connector, :locale" + assert_equal "Unknown key: :passing. Valid keys are: :words_connector, :two_words_connector, :last_word_connector, :locale", exception.message end def test_always_returns_string diff --git a/activesupport/test/core_ext/array/extract_options_test.rb b/activesupport/test/core_ext/array/extract_options_test.rb index 1651bee0f6..09bf97ae6c 100644 --- a/activesupport/test/core_ext/array/extract_options_test.rb +++ b/activesupport/test/core_ext/array/extract_options_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/array" require "active_support/core_ext/hash" diff --git a/activesupport/test/core_ext/array/grouping_test.rb b/activesupport/test/core_ext/array/grouping_test.rb index 4c6aadba8c..daf47e9a9f 100644 --- a/activesupport/test/core_ext/array/grouping_test.rb +++ b/activesupport/test/core_ext/array/grouping_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/array" diff --git a/activesupport/test/core_ext/array/prepend_append_test.rb b/activesupport/test/core_ext/array/prepend_append_test.rb index 763e26191d..3b38acf56c 100644 --- a/activesupport/test/core_ext/array/prepend_append_test.rb +++ b/activesupport/test/core_ext/array/prepend_append_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/array" diff --git a/activesupport/test/core_ext/array/wrap_test.rb b/activesupport/test/core_ext/array/wrap_test.rb index ae846cb3f2..451f9db2ed 100644 --- a/activesupport/test/core_ext/array/wrap_test.rb +++ b/activesupport/test/core_ext/array/wrap_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/array" diff --git a/activesupport/test/core_ext/bigdecimal_test.rb b/activesupport/test/core_ext/bigdecimal_test.rb index 43b659546f..dbd0762574 100644 --- a/activesupport/test/core_ext/bigdecimal_test.rb +++ b/activesupport/test/core_ext/bigdecimal_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/big_decimal" diff --git a/activesupport/test/core_ext/class/attribute_test.rb b/activesupport/test/core_ext/class/attribute_test.rb index f16043c612..2933b62c58 100644 --- a/activesupport/test/core_ext/class/attribute_test.rb +++ b/activesupport/test/core_ext/class/attribute_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/class/attribute" diff --git a/activesupport/test/core_ext/class_test.rb b/activesupport/test/core_ext/class_test.rb index a7905196ae..c0cabea8fd 100644 --- a/activesupport/test/core_ext/class_test.rb +++ b/activesupport/test/core_ext/class_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/class" require "set" diff --git a/activesupport/test/core_ext/date_and_time_behavior.rb b/activesupport/test/core_ext/date_and_time_behavior.rb index 6c77e8f313..8d908968ef 100644 --- a/activesupport/test/core_ext/date_and_time_behavior.rb +++ b/activesupport/test/core_ext/date_and_time_behavior.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" module DateAndTimeBehavior diff --git a/activesupport/test/core_ext/date_and_time_compatibility_test.rb b/activesupport/test/core_ext/date_and_time_compatibility_test.rb index 6c6205a4d2..04b93105d5 100644 --- a/activesupport/test/core_ext/date_and_time_compatibility_test.rb +++ b/activesupport/test/core_ext/date_and_time_compatibility_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/time" require "time_zone_test_helpers" diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index 50bb1004f7..7c6e705936 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/time" require "core_ext/date_and_time_behavior" diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb index 276fa2bfd3..beddfe4584 100644 --- a/activesupport/test/core_ext/date_time_ext_test.rb +++ b/activesupport/test/core_ext/date_time_ext_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/time" require "core_ext/date_and_time_behavior" diff --git a/activesupport/test/core_ext/digest/uuid_test.rb b/activesupport/test/core_ext/digest/uuid_test.rb index 866a03259a..ea3605bf9c 100644 --- a/activesupport/test/core_ext/digest/uuid_test.rb +++ b/activesupport/test/core_ext/digest/uuid_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/digest/uuid" diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index cd1b505c34..32c0ce4317 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/inflector" require "active_support/time" diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index 0b345ecf0f..3259109b0e 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/array" require "active_support/core_ext/enumerable" diff --git a/activesupport/test/core_ext/file_test.rb b/activesupport/test/core_ext/file_test.rb index df5d09acd0..67b1a04429 100644 --- a/activesupport/test/core_ext/file_test.rb +++ b/activesupport/test/core_ext/file_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/file" diff --git a/activesupport/test/core_ext/hash/transform_keys_test.rb b/activesupport/test/core_ext/hash/transform_keys_test.rb index 7a11d827f8..f329246bdd 100644 --- a/activesupport/test/core_ext/hash/transform_keys_test.rb +++ b/activesupport/test/core_ext/hash/transform_keys_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/hash/keys" diff --git a/activesupport/test/core_ext/hash/transform_values_test.rb b/activesupport/test/core_ext/hash/transform_values_test.rb index f2ac4ce6ce..4eb6999510 100644 --- a/activesupport/test/core_ext/hash/transform_values_test.rb +++ b/activesupport/test/core_ext/hash/transform_values_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/hash/indifferent_access" require "active_support/core_ext/hash/transform_values" diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 18da5fcf5f..c533c002a4 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/hash" require "bigdecimal" diff --git a/activesupport/test/core_ext/integer_ext_test.rb b/activesupport/test/core_ext/integer_ext_test.rb index 137e8ce85f..a7ea084e7f 100644 --- a/activesupport/test/core_ext/integer_ext_test.rb +++ b/activesupport/test/core_ext/integer_ext_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/integer" diff --git a/activesupport/test/core_ext/kernel/concern_test.rb b/activesupport/test/core_ext/kernel/concern_test.rb index e7e4f99d7e..1f4fb8029c 100644 --- a/activesupport/test/core_ext/kernel/concern_test.rb +++ b/activesupport/test/core_ext/kernel/concern_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/kernel/concern" diff --git a/activesupport/test/core_ext/kernel_test.rb b/activesupport/test/core_ext/kernel_test.rb index 26f5088ede..875598f611 100644 --- a/activesupport/test/core_ext/kernel_test.rb +++ b/activesupport/test/core_ext/kernel_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/kernel" diff --git a/activesupport/test/core_ext/load_error_test.rb b/activesupport/test/core_ext/load_error_test.rb index 44ff6bb051..3d003fd1d5 100644 --- a/activesupport/test/core_ext/load_error_test.rb +++ b/activesupport/test/core_ext/load_error_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/load_error" diff --git a/activesupport/test/core_ext/marshal_test.rb b/activesupport/test/core_ext/marshal_test.rb index cabeed2fae..d17a6fe7f1 100644 --- a/activesupport/test/core_ext/marshal_test.rb +++ b/activesupport/test/core_ext/marshal_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/marshal" require "dependencies_test_helpers" diff --git a/activesupport/test/core_ext/module/anonymous_test.rb b/activesupport/test/core_ext/module/anonymous_test.rb index f885444284..d667bc0a34 100644 --- a/activesupport/test/core_ext/module/anonymous_test.rb +++ b/activesupport/test/core_ext/module/anonymous_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/module/anonymous" diff --git a/activesupport/test/core_ext/module/attr_internal_test.rb b/activesupport/test/core_ext/module/attr_internal_test.rb index 8458e278ee..12dc2f101a 100644 --- a/activesupport/test/core_ext/module/attr_internal_test.rb +++ b/activesupport/test/core_ext/module/attr_internal_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/module/attr_internal" diff --git a/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb b/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb index af240bc38d..e8587e3424 100644 --- a/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb +++ b/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/module/attribute_accessors_per_thread" diff --git a/activesupport/test/core_ext/module/attribute_accessor_test.rb b/activesupport/test/core_ext/module/attribute_accessor_test.rb index 9b185e9381..2cf33fcc12 100644 --- a/activesupport/test/core_ext/module/attribute_accessor_test.rb +++ b/activesupport/test/core_ext/module/attribute_accessor_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/module/attribute_accessors" diff --git a/activesupport/test/core_ext/module/attribute_aliasing_test.rb b/activesupport/test/core_ext/module/attribute_aliasing_test.rb index fdfa868851..9e5edda77a 100644 --- a/activesupport/test/core_ext/module/attribute_aliasing_test.rb +++ b/activesupport/test/core_ext/module/attribute_aliasing_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/module/aliasing" diff --git a/activesupport/test/core_ext/module/concerning_test.rb b/activesupport/test/core_ext/module/concerning_test.rb index 098036828a..64accc06fc 100644 --- a/activesupport/test/core_ext/module/concerning_test.rb +++ b/activesupport/test/core_ext/module/concerning_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/module/concerning" diff --git a/activesupport/test/core_ext/module/introspection_test.rb b/activesupport/test/core_ext/module/introspection_test.rb index db383850cd..589c9455ed 100644 --- a/activesupport/test/core_ext/module/introspection_test.rb +++ b/activesupport/test/core_ext/module/introspection_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/module/introspection" diff --git a/activesupport/test/core_ext/module/reachable_test.rb b/activesupport/test/core_ext/module/reachable_test.rb index 487c7dee16..f8970bc9f4 100644 --- a/activesupport/test/core_ext/module/reachable_test.rb +++ b/activesupport/test/core_ext/module/reachable_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/module/reachable" diff --git a/activesupport/test/core_ext/module/remove_method_test.rb b/activesupport/test/core_ext/module/remove_method_test.rb index 0c627f1e74..327c66e3ec 100644 --- a/activesupport/test/core_ext/module/remove_method_test.rb +++ b/activesupport/test/core_ext/module/remove_method_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/module/remove_method" diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index a4d4444d69..3dd10ab325 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/module" @@ -392,4 +393,42 @@ class ModuleTest < ActiveSupport::TestCase event = Event.new(Tester.new) assert_equal 1, event.foo end + + def test_private_delegate + location = Class.new do + def initialize(place) + @place = place + end + + private(*delegate(:street, :city, to: :@place)) + end + + place = location.new(Somewhere.new("Such street", "Sad city")) + + assert_not place.respond_to?(:street) + assert_not place.respond_to?(:city) + + assert place.respond_to?(:street, true) # Asking for private method + assert place.respond_to?(:city, true) + end + + def test_private_delegate_prefixed + location = Class.new do + def initialize(place) + @place = place + end + + private(*delegate(:street, :city, to: :@place, prefix: :the)) + end + + place = location.new(Somewhere.new("Such street", "Sad city")) + + assert_not place.respond_to?(:street) + assert_not place.respond_to?(:city) + + assert_not place.respond_to?(:the_street) + assert place.respond_to?(:the_street, true) + assert_not place.respond_to?(:the_city) + assert place.respond_to?(:the_city, true) + end end diff --git a/activesupport/test/core_ext/name_error_test.rb b/activesupport/test/core_ext/name_error_test.rb index fdb9493d3c..a99b20602d 100644 --- a/activesupport/test/core_ext/name_error_test.rb +++ b/activesupport/test/core_ext/name_error_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/name_error" diff --git a/activesupport/test/core_ext/numeric_ext_test.rb b/activesupport/test/core_ext/numeric_ext_test.rb index 3cfbe6e7e6..d4e03a90a4 100644 --- a/activesupport/test/core_ext/numeric_ext_test.rb +++ b/activesupport/test/core_ext/numeric_ext_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/time" require "active_support/core_ext/numeric" diff --git a/activesupport/test/core_ext/object/acts_like_test.rb b/activesupport/test/core_ext/object/acts_like_test.rb index 631f4e63a8..1f1b71f748 100644 --- a/activesupport/test/core_ext/object/acts_like_test.rb +++ b/activesupport/test/core_ext/object/acts_like_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/object" diff --git a/activesupport/test/core_ext/object/blank_test.rb b/activesupport/test/core_ext/object/blank_test.rb index 7fd3fed042..fbd96893f6 100644 --- a/activesupport/test/core_ext/object/blank_test.rb +++ b/activesupport/test/core_ext/object/blank_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/object/blank" diff --git a/activesupport/test/core_ext/object/deep_dup_test.rb b/activesupport/test/core_ext/object/deep_dup_test.rb index f247ee16de..d6f0a71c5b 100644 --- a/activesupport/test/core_ext/object/deep_dup_test.rb +++ b/activesupport/test/core_ext/object/deep_dup_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/object" diff --git a/activesupport/test/core_ext/object/duplicable_test.rb b/activesupport/test/core_ext/object/duplicable_test.rb index 68b0129980..7607e98b0c 100644 --- a/activesupport/test/core_ext/object/duplicable_test.rb +++ b/activesupport/test/core_ext/object/duplicable_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "bigdecimal" require "active_support/core_ext/object/duplicable" diff --git a/activesupport/test/core_ext/object/inclusion_test.rb b/activesupport/test/core_ext/object/inclusion_test.rb index 955686d6aa..b706e6b90f 100644 --- a/activesupport/test/core_ext/object/inclusion_test.rb +++ b/activesupport/test/core_ext/object/inclusion_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/object/inclusion" diff --git a/activesupport/test/core_ext/object/instance_variables_test.rb b/activesupport/test/core_ext/object/instance_variables_test.rb index 5bdb2fbc35..df38282fb0 100644 --- a/activesupport/test/core_ext/object/instance_variables_test.rb +++ b/activesupport/test/core_ext/object/instance_variables_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/object" diff --git a/activesupport/test/core_ext/object/json_cherry_pick_test.rb b/activesupport/test/core_ext/object/json_cherry_pick_test.rb index dd4e90918e..9f3f92a74b 100644 --- a/activesupport/test/core_ext/object/json_cherry_pick_test.rb +++ b/activesupport/test/core_ext/object/json_cherry_pick_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" # These test cases were added to test that cherry-picking the json extensions diff --git a/activesupport/test/core_ext/object/json_gem_encoding_test.rb b/activesupport/test/core_ext/object/json_gem_encoding_test.rb index f5016d0c2a..3ff34e448e 100644 --- a/activesupport/test/core_ext/object/json_gem_encoding_test.rb +++ b/activesupport/test/core_ext/object/json_gem_encoding_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "json" require "json/encoding_test_cases" diff --git a/activesupport/test/core_ext/object/to_param_test.rb b/activesupport/test/core_ext/object/to_param_test.rb index 56246b24f3..e446092abe 100644 --- a/activesupport/test/core_ext/object/to_param_test.rb +++ b/activesupport/test/core_ext/object/to_param_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/object/to_param" diff --git a/activesupport/test/core_ext/object/to_query_test.rb b/activesupport/test/core_ext/object/to_query_test.rb index 298c8bf373..44147d47cf 100644 --- a/activesupport/test/core_ext/object/to_query_test.rb +++ b/activesupport/test/core_ext/object/to_query_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/ordered_hash" require "active_support/core_ext/object/to_query" diff --git a/activesupport/test/core_ext/object/try_test.rb b/activesupport/test/core_ext/object/try_test.rb index 5c8bf59952..fe437f6260 100644 --- a/activesupport/test/core_ext/object/try_test.rb +++ b/activesupport/test/core_ext/object/try_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/object" diff --git a/activesupport/test/core_ext/range_ext_test.rb b/activesupport/test/core_ext/range_ext_test.rb index d166c7309c..693de2755d 100644 --- a/activesupport/test/core_ext/range_ext_test.rb +++ b/activesupport/test/core_ext/range_ext_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/time" require "active_support/core_ext/numeric" diff --git a/activesupport/test/core_ext/regexp_ext_test.rb b/activesupport/test/core_ext/regexp_ext_test.rb index e569a9f234..c937dad1db 100644 --- a/activesupport/test/core_ext/regexp_ext_test.rb +++ b/activesupport/test/core_ext/regexp_ext_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/regexp" diff --git a/activesupport/test/core_ext/secure_random_test.rb b/activesupport/test/core_ext/secure_random_test.rb index fc25f6ab41..b2ac4640ab 100644 --- a/activesupport/test/core_ext/secure_random_test.rb +++ b/activesupport/test/core_ext/secure_random_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/securerandom" diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index a98951e889..defec8bba0 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "date" require "abstract_unit" require "timeout" @@ -233,7 +234,7 @@ class StringInflectionsTest < ActiveSupport::TestCase 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} + with tabs(\t\t), newlines(\n\n), unicode nextlines(\u0085\u0085) and many spaces( ). \u00a0\u2007}.dup expected = "A string surrounded by various unicode spaces, " \ "with tabs( ), newlines( ), unicode nextlines( ) and many spaces( )." @@ -303,8 +304,8 @@ class StringInflectionsTest < ActiveSupport::TestCase end def test_truncate_multibyte - 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) + 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) end def test_truncate_should_not_be_html_safe @@ -325,7 +326,7 @@ class StringInflectionsTest < ActiveSupport::TestCase end def test_remove! - original = "This is a very good day to die" + original = "This is a very good day to die".dup 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/) @@ -658,7 +659,7 @@ end class OutputSafetyTest < ActiveSupport::TestCase def setup - @string = "hello" + @string = "hello".dup @object = Class.new(Object) do def to_s "other" @@ -734,7 +735,7 @@ class OutputSafetyTest < ActiveSupport::TestCase end test "Concatting safe onto unsafe yields unsafe" do - @other_string = "other" + @other_string = "other".dup string = @string.html_safe @other_string.concat(string) @@ -757,7 +758,7 @@ class OutputSafetyTest < ActiveSupport::TestCase end test "Concatting safe onto unsafe with << yields unsafe" do - @other_string = "other" + @other_string = "other".dup string = @string.html_safe @other_string << string @@ -813,7 +814,7 @@ class OutputSafetyTest < ActiveSupport::TestCase test "Concatting an integer to safe always yields safe" do string = @string.html_safe string = string.concat(13) - assert_equal "hello".concat(13), string + assert_equal "hello".dup.concat(13), string assert string.html_safe? end @@ -868,7 +869,8 @@ end class StringIndentTest < ActiveSupport::TestCase test "does not indent strings that only contain newlines (edge cases)" do - ["", "\n", "\n" * 7].each do |str| + ["", "\n", "\n" * 7].each do |string| + str = string.dup assert_nil str.indent!(8) assert_equal str, str.indent(8) assert_equal str, str.indent(1, "\t") diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index 625a5bffb8..f1c6fa4f8c 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/time" require "core_ext/date_and_time_behavior" diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 70ae793cda..9401b9be07 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/time" require "time_zone_test_helpers" diff --git a/activesupport/test/core_ext/uri_ext_test.rb b/activesupport/test/core_ext/uri_ext_test.rb index 0f13ca9c0e..555716d1c3 100644 --- a/activesupport/test/core_ext/uri_ext_test.rb +++ b/activesupport/test/core_ext/uri_ext_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "uri" require "active_support/core_ext/uri" diff --git a/activesupport/test/current_attributes_test.rb b/activesupport/test/current_attributes_test.rb index 67ef6ef619..f195787135 100644 --- a/activesupport/test/current_attributes_test.rb +++ b/activesupport/test/current_attributes_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" class CurrentAttributesTest < ActiveSupport::TestCase diff --git a/activesupport/test/dependencies/check_warnings.rb b/activesupport/test/dependencies/check_warnings.rb index 03c3dca1d6..d177dce295 100644 --- a/activesupport/test/dependencies/check_warnings.rb +++ b/activesupport/test/dependencies/check_warnings.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true $check_warnings_load_count += 1 $checked_verbose = $VERBOSE diff --git a/activesupport/test/dependencies/conflict.rb b/activesupport/test/dependencies/conflict.rb index 7eff49bbfa..a7199a093b 100644 --- a/activesupport/test/dependencies/conflict.rb +++ b/activesupport/test/dependencies/conflict.rb @@ -1 +1,2 @@ +# frozen_string_literal: true Conflict = 1 diff --git a/activesupport/test/dependencies/cross_site_depender.rb b/activesupport/test/dependencies/cross_site_depender.rb index fbc3b64f56..b414058e27 100644 --- a/activesupport/test/dependencies/cross_site_depender.rb +++ b/activesupport/test/dependencies/cross_site_depender.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class CrossSiteDepender CrossSiteDependency end diff --git a/activesupport/test/dependencies/mutual_one.rb b/activesupport/test/dependencies/mutual_one.rb index 05f08f82d3..f739ce2744 100644 --- a/activesupport/test/dependencies/mutual_one.rb +++ b/activesupport/test/dependencies/mutual_one.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true $mutual_dependencies_count += 1 require_dependency "mutual_two" require_dependency "mutual_two.rb" diff --git a/activesupport/test/dependencies/mutual_two.rb b/activesupport/test/dependencies/mutual_two.rb index 1d87d334af..30034be6d1 100644 --- a/activesupport/test/dependencies/mutual_two.rb +++ b/activesupport/test/dependencies/mutual_two.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true $mutual_dependencies_count += 1 require_dependency "mutual_one.rb" require_dependency "mutual_one" diff --git a/activesupport/test/dependencies/raises_exception.rb b/activesupport/test/dependencies/raises_exception.rb index 0a56680fe3..ce9050e572 100644 --- a/activesupport/test/dependencies/raises_exception.rb +++ b/activesupport/test/dependencies/raises_exception.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true $raises_exception_load_count += 1 raise Exception, "Loading me failed, so do not add to loaded or history." $raises_exception_load_count += 1 diff --git a/activesupport/test/dependencies/raises_exception_without_blame_file.rb b/activesupport/test/dependencies/raises_exception_without_blame_file.rb index 7c3856b1e6..7fb2a5c8bc 100644 --- a/activesupport/test/dependencies/raises_exception_without_blame_file.rb +++ b/activesupport/test/dependencies/raises_exception_without_blame_file.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true exception = Exception.new("I am not blamable!") class << exception undef_method(:blame_file!) diff --git a/activesupport/test/dependencies/requires_nonexistent0.rb b/activesupport/test/dependencies/requires_nonexistent0.rb index 7f8a0d8419..86a66203f8 100644 --- a/activesupport/test/dependencies/requires_nonexistent0.rb +++ b/activesupport/test/dependencies/requires_nonexistent0.rb @@ -1 +1,2 @@ +# frozen_string_literal: true require "RMagickDontExistDude" diff --git a/activesupport/test/dependencies/requires_nonexistent1.rb b/activesupport/test/dependencies/requires_nonexistent1.rb index 0055177d67..a3ec7ce4ef 100644 --- a/activesupport/test/dependencies/requires_nonexistent1.rb +++ b/activesupport/test/dependencies/requires_nonexistent1.rb @@ -1 +1,2 @@ +# frozen_string_literal: true require_dependency "requires_nonexistent0" diff --git a/activesupport/test/dependencies/service_one.rb b/activesupport/test/dependencies/service_one.rb index afc3042269..6149297741 100644 --- a/activesupport/test/dependencies/service_one.rb +++ b/activesupport/test/dependencies/service_one.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true $loaded_service_one ||= 0 $loaded_service_one += 1 diff --git a/activesupport/test/dependencies/service_two.rb b/activesupport/test/dependencies/service_two.rb index aabfc3c553..4c013f1fe3 100644 --- a/activesupport/test/dependencies/service_two.rb +++ b/activesupport/test/dependencies/service_two.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true class ServiceTwo end diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index 1ea36418ff..1aad7fc0ec 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "pp" require "active_support/dependencies" diff --git a/activesupport/test/dependencies_test_helpers.rb b/activesupport/test/dependencies_test_helpers.rb index 451195a143..9ba8f3b9b5 100644 --- a/activesupport/test/dependencies_test_helpers.rb +++ b/activesupport/test/dependencies_test_helpers.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module DependenciesTestHelpers def with_loading(*from) old_mechanism, ActiveSupport::Dependencies.mechanism = ActiveSupport::Dependencies.mechanism, :load diff --git a/activesupport/test/deprecation/method_wrappers_test.rb b/activesupport/test/deprecation/method_wrappers_test.rb index 85d057bb02..33ce4aaeca 100644 --- a/activesupport/test/deprecation/method_wrappers_test.rb +++ b/activesupport/test/deprecation/method_wrappers_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/deprecation" diff --git a/activesupport/test/deprecation/proxy_wrappers_test.rb b/activesupport/test/deprecation/proxy_wrappers_test.rb index 67afd75c44..ff38a8165d 100644 --- a/activesupport/test/deprecation/proxy_wrappers_test.rb +++ b/activesupport/test/deprecation/proxy_wrappers_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/deprecation" diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb index 257cb50fb2..22e0ef9afc 100644 --- a/activesupport/test/deprecation_test.rb +++ b/activesupport/test/deprecation_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/testing/stream" diff --git a/activesupport/test/descendants_tracker_test_cases.rb b/activesupport/test/descendants_tracker_test_cases.rb index cf349d53ee..abae3f5880 100644 --- a/activesupport/test/descendants_tracker_test_cases.rb +++ b/activesupport/test/descendants_tracker_test_cases.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "set" module DescendantsTrackerTestCases diff --git a/activesupport/test/descendants_tracker_with_autoloading_test.rb b/activesupport/test/descendants_tracker_with_autoloading_test.rb index e202667a8a..021093956f 100644 --- a/activesupport/test/descendants_tracker_with_autoloading_test.rb +++ b/activesupport/test/descendants_tracker_with_autoloading_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/descendants_tracker" require "active_support/dependencies" diff --git a/activesupport/test/descendants_tracker_without_autoloading_test.rb b/activesupport/test/descendants_tracker_without_autoloading_test.rb index 72adc30ace..cadd21be92 100644 --- a/activesupport/test/descendants_tracker_without_autoloading_test.rb +++ b/activesupport/test/descendants_tracker_without_autoloading_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/descendants_tracker" require "descendants_tracker_test_cases" diff --git a/activesupport/test/evented_file_update_checker_test.rb b/activesupport/test/evented_file_update_checker_test.rb index f33a5f5764..9450bcb814 100644 --- a/activesupport/test/evented_file_update_checker_test.rb +++ b/activesupport/test/evented_file_update_checker_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "pathname" require "file_update_checker_shared_tests" diff --git a/activesupport/test/executor_test.rb b/activesupport/test/executor_test.rb index 7fefc066b3..c522ea9b52 100644 --- a/activesupport/test/executor_test.rb +++ b/activesupport/test/executor_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" class ExecutorTest < ActiveSupport::TestCase diff --git a/activesupport/test/file_update_checker_shared_tests.rb b/activesupport/test/file_update_checker_shared_tests.rb index 361e7e2349..90ef886b08 100644 --- a/activesupport/test/file_update_checker_shared_tests.rb +++ b/activesupport/test/file_update_checker_shared_tests.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "fileutils" module FileUpdateCheckerSharedTests diff --git a/activesupport/test/file_update_checker_test.rb b/activesupport/test/file_update_checker_test.rb index 55b0b46644..5a4e3bebf2 100644 --- a/activesupport/test/file_update_checker_test.rb +++ b/activesupport/test/file_update_checker_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "file_update_checker_shared_tests" diff --git a/activesupport/test/fixtures/autoload/another_class.rb b/activesupport/test/fixtures/autoload/another_class.rb index ab6e075ab4..f61698823c 100644 --- a/activesupport/test/fixtures/autoload/another_class.rb +++ b/activesupport/test/fixtures/autoload/another_class.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true class Fixtures::AnotherClass end diff --git a/activesupport/test/fixtures/autoload/some_class.rb b/activesupport/test/fixtures/autoload/some_class.rb index 30d41eb0bf..a3b5f831ad 100644 --- a/activesupport/test/fixtures/autoload/some_class.rb +++ b/activesupport/test/fixtures/autoload/some_class.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true class Fixtures::Autoload::SomeClass end diff --git a/activesupport/test/gzip_test.rb b/activesupport/test/gzip_test.rb index 33e0cd2a04..592578fedd 100644 --- a/activesupport/test/gzip_test.rb +++ b/activesupport/test/gzip_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/object/blank" diff --git a/activesupport/test/hash_with_indifferent_access_test.rb b/activesupport/test/hash_with_indifferent_access_test.rb index d68add46cd..b71839a5a2 100644 --- a/activesupport/test/hash_with_indifferent_access_test.rb +++ b/activesupport/test/hash_with_indifferent_access_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/hash" require "bigdecimal" diff --git a/activesupport/test/i18n_test.rb b/activesupport/test/i18n_test.rb index 7d88d2dc6b..58ccbdf108 100644 --- a/activesupport/test/i18n_test.rb +++ b/activesupport/test/i18n_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/time" require "active_support/core_ext/array/conversions" diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index ef956eda90..b22054ebee 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/inflector" diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb index d61ca3fc18..9b0d2867c2 100644 --- a/activesupport/test/inflector_test_cases.rb +++ b/activesupport/test/inflector_test_cases.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module InflectorTestCases SingularToPlural = { "search" => "searches", diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index 6f5051c312..52687a003f 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/json" require "active_support/time" diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index 6d8f7cfbd0..314c11b2fc 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "securerandom" require "abstract_unit" require "active_support/core_ext/string/inflections" diff --git a/activesupport/test/json/encoding_test_cases.rb b/activesupport/test/json/encoding_test_cases.rb index 7e4775cec8..2b64aa624d 100644 --- a/activesupport/test/json/encoding_test_cases.rb +++ b/activesupport/test/json/encoding_test_cases.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "bigdecimal" require "date" require "time" diff --git a/activesupport/test/key_generator_test.rb b/activesupport/test/key_generator_test.rb index 89db9563ac..ae7018274a 100644 --- a/activesupport/test/key_generator_test.rb +++ b/activesupport/test/key_generator_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" begin diff --git a/activesupport/test/lazy_load_hooks_test.rb b/activesupport/test/lazy_load_hooks_test.rb index 3b1959a1c9..761fe46094 100644 --- a/activesupport/test/lazy_load_hooks_test.rb +++ b/activesupport/test/lazy_load_hooks_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" class LazyLoadHooksTest < ActiveSupport::TestCase diff --git a/activesupport/test/log_subscriber_test.rb b/activesupport/test/log_subscriber_test.rb index f6496ef7d6..f30932452f 100644 --- a/activesupport/test/log_subscriber_test.rb +++ b/activesupport/test/log_subscriber_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/log_subscriber/test_helper" diff --git a/activesupport/test/logger_test.rb b/activesupport/test/logger_test.rb index 3f04783401..cd0ddb4b97 100644 --- a/activesupport/test/logger_test.rb +++ b/activesupport/test/logger_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "multibyte_test_helpers" require "stringio" @@ -37,7 +38,7 @@ class LoggerTest < ActiveSupport::TestCase logger = Logger.new f logger.level = Logger::DEBUG - str = "\x80" + str = "\x80".dup str.force_encoding("ASCII-8BIT") logger.add Logger::DEBUG, str @@ -55,7 +56,7 @@ class LoggerTest < ActiveSupport::TestCase logger = Logger.new f logger.level = Logger::DEBUG - str = "\x80" + str = "\x80".dup str.force_encoding("ASCII-8BIT") logger.add Logger::DEBUG, str diff --git a/activesupport/test/message_encryptor_test.rb b/activesupport/test/message_encryptor_test.rb index 4c3515b5e1..33ab7620da 100644 --- a/activesupport/test/message_encryptor_test.rb +++ b/activesupport/test/message_encryptor_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "openssl" require "active_support/time" diff --git a/activesupport/test/message_verifier_test.rb b/activesupport/test/message_verifier_test.rb index d6109c761d..d2964aeb7e 100644 --- a/activesupport/test/message_verifier_test.rb +++ b/activesupport/test/message_verifier_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "openssl" require "active_support/time" diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb index d80d340986..6bef794fe2 100644 --- a/activesupport/test/multibyte_chars_test.rb +++ b/activesupport/test/multibyte_chars_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "multibyte_test_helpers" require "active_support/core_ext/string/multibyte" @@ -51,7 +52,7 @@ class MultibyteCharsTest < ActiveSupport::TestCase end def test_forwarded_method_with_non_string_result_should_be_returned_verbatim - str = "" + str = "".dup 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 } @@ -59,14 +60,14 @@ class MultibyteCharsTest < ActiveSupport::TestCase end def test_should_concatenate - mb_a = "a".mb_chars - mb_b = "b".mb_chars + mb_a = "a".dup.mb_chars + mb_b = "b".dup.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" << mb_b + assert_equal "ab", "a".dup << mb_b assert_equal "abb", mb_a << mb_b end @@ -78,7 +79,7 @@ class MultibyteCharsTest < ActiveSupport::TestCase 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".mb_chars << "b").class + assert_equal ActiveSupport::Multibyte.proxy_class, ("a".dup.mb_chars << "b").class end def test_ascii_strings_are_treated_at_utf8_strings @@ -88,8 +89,8 @@ class MultibyteCharsTest < ActiveSupport::TestCase 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".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)) end def test_should_return_string_as_json @@ -115,12 +116,12 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase %w{capitalize downcase lstrip reverse rstrip swapcase upcase}.each do |method| class_eval(<<-EOTESTS, __FILE__, __LINE__ + 1) def test_#{method}_bang_should_return_self_when_modifying_wrapped_string - chars = ' él piDió Un bUen café ' + chars = ' él piDió Un bUen café '.dup assert_equal chars.object_id, chars.send("#{method}!").object_id end def test_#{method}_bang_should_change_wrapped_string - original = ' él piDió Un bUen café ' + original = ' él piDió Un bUen café '.dup proxy = chars(original.dup) proxy.send("#{method}!") assert_not_equal original, proxy.to_s @@ -133,7 +134,7 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase end def test_tidy_bytes_bang_should_change_wrapped_string - original = " Un bUen café \x92" + original = " Un bUen café \x92".dup proxy = chars(original.dup) proxy.tidy_bytes! assert_not_equal original, proxy.to_s @@ -150,7 +151,7 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase end def test_string_methods_are_chainable - assert chars("").insert(0, "").kind_of?(ActiveSupport::Multibyte.proxy_class) + assert chars("".dup).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) @@ -195,7 +196,7 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase end def test_should_use_character_offsets_for_insert_offsets - assert_equal "", "".mb_chars.insert(0, "") + assert_equal "", "".dup.mb_chars.insert(0, "") assert_equal "こわにちわ", @chars.insert(1, "わ") assert_equal "こわわわにちわ", @chars.insert(2, "わわ") assert_equal "わこわわわにちわ", @chars.insert(0, "わ") @@ -418,13 +419,13 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase end def test_slice_bang_removes_the_slice_from_the_receiver - chars = "úüù".mb_chars + chars = "úüù".dup.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 = "úüù" + string = "úüù".dup chars = string.mb_chars assert_nil chars.slice!(4, 5) assert_equal "úüù", chars diff --git a/activesupport/test/multibyte_conformance_test.rb b/activesupport/test/multibyte_conformance_test.rb index ef1a26135f..be89c85c79 100644 --- a/activesupport/test/multibyte_conformance_test.rb +++ b/activesupport/test/multibyte_conformance_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "multibyte_test_helpers" diff --git a/activesupport/test/multibyte_grapheme_break_conformance_test.rb b/activesupport/test/multibyte_grapheme_break_conformance_test.rb index b3328987ae..855626e779 100644 --- a/activesupport/test/multibyte_grapheme_break_conformance_test.rb +++ b/activesupport/test/multibyte_grapheme_break_conformance_test.rb @@ -1,4 +1,5 @@ # encoding: utf-8 +# frozen_string_literal: true require "abstract_unit" require "multibyte_test_helpers" diff --git a/activesupport/test/multibyte_normalization_conformance_test.rb b/activesupport/test/multibyte_normalization_conformance_test.rb index ebc9f92d23..deb94a7aa3 100644 --- a/activesupport/test/multibyte_normalization_conformance_test.rb +++ b/activesupport/test/multibyte_normalization_conformance_test.rb @@ -1,4 +1,5 @@ # encoding: utf-8 +# frozen_string_literal: true require "abstract_unit" require "multibyte_test_helpers" diff --git a/activesupport/test/multibyte_proxy_test.rb b/activesupport/test/multibyte_proxy_test.rb index c303097f80..27d5cea836 100644 --- a/activesupport/test/multibyte_proxy_test.rb +++ b/activesupport/test/multibyte_proxy_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" class MultibyteProxyText < ActiveSupport::TestCase diff --git a/activesupport/test/multibyte_test_helpers.rb b/activesupport/test/multibyte_test_helpers.rb index a70516bb08..c3346c233a 100644 --- a/activesupport/test/multibyte_test_helpers.rb +++ b/activesupport/test/multibyte_test_helpers.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module MultibyteTestHelpers class Downloader def self.download(from, to) @@ -23,7 +24,7 @@ module MultibyteTestHelpers UNICODE_STRING = "こにちわ".freeze ASCII_STRING = "ohayo".freeze - BYTE_STRING = "\270\236\010\210\245".force_encoding("ASCII-8BIT").freeze + BYTE_STRING = "\270\236\010\210\245".dup.force_encoding("ASCII-8BIT").freeze def chars(str) ActiveSupport::Multibyte::Chars.new(str) diff --git a/activesupport/test/multibyte_unicode_database_test.rb b/activesupport/test/multibyte_unicode_database_test.rb index 3724782930..0defa6dc54 100644 --- a/activesupport/test/multibyte_unicode_database_test.rb +++ b/activesupport/test/multibyte_unicode_database_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" class MultibyteUnicodeDatabaseTest < ActiveSupport::TestCase diff --git a/activesupport/test/notifications/evented_notification_test.rb b/activesupport/test/notifications/evented_notification_test.rb index 24c5befec3..1fd50d540b 100644 --- a/activesupport/test/notifications/evented_notification_test.rb +++ b/activesupport/test/notifications/evented_notification_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" module ActiveSupport diff --git a/activesupport/test/notifications/instrumenter_test.rb b/activesupport/test/notifications/instrumenter_test.rb index 7eacc5cbe7..122afa1cae 100644 --- a/activesupport/test/notifications/instrumenter_test.rb +++ b/activesupport/test/notifications/instrumenter_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/notifications/instrumenter" diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 11f743519f..d92c059f36 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/module/delegation" diff --git a/activesupport/test/number_helper_i18n_test.rb b/activesupport/test/number_helper_i18n_test.rb index a1d1c41dc2..b5ac343390 100644 --- a/activesupport/test/number_helper_i18n_test.rb +++ b/activesupport/test/number_helper_i18n_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/number_helper" require "active_support/core_ext/hash/keys" diff --git a/activesupport/test/number_helper_test.rb b/activesupport/test/number_helper_test.rb index 4caf1428ea..db99ba649f 100644 --- a/activesupport/test/number_helper_test.rb +++ b/activesupport/test/number_helper_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/number_helper" require "active_support/core_ext/string/output_safety" diff --git a/activesupport/test/option_merger_test.rb b/activesupport/test/option_merger_test.rb index c5a6d304ee..90291d6ea8 100644 --- a/activesupport/test/option_merger_test.rb +++ b/activesupport/test/option_merger_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/object/with_options" diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index 2cefab3832..5d7b83d7a2 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/json" require "active_support/core_ext/object/json" diff --git a/activesupport/test/ordered_options_test.rb b/activesupport/test/ordered_options_test.rb index 0417911289..7ff8e01540 100644 --- a/activesupport/test/ordered_options_test.rb +++ b/activesupport/test/ordered_options_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/ordered_options" diff --git a/activesupport/test/reloader_test.rb b/activesupport/test/reloader_test.rb index bdd80307c7..8dafbff04c 100644 --- a/activesupport/test/reloader_test.rb +++ b/activesupport/test/reloader_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" class ReloaderTest < ActiveSupport::TestCase diff --git a/activesupport/test/rescuable_test.rb b/activesupport/test/rescuable_test.rb index 3bdd1651e7..96ed3718af 100644 --- a/activesupport/test/rescuable_test.rb +++ b/activesupport/test/rescuable_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" class WraithAttack < StandardError diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb index 36c068b91f..5a0f6539a4 100644 --- a/activesupport/test/safe_buffer_test.rb +++ b/activesupport/test/safe_buffer_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/string/inflections" require "yaml" diff --git a/activesupport/test/security_utils_test.rb b/activesupport/test/security_utils_test.rb index e8f762da22..34f2eea919 100644 --- a/activesupport/test/security_utils_test.rb +++ b/activesupport/test/security_utils_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/security_utils" diff --git a/activesupport/test/share_lock_test.rb b/activesupport/test/share_lock_test.rb index a5970591fa..7d850b4757 100644 --- a/activesupport/test/share_lock_test.rb +++ b/activesupport/test/share_lock_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "concurrent/atomic/count_down_latch" require "active_support/concurrency/share_lock" diff --git a/activesupport/test/string_inquirer_test.rb b/activesupport/test/string_inquirer_test.rb index 79a715349c..ba9791886d 100644 --- a/activesupport/test/string_inquirer_test.rb +++ b/activesupport/test/string_inquirer_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" class StringInquirerTest < ActiveSupport::TestCase diff --git a/activesupport/test/subscriber_test.rb b/activesupport/test/subscriber_test.rb index 9127da35d4..33f89d237e 100644 --- a/activesupport/test/subscriber_test.rb +++ b/activesupport/test/subscriber_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/subscriber" diff --git a/activesupport/test/tagged_logging_test.rb b/activesupport/test/tagged_logging_test.rb index 2469e827d4..e35ddba74b 100644 --- a/activesupport/test/tagged_logging_test.rb +++ b/activesupport/test/tagged_logging_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/logger" require "active_support/tagged_logging" diff --git a/activesupport/test/test_case_test.rb b/activesupport/test/test_case_test.rb index 40dfbe2542..bc83fc3f07 100644 --- a/activesupport/test/test_case_test.rb +++ b/activesupport/test/test_case_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" class AssertDifferenceTest < ActiveSupport::TestCase diff --git a/activesupport/test/testing/constant_lookup_test.rb b/activesupport/test/testing/constant_lookup_test.rb index 00e69fcdb5..02ef708a63 100644 --- a/activesupport/test/testing/constant_lookup_test.rb +++ b/activesupport/test/testing/constant_lookup_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "dependencies_test_helpers" diff --git a/activesupport/test/testing/file_fixtures_test.rb b/activesupport/test/testing/file_fixtures_test.rb index 9f28252c31..cc00e7f113 100644 --- a/activesupport/test/testing/file_fixtures_test.rb +++ b/activesupport/test/testing/file_fixtures_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "pathname" diff --git a/activesupport/test/testing/method_call_assertions_test.rb b/activesupport/test/testing/method_call_assertions_test.rb index 7887933b15..3912c19b80 100644 --- a/activesupport/test/testing/method_call_assertions_test.rb +++ b/activesupport/test/testing/method_call_assertions_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/testing/method_call_assertions" diff --git a/activesupport/test/time_travel_test.rb b/activesupport/test/time_travel_test.rb index 9d354f14f4..616015b74e 100644 --- a/activesupport/test/time_travel_test.rb +++ b/activesupport/test/time_travel_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/core_ext/date_time" require "active_support/core_ext/numeric/time" diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index de111cc40e..043ff4d385 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/time" require "time_zone_test_helpers" @@ -403,6 +404,16 @@ class TimeZoneTest < ActiveSupport::TestCase end end + def test_parse_with_invalid_date + zone = ActiveSupport::TimeZone["UTC"] + + exception = assert_raises(ArgumentError) do + zone.parse("9000") + end + + assert_equal "argument out of range", exception.message + end + def test_rfc3339 zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] twz = zone.rfc3339("1999-12-31T14:00:00-10:00") diff --git a/activesupport/test/time_zone_test_helpers.rb b/activesupport/test/time_zone_test_helpers.rb index e1d615d154..118dc38b5c 100644 --- a/activesupport/test/time_zone_test_helpers.rb +++ b/activesupport/test/time_zone_test_helpers.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module TimeZoneTestHelpers def with_tz_default(tz = nil) old_tz = Time.zone diff --git a/activesupport/test/transliterate_test.rb b/activesupport/test/transliterate_test.rb index 466b69bcef..1359fe8a8d 100644 --- a/activesupport/test/transliterate_test.rb +++ b/activesupport/test/transliterate_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/inflector/transliterate" diff --git a/activesupport/test/xml_mini/jdom_engine_test.rb b/activesupport/test/xml_mini/jdom_engine_test.rb index fc35ac113b..ae78a0e547 100644 --- a/activesupport/test/xml_mini/jdom_engine_test.rb +++ b/activesupport/test/xml_mini/jdom_engine_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require_relative "xml_mini_engine_test" XMLMiniEngineTest.run_with_platform("java") do diff --git a/activesupport/test/xml_mini/libxml_engine_test.rb b/activesupport/test/xml_mini/libxml_engine_test.rb index f3394ad7f2..64ef5b61a1 100644 --- a/activesupport/test/xml_mini/libxml_engine_test.rb +++ b/activesupport/test/xml_mini/libxml_engine_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require_relative "xml_mini_engine_test" XMLMiniEngineTest.run_with_gem("libxml") do diff --git a/activesupport/test/xml_mini/libxmlsax_engine_test.rb b/activesupport/test/xml_mini/libxmlsax_engine_test.rb index f457e160d6..deeb01eefe 100644 --- a/activesupport/test/xml_mini/libxmlsax_engine_test.rb +++ b/activesupport/test/xml_mini/libxmlsax_engine_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require_relative "xml_mini_engine_test" XMLMiniEngineTest.run_with_gem("libxml") do diff --git a/activesupport/test/xml_mini/nokogiri_engine_test.rb b/activesupport/test/xml_mini/nokogiri_engine_test.rb index 3151e75fc0..10062577f6 100644 --- a/activesupport/test/xml_mini/nokogiri_engine_test.rb +++ b/activesupport/test/xml_mini/nokogiri_engine_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require_relative "xml_mini_engine_test" XMLMiniEngineTest.run_with_gem("nokogiri") do diff --git a/activesupport/test/xml_mini/nokogirisax_engine_test.rb b/activesupport/test/xml_mini/nokogirisax_engine_test.rb index 7dafbdaf48..9d298b77d3 100644 --- a/activesupport/test/xml_mini/nokogirisax_engine_test.rb +++ b/activesupport/test/xml_mini/nokogirisax_engine_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require_relative "xml_mini_engine_test" XMLMiniEngineTest.run_with_gem("nokogiri") do diff --git a/activesupport/test/xml_mini/rexml_engine_test.rb b/activesupport/test/xml_mini/rexml_engine_test.rb index c51f0d3c20..29a9dbfbeb 100644 --- a/activesupport/test/xml_mini/rexml_engine_test.rb +++ b/activesupport/test/xml_mini/rexml_engine_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require_relative "xml_mini_engine_test" class REXMLEngineTest < XMLMiniEngineTest diff --git a/activesupport/test/xml_mini/xml_mini_engine_test.rb b/activesupport/test/xml_mini/xml_mini_engine_test.rb index 244e0b0d3a..6e6be2ff0a 100644 --- a/activesupport/test/xml_mini/xml_mini_engine_test.rb +++ b/activesupport/test/xml_mini/xml_mini_engine_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/xml_mini" require "active_support/core_ext/hash/conversions" diff --git a/activesupport/test/xml_mini_test.rb b/activesupport/test/xml_mini_test.rb index b8caa1d74c..cf66e9ff41 100644 --- a/activesupport/test/xml_mini_test.rb +++ b/activesupport/test/xml_mini_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "abstract_unit" require "active_support/xml_mini" require "active_support/builder" diff --git a/guides/source/i18n.md b/guides/source/i18n.md index 6c8706bc13..aa2b7d1ba9 100644 --- a/guides/source/i18n.md +++ b/guides/source/i18n.md @@ -701,9 +701,11 @@ end ### Pluralization -In English there are only one singular and one plural form for a given string, e.g. "1 message" and "2 messages". Other languages ([Arabic](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#ar), [Japanese](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#ja), [Russian](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#ru) and many more) have different grammars that have additional or fewer [plural forms](http://cldr.unicode.org/index/cldr-spec/plural-rules). Thus, the I18n API provides a flexible pluralization feature. +In many languages — including English — there are only two forms, a singular and a plural, for +a given string, e.g. "1 message" and "2 messages". Other languages ([Arabic](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#ar), [Japanese](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#ja), [Russian](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#ru) and many more) have different grammars that have additional or fewer [plural forms](http://cldr.unicode.org/index/cldr-spec/plural-rules). Thus, the I18n API provides a flexible pluralization feature. -The `:count` interpolation variable has a special role in that it both is interpolated to the translation and used to pick a pluralization from the translations according to the pluralization rules defined by CLDR: +The `:count` interpolation variable has a special role in that it both is interpolated to the translation and used to pick a pluralization from the translations according to the pluralization rules defined in the +pluralization backend. By default, only the English pluralization rules are applied. ```ruby I18n.backend.store_translations :en, inbox: { @@ -733,6 +735,22 @@ The translation denoted as `:one` is regarded as singular, and the `:other` is u If the lookup for the key does not return a Hash suitable for pluralization, an `I18n::InvalidPluralizationData` exception is raised. +#### Locale-specific rules + +The I18n gem provides a Pluralization backend that can be used to enable locale-specific rules. Include it +to the Simple backend, then add the localized pluralization algorithms to translation store, as `i18n.plural.rule`. + +```ruby +I18n::Backend::Simple.include(I18n::Backend::Pluralization) +I18n.backend.store_translations :pt, i18n: { plural: { rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } +I18n.backend.store_translations :pt, apples: { one: 'one or none', other: 'more than one' } + +I18n.t :apples, count: 0, locale: :pt +# => 'one or none' +``` + +Alternatively, the separate gem [rails-i18n](https://github.com/svenfuchs/rails-i18n) can be used to provide a fuller set of locale-specific pluralization rules. + ### Setting and Passing a Locale The locale can be either set pseudo-globally to `I18n.locale` (which uses `Thread.current` like, e.g., `Time.zone`) or can be passed as an option to `#translate` and `#localize`. diff --git a/guides/source/layouts_and_rendering.md b/guides/source/layouts_and_rendering.md index 57e603ec0d..76b325d0bf 100644 --- a/guides/source/layouts_and_rendering.md +++ b/guides/source/layouts_and_rendering.md @@ -379,6 +379,7 @@ Rails understands both numeric status codes and the corresponding symbols shown | | 415 | :unsupported_media_type | | | 416 | :range_not_satisfiable | | | 417 | :expectation_failed | +| | 421 | :misdirected_request | | | 422 | :unprocessable_entity | | | 423 | :locked | | | 424 | :failed_dependency | @@ -386,6 +387,7 @@ Rails understands both numeric status codes and the corresponding symbols shown | | 428 | :precondition_required | | | 429 | :too_many_requests | | | 431 | :request_header_fields_too_large | +| | 451 | :unavailable_for_legal_reasons | | **Server Error** | 500 | :internal_server_error | | | 501 | :not_implemented | | | 502 | :bad_gateway | diff --git a/rails.gemspec b/rails.gemspec index 91316f089f..1dbd86d2fb 100644 --- a/rails.gemspec +++ b/rails.gemspec @@ -28,6 +28,6 @@ Gem::Specification.new do |s| s.add_dependency "actioncable", version s.add_dependency "railties", version - s.add_dependency "bundler", ">= 1.3.0", "< 2.0" + s.add_dependency "bundler", ">= 1.3.0" s.add_dependency "sprockets-rails", ">= 2.0.0" end diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 7d94336207..d793405da1 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,19 @@ +* Load environment file in `dbconsole` command. + + Fixes #29717 + + *Yuji Yaginuma* + +* Add `rails secrets:show` command. + + *Yuji Yaginuma* + +* Allow mounting the same engine several times in different locations. + + Fixes #20204. + + *David Rodríguez* + * Clear screenshot files in `tmp:clear` task. *Yuji Yaginuma* @@ -16,7 +32,7 @@ *Yuji Yaginuma* -* Added a shared section to config/database.yml that will be loaded for all environments. +* Added a shared section to `config/database.yml` that will be loaded for all environments. *Pierre Schambacher* diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index 6d8bf28943..a12ca42c30 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -1,4 +1,4 @@ -require "rails/ruby_version_check" +require_relative "rails/ruby_version_check" require "pathname" @@ -9,8 +9,8 @@ require "active_support/core_ext/module/delegation" require "active_support/core_ext/array/extract_options" require "active_support/core_ext/object/blank" -require "rails/application" -require "rails/version" +require_relative "rails/application" +require_relative "rails/version" require "active_support/railtie" require "action_dispatch/railtie" @@ -48,7 +48,7 @@ module Rails def backtrace_cleaner @backtrace_cleaner ||= begin # Relies on Active Support, so we have to lazy load to postpone definition until Active Support has been loaded - require "rails/backtrace_cleaner" + require_relative "rails/backtrace_cleaner" Rails::BacktraceCleaner.new end end diff --git a/railties/lib/rails/app_loader.rb b/railties/lib/rails/app_loader.rb index 525d5f0161..3dc4fe5414 100644 --- a/railties/lib/rails/app_loader.rb +++ b/railties/lib/rails/app_loader.rb @@ -1,5 +1,5 @@ require "pathname" -require "rails/version" +require_relative "version" module Rails module AppLoader # :nodoc: @@ -43,7 +43,7 @@ EOS $stderr.puts(BUNDLER_WARNING) Object.const_set(:APP_PATH, File.expand_path("config/application", Dir.pwd)) require File.expand_path("../boot", APP_PATH) - require "rails/commands" + require_relative "commands" break end end diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 39ca2db8e1..a71f36840e 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -3,8 +3,8 @@ require "active_support/core_ext/hash/keys" require "active_support/core_ext/object/blank" require "active_support/key_generator" require "active_support/message_verifier" -require "rails/engine" -require "rails/secrets" +require_relative "engine" +require_relative "secrets" module Rails # An Engine with the responsibility of coordinating the whole boot process. @@ -439,7 +439,7 @@ module Rails def run_tasks_blocks(app) #:nodoc: railties.each { |r| r.run_tasks_blocks(app) } super - require "rails/tasks" + require_relative "tasks" task :environment do ActiveSupport.on_load(:before_initialize) { config.eager_load = false } diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index dc0491035d..44b49556d7 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -2,7 +2,7 @@ require "fileutils" require "active_support/notifications" require "active_support/dependencies" require "active_support/descendants_tracker" -require "rails/secrets" +require_relative "../secrets" module Rails class Application diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index fb635c6ae8..7e1359c42b 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -1,7 +1,7 @@ require "active_support/core_ext/kernel/reporting" require "active_support/file_update_checker" -require "rails/engine/configuration" -require "rails/source_annotation_extractor" +require_relative "../engine/configuration" +require_relative "../source_annotation_extractor" module Rails class Application diff --git a/railties/lib/rails/cli.rb b/railties/lib/rails/cli.rb index 973b746068..602e56c961 100644 --- a/railties/lib/rails/cli.rb +++ b/railties/lib/rails/cli.rb @@ -1,13 +1,13 @@ -require "rails/app_loader" +require_relative "app_loader" # If we are inside a Rails application this method performs an exec and thus # the rest of this script is not run. Rails::AppLoader.exec_app -require "rails/ruby_version_check" +require_relative "ruby_version_check" Signal.trap("INT") { puts; exit(1) } -require "rails/command" +require_relative "command" if ARGV.first == "plugin" ARGV.shift diff --git a/railties/lib/rails/code_statistics.rb b/railties/lib/rails/code_statistics.rb index 70dce268f1..5e0d807a21 100644 --- a/railties/lib/rails/code_statistics.rb +++ b/railties/lib/rails/code_statistics.rb @@ -1,4 +1,4 @@ -require "rails/code_statistics_calculator" +require_relative "code_statistics_calculator" require "active_support/core_ext/enumerable" class CodeStatistics #:nodoc: diff --git a/railties/lib/rails/command/base.rb b/railties/lib/rails/command/base.rb index 4f074df473..cd0720be4e 100644 --- a/railties/lib/rails/command/base.rb +++ b/railties/lib/rails/command/base.rb @@ -4,7 +4,7 @@ require "erb" require "active_support/core_ext/string/filters" require "active_support/core_ext/string/inflections" -require "rails/command/actions" +require_relative "actions" module Rails module Command diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb index fff0119c65..a33e2778d4 100644 --- a/railties/lib/rails/commands.rb +++ b/railties/lib/rails/commands.rb @@ -1,4 +1,4 @@ -require "rails/command" +require_relative "command" aliases = { "g" => "generate", diff --git a/railties/lib/rails/commands/application/application_command.rb b/railties/lib/rails/commands/application/application_command.rb index 7675d3b3d1..e92daf9be6 100644 --- a/railties/lib/rails/commands/application/application_command.rb +++ b/railties/lib/rails/commands/application/application_command.rb @@ -1,5 +1,5 @@ -require "rails/generators" -require "rails/generators/rails/app/app_generator" +require_relative "../../generators" +require_relative "../../generators/rails/app/app_generator" module Rails module Generators diff --git a/railties/lib/rails/commands/console/console_command.rb b/railties/lib/rails/commands/console/console_command.rb index ec58540923..1da1e331f1 100644 --- a/railties/lib/rails/commands/console/console_command.rb +++ b/railties/lib/rails/commands/console/console_command.rb @@ -1,7 +1,7 @@ require "irb" require "irb/completion" -require "rails/command/environment_argument" +require_relative "../../command/environment_argument" module Rails class Console diff --git a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb index 5bfbe58d97..b3df5191c6 100644 --- a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb +++ b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb @@ -1,4 +1,4 @@ -require "rails/command/environment_argument" +require_relative "../../command/environment_argument" module Rails class DBConsole @@ -148,6 +148,7 @@ module Rails def perform extract_environment_option_from_argument + require_application_and_environment! Rails::DBConsole.start(options) end end diff --git a/railties/lib/rails/commands/destroy/destroy_command.rb b/railties/lib/rails/commands/destroy/destroy_command.rb index 281732a936..8a6fe67f77 100644 --- a/railties/lib/rails/commands/destroy/destroy_command.rb +++ b/railties/lib/rails/commands/destroy/destroy_command.rb @@ -1,4 +1,4 @@ -require "rails/generators" +require_relative "../../generators" module Rails module Command diff --git a/railties/lib/rails/commands/generate/generate_command.rb b/railties/lib/rails/commands/generate/generate_command.rb index 9dd7ad1012..c2089dbcb7 100644 --- a/railties/lib/rails/commands/generate/generate_command.rb +++ b/railties/lib/rails/commands/generate/generate_command.rb @@ -1,4 +1,4 @@ -require "rails/generators" +require_relative "../../generators" module Rails module Command diff --git a/railties/lib/rails/commands/plugin/plugin_command.rb b/railties/lib/rails/commands/plugin/plugin_command.rb index b40ab006af..e915a24e5b 100644 --- a/railties/lib/rails/commands/plugin/plugin_command.rb +++ b/railties/lib/rails/commands/plugin/plugin_command.rb @@ -34,8 +34,8 @@ module Rails private def run_plugin_generator(plugin_args) - require "rails/generators" - require "rails/generators/rails/plugin/plugin_generator" + require_relative "../../generators" + require_relative "../../generators/rails/plugin/plugin_generator" Rails::Generators::PluginGenerator.start plugin_args end end diff --git a/railties/lib/rails/commands/secrets/secrets_command.rb b/railties/lib/rails/commands/secrets/secrets_command.rb index 5f077a5bcb..45e02fa730 100644 --- a/railties/lib/rails/commands/secrets/secrets_command.rb +++ b/railties/lib/rails/commands/secrets/secrets_command.rb @@ -1,5 +1,5 @@ require "active_support" -require "rails/secrets" +require_relative "../../secrets" module Rails module Command @@ -48,10 +48,14 @@ module Rails end end + def show + say Rails::Secrets.read + end + private def generator - require "rails/generators" - require "rails/generators/rails/encrypted_secrets/encrypted_secrets_generator" + require_relative "../../generators" + require_relative "../../generators/rails/encrypted_secrets/encrypted_secrets_generator" Rails::Generators::EncryptedSecretsGenerator end diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb index ebb4ae795a..b607a63176 100644 --- a/railties/lib/rails/commands/server/server_command.rb +++ b/railties/lib/rails/commands/server/server_command.rb @@ -2,7 +2,7 @@ require "fileutils" require "optparse" require "action_dispatch" require "rails" -require "rails/dev_caching" +require_relative "../../dev_caching" module Rails class Server < ::Rack::Server diff --git a/railties/lib/rails/commands/test/test_command.rb b/railties/lib/rails/commands/test/test_command.rb index dce85cf12d..ca0b6c00fe 100644 --- a/railties/lib/rails/commands/test/test_command.rb +++ b/railties/lib/rails/commands/test/test_command.rb @@ -1,5 +1,5 @@ -require "rails/command" -require "rails/test_unit/minitest_plugin" +require_relative "../../command" +require_relative "../../test_unit/minitest_plugin" module Rails module Command diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index fc7d4909f6..89ed313ff0 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -1,7 +1,7 @@ require "active_support/ordered_options" require "active_support/core_ext/object" -require "rails/paths" -require "rails/rack" +require_relative "paths" +require_relative "rack" module Rails module Configuration diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 2732485c5a..a80593d4b9 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -1,5 +1,5 @@ -require "rails/railtie" -require "rails/engine/railties" +require_relative "railtie" +require_relative "engine/railties" require "active_support/core_ext/module/delegation" require "pathname" require "thread" @@ -437,8 +437,8 @@ module Rails # Load console and invoke the registered hooks. # Check <tt>Rails::Railtie.console</tt> for more info. def load_console(app = self) - require "rails/console/app" - require "rails/console/helpers" + require_relative "console/app" + require_relative "console/helpers" run_console_blocks(app) self end @@ -461,7 +461,7 @@ module Rails # Load Rails generators and invoke the registered hooks. # Check <tt>Rails::Railtie.generators</tt> for more info. def load_generators(app = self) - require "rails/generators" + require_relative "generators" run_generators_blocks(app) Rails::Generators.configure!(app.config.generators) self diff --git a/railties/lib/rails/engine/commands.rb b/railties/lib/rails/engine/commands.rb index b9ef63243a..5267b23d6c 100644 --- a/railties/lib/rails/engine/commands.rb +++ b/railties/lib/rails/engine/commands.rb @@ -4,4 +4,4 @@ unless defined?(APP_PATH) end end -require "rails/commands" +require_relative "../commands" diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index 0c40173c38..9c7e2942bc 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -1,4 +1,4 @@ -require "rails/railtie/configuration" +require_relative "../railtie/configuration" module Rails class Engine diff --git a/railties/lib/rails/engine/updater.rb b/railties/lib/rails/engine/updater.rb index 2ecf994a5c..af2bff1e59 100644 --- a/railties/lib/rails/engine/updater.rb +++ b/railties/lib/rails/engine/updater.rb @@ -1,5 +1,5 @@ -require "rails/generators" -require "rails/generators/rails/plugin/plugin_generator" +require_relative "../generators" +require_relative "../generators/rails/plugin/plugin_generator" module Rails class Engine diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 8f15f3a594..b9a0fe07c8 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -2,7 +2,7 @@ activesupport_path = File.expand_path("../../../activesupport/lib", __dir__) $:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path) require "thor/group" -require "rails/command" +require_relative "command" require "active_support" require "active_support/core_ext/object/blank" diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 8429b6c7b8..760cb2f81e 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -1,10 +1,10 @@ require "fileutils" require "digest/md5" require "active_support/core_ext/string/strip" -require "rails/version" unless defined?(Rails::VERSION) +require_relative "../version" unless defined?(Rails::VERSION) require "open-uri" require "uri" -require "rails/generators" +require_relative "../generators" require "active_support/core_ext/array/extract_options" module Rails diff --git a/railties/lib/rails/generators/css/assets/assets_generator.rb b/railties/lib/rails/generators/css/assets/assets_generator.rb index af7b5cf609..40f3bb3c70 100644 --- a/railties/lib/rails/generators/css/assets/assets_generator.rb +++ b/railties/lib/rails/generators/css/assets/assets_generator.rb @@ -1,4 +1,4 @@ -require "rails/generators/named_base" +require_relative "../../named_base" module Css # :nodoc: module Generators # :nodoc: diff --git a/railties/lib/rails/generators/css/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/css/scaffold/scaffold_generator.rb index cf534030f9..b8c72828a1 100644 --- a/railties/lib/rails/generators/css/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/css/scaffold/scaffold_generator.rb @@ -1,4 +1,4 @@ -require "rails/generators/named_base" +require_relative "../../named_base" module Css # :nodoc: module Generators # :nodoc: diff --git a/railties/lib/rails/generators/erb.rb b/railties/lib/rails/generators/erb.rb index 97d9ab29d4..5314c42e46 100644 --- a/railties/lib/rails/generators/erb.rb +++ b/railties/lib/rails/generators/erb.rb @@ -1,4 +1,4 @@ -require "rails/generators/named_base" +require_relative "named_base" module Erb # :nodoc: module Generators # :nodoc: diff --git a/railties/lib/rails/generators/erb/controller/controller_generator.rb b/railties/lib/rails/generators/erb/controller/controller_generator.rb index 36ecfea09b..fb8222f654 100644 --- a/railties/lib/rails/generators/erb/controller/controller_generator.rb +++ b/railties/lib/rails/generators/erb/controller/controller_generator.rb @@ -1,4 +1,4 @@ -require "rails/generators/erb" +require_relative "../../erb" module Erb # :nodoc: module Generators # :nodoc: diff --git a/railties/lib/rails/generators/erb/mailer/mailer_generator.rb b/railties/lib/rails/generators/erb/mailer/mailer_generator.rb index 3f1d9932f6..53dd3289d4 100644 --- a/railties/lib/rails/generators/erb/mailer/mailer_generator.rb +++ b/railties/lib/rails/generators/erb/mailer/mailer_generator.rb @@ -1,4 +1,4 @@ -require "rails/generators/erb" +require_relative "../../erb" module Erb # :nodoc: module Generators # :nodoc: diff --git a/railties/lib/rails/generators/erb/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/erb/scaffold/scaffold_generator.rb index 0d77ef21da..0929425137 100644 --- a/railties/lib/rails/generators/erb/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/erb/scaffold/scaffold_generator.rb @@ -1,5 +1,5 @@ -require "rails/generators/erb" -require "rails/generators/resource_helpers" +require_relative "../../erb" +require_relative "../../resource_helpers" module Erb # :nodoc: module Generators # :nodoc: diff --git a/railties/lib/rails/generators/js/assets/assets_generator.rb b/railties/lib/rails/generators/js/assets/assets_generator.rb index 52a71b58cd..a4f84cc1ad 100644 --- a/railties/lib/rails/generators/js/assets/assets_generator.rb +++ b/railties/lib/rails/generators/js/assets/assets_generator.rb @@ -1,4 +1,4 @@ -require "rails/generators/named_base" +require_relative "../../named_base" module Js # :nodoc: module Generators # :nodoc: diff --git a/railties/lib/rails/generators/migration.rb b/railties/lib/rails/generators/migration.rb index 82481169c3..57c36f5668 100644 --- a/railties/lib/rails/generators/migration.rb +++ b/railties/lib/rails/generators/migration.rb @@ -1,5 +1,5 @@ require "active_support/concern" -require "rails/generators/actions/create_migration" +require_relative "actions/create_migration" module Rails module Generators diff --git a/railties/lib/rails/generators/model_helpers.rb b/railties/lib/rails/generators/model_helpers.rb index 6f87a18660..5bf480c5c0 100644 --- a/railties/lib/rails/generators/model_helpers.rb +++ b/railties/lib/rails/generators/model_helpers.rb @@ -1,4 +1,4 @@ -require "rails/generators/active_model" +require_relative "active_model" module Rails module Generators diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index aef66adb64..d63a5b0c30 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -1,6 +1,6 @@ require "active_support/core_ext/module/introspection" -require "rails/generators/base" -require "rails/generators/generated_attribute" +require_relative "base" +require_relative "generated_attribute" module Rails module Generators diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 45b9e7bdff..7614e6304b 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -1,4 +1,4 @@ -require "rails/generators/app_base" +require_relative "../../app_base" module Rails module ActionMethods # :nodoc: @@ -515,7 +515,7 @@ module Rails def handle_version_request!(argument) if ["--version", "-v"].include?(argument) - require "rails/version" + require_relative "../../../version" puts "Rails #{Rails::VERSION::STRING}" exit(0) end diff --git a/railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb b/railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb index 1da2fbc1a5..8ba0fc4c5b 100644 --- a/railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb +++ b/railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb @@ -1,5 +1,5 @@ -require "rails/generators/base" -require "rails/secrets" +require_relative "../../base" +require_relative "../../../secrets" module Rails module Generators diff --git a/railties/lib/rails/generators/rails/model/model_generator.rb b/railties/lib/rails/generators/rails/model/model_generator.rb index c32a8a079a..8c8aac54bf 100644 --- a/railties/lib/rails/generators/rails/model/model_generator.rb +++ b/railties/lib/rails/generators/rails/model/model_generator.rb @@ -1,4 +1,4 @@ -require "rails/generators/model_helpers" +require_relative "../../model_helpers" module Rails module Generators diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb index 445235852d..a1209e4624 100644 --- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb @@ -1,5 +1,5 @@ require "active_support/core_ext/hash/slice" -require "rails/generators/rails/app/app_generator" +require_relative "../app/app_generator" require "date" module Rails diff --git a/railties/lib/rails/generators/rails/resource/resource_generator.rb b/railties/lib/rails/generators/rails/resource/resource_generator.rb index 5ac5164af0..fa700c598a 100644 --- a/railties/lib/rails/generators/rails/resource/resource_generator.rb +++ b/railties/lib/rails/generators/rails/resource/resource_generator.rb @@ -1,5 +1,5 @@ -require "rails/generators/resource_helpers" -require "rails/generators/rails/model/model_generator" +require_relative "../../resource_helpers" +require_relative "../model/model_generator" module Rails module Generators diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb index 9522778c09..3f92af4295 100644 --- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb @@ -1,4 +1,4 @@ -require "rails/generators/rails/resource/resource_generator" +require_relative "../resource/resource_generator" module Rails module Generators diff --git a/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb b/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb index cf97c22160..291a208498 100644 --- a/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +++ b/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb @@ -1,4 +1,4 @@ -require "rails/generators/resource_helpers" +require_relative "../../resource_helpers" module Rails module Generators diff --git a/railties/lib/rails/generators/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb index e7cb722473..170da6cb0d 100644 --- a/railties/lib/rails/generators/resource_helpers.rb +++ b/railties/lib/rails/generators/resource_helpers.rb @@ -1,5 +1,5 @@ -require "rails/generators/active_model" -require "rails/generators/model_helpers" +require_relative "active_model" +require_relative "model_helpers" module Rails module Generators diff --git a/railties/lib/rails/generators/test_case.rb b/railties/lib/rails/generators/test_case.rb index 575af80303..6cebd217a7 100644 --- a/railties/lib/rails/generators/test_case.rb +++ b/railties/lib/rails/generators/test_case.rb @@ -1,7 +1,7 @@ -require "rails/generators" -require "rails/generators/testing/behaviour" -require "rails/generators/testing/setup_and_teardown" -require "rails/generators/testing/assertions" +require_relative "../generators" +require_relative "testing/behaviour" +require_relative "testing/setup_and_teardown" +require_relative "testing/assertions" require "fileutils" module Rails diff --git a/railties/lib/rails/generators/test_unit.rb b/railties/lib/rails/generators/test_unit.rb index 722efcf492..986e673611 100644 --- a/railties/lib/rails/generators/test_unit.rb +++ b/railties/lib/rails/generators/test_unit.rb @@ -1,4 +1,4 @@ -require "rails/generators/named_base" +require_relative "named_base" module TestUnit # :nodoc: module Generators # :nodoc: diff --git a/railties/lib/rails/generators/test_unit/controller/controller_generator.rb b/railties/lib/rails/generators/test_unit/controller/controller_generator.rb index ac528d94f1..72a650e7d9 100644 --- a/railties/lib/rails/generators/test_unit/controller/controller_generator.rb +++ b/railties/lib/rails/generators/test_unit/controller/controller_generator.rb @@ -1,4 +1,4 @@ -require "rails/generators/test_unit" +require_relative "../../test_unit" module TestUnit # :nodoc: module Generators # :nodoc: diff --git a/railties/lib/rails/generators/test_unit/generator/generator_generator.rb b/railties/lib/rails/generators/test_unit/generator/generator_generator.rb index 6b6e094453..abc3615cfd 100644 --- a/railties/lib/rails/generators/test_unit/generator/generator_generator.rb +++ b/railties/lib/rails/generators/test_unit/generator/generator_generator.rb @@ -1,4 +1,4 @@ -require "rails/generators/test_unit" +require_relative "../../test_unit" module TestUnit # :nodoc: module Generators # :nodoc: diff --git a/railties/lib/rails/generators/test_unit/helper/helper_generator.rb b/railties/lib/rails/generators/test_unit/helper/helper_generator.rb index 6674a15fa3..2020e7785e 100644 --- a/railties/lib/rails/generators/test_unit/helper/helper_generator.rb +++ b/railties/lib/rails/generators/test_unit/helper/helper_generator.rb @@ -1,4 +1,4 @@ -require "rails/generators/test_unit" +require_relative "../../test_unit" module TestUnit # :nodoc: module Generators # :nodoc: diff --git a/railties/lib/rails/generators/test_unit/integration/integration_generator.rb b/railties/lib/rails/generators/test_unit/integration/integration_generator.rb index 9d065c1297..a31a795212 100644 --- a/railties/lib/rails/generators/test_unit/integration/integration_generator.rb +++ b/railties/lib/rails/generators/test_unit/integration/integration_generator.rb @@ -1,4 +1,4 @@ -require "rails/generators/test_unit" +require_relative "../../test_unit" module TestUnit # :nodoc: module Generators # :nodoc: diff --git a/railties/lib/rails/generators/test_unit/job/job_generator.rb b/railties/lib/rails/generators/test_unit/job/job_generator.rb index 6975252b99..f3ea7cd170 100644 --- a/railties/lib/rails/generators/test_unit/job/job_generator.rb +++ b/railties/lib/rails/generators/test_unit/job/job_generator.rb @@ -1,4 +1,4 @@ -require "rails/generators/test_unit" +require_relative "../../test_unit" module TestUnit # :nodoc: module Generators # :nodoc: diff --git a/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb b/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb index 67bff8e4f9..274755b057 100644 --- a/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb +++ b/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb @@ -1,4 +1,4 @@ -require "rails/generators/test_unit" +require_relative "../../test_unit" module TestUnit # :nodoc: module Generators # :nodoc: diff --git a/railties/lib/rails/generators/test_unit/model/model_generator.rb b/railties/lib/rails/generators/test_unit/model/model_generator.rb index 99495d5247..fef640f947 100644 --- a/railties/lib/rails/generators/test_unit/model/model_generator.rb +++ b/railties/lib/rails/generators/test_unit/model/model_generator.rb @@ -1,4 +1,4 @@ -require "rails/generators/test_unit" +require_relative "../../test_unit" module TestUnit # :nodoc: module Generators # :nodoc: diff --git a/railties/lib/rails/generators/test_unit/plugin/plugin_generator.rb b/railties/lib/rails/generators/test_unit/plugin/plugin_generator.rb index f1c9b6da5b..f324000235 100644 --- a/railties/lib/rails/generators/test_unit/plugin/plugin_generator.rb +++ b/railties/lib/rails/generators/test_unit/plugin/plugin_generator.rb @@ -1,4 +1,4 @@ -require "rails/generators/test_unit" +require_relative "../../test_unit" module TestUnit # :nodoc: module Generators # :nodoc: diff --git a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb index ef2cf3e389..fbe5be3cdc 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb @@ -1,5 +1,5 @@ -require "rails/generators/test_unit" -require "rails/generators/resource_helpers" +require_relative "../../test_unit" +require_relative "../../resource_helpers" module TestUnit # :nodoc: module Generators # :nodoc: diff --git a/railties/lib/rails/generators/test_unit/system/system_generator.rb b/railties/lib/rails/generators/test_unit/system/system_generator.rb index 0514957d9c..95cc86cc8a 100644 --- a/railties/lib/rails/generators/test_unit/system/system_generator.rb +++ b/railties/lib/rails/generators/test_unit/system/system_generator.rb @@ -1,4 +1,4 @@ -require "rails/generators/test_unit" +require_relative "../../test_unit" module TestUnit # :nodoc: module Generators # :nodoc: diff --git a/railties/lib/rails/generators/testing/behaviour.rb b/railties/lib/rails/generators/testing/behaviour.rb index ce0e42e60d..ede181a1bc 100644 --- a/railties/lib/rails/generators/testing/behaviour.rb +++ b/railties/lib/rails/generators/testing/behaviour.rb @@ -4,7 +4,7 @@ require "active_support/core_ext/hash/reverse_merge" require "active_support/core_ext/kernel/reporting" require "active_support/testing/stream" require "active_support/concern" -require "rails/generators" +require_relative "../../generators" module Rails module Generators diff --git a/railties/lib/rails/info_controller.rb b/railties/lib/rails/info_controller.rb index 8b553aea79..9fe6ef5a93 100644 --- a/railties/lib/rails/info_controller.rb +++ b/railties/lib/rails/info_controller.rb @@ -1,4 +1,4 @@ -require "rails/application_controller" +require_relative "application_controller" require "action_dispatch/routing/inspector" class Rails::InfoController < Rails::ApplicationController # :nodoc: diff --git a/railties/lib/rails/mailers_controller.rb b/railties/lib/rails/mailers_controller.rb index 7ff55ef5bf..5b9af97617 100644 --- a/railties/lib/rails/mailers_controller.rb +++ b/railties/lib/rails/mailers_controller.rb @@ -1,4 +1,4 @@ -require "rails/application_controller" +require_relative "application_controller" class Rails::MailersController < Rails::ApplicationController # :nodoc: prepend_view_path ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH diff --git a/railties/lib/rails/plugin/test.rb b/railties/lib/rails/plugin/test.rb index ff043b488e..bd43cba688 100644 --- a/railties/lib/rails/plugin/test.rb +++ b/railties/lib/rails/plugin/test.rb @@ -1,4 +1,4 @@ -require "rails/test_unit/minitest_plugin" +require_relative "../test_unit/minitest_plugin" Rails::TestUnitReporter.executable = "bin/test" diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index eca8335559..a2a0192cfc 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -1,4 +1,4 @@ -require "rails/initializable" +require_relative "initializable" require "active_support/inflector" require "active_support/core_ext/module/introspection" require "active_support/core_ext/module/delegation" diff --git a/railties/lib/rails/railtie/configuration.rb b/railties/lib/rails/railtie/configuration.rb index aecc81c491..275d2039f6 100644 --- a/railties/lib/rails/railtie/configuration.rb +++ b/railties/lib/rails/railtie/configuration.rb @@ -1,4 +1,4 @@ -require "rails/configuration" +require_relative "../configuration" module Rails class Railtie diff --git a/railties/lib/rails/secrets.rb b/railties/lib/rails/secrets.rb index c7a8676d7b..46e21185d7 100644 --- a/railties/lib/rails/secrets.rb +++ b/railties/lib/rails/secrets.rb @@ -101,11 +101,13 @@ module Rails def writing(contents) tmp_path = File.join(Dir.tmpdir, File.basename(path)) - File.write(tmp_path, contents) + IO.binwrite(tmp_path, contents) yield tmp_path - write(File.read(tmp_path)) + updated_contents = IO.binread(tmp_path) + + write(updated_contents) if updated_contents != contents ensure FileUtils.rm(tmp_path) if File.exist?(tmp_path) end diff --git a/railties/lib/rails/tasks/annotations.rake b/railties/lib/rails/tasks/annotations.rake index 9a69eb9934..ae427249ef 100644 --- a/railties/lib/rails/tasks/annotations.rake +++ b/railties/lib/rails/tasks/annotations.rake @@ -1,4 +1,4 @@ -require "rails/source_annotation_extractor" +require_relative "../source_annotation_extractor" desc "Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)" task :notes do diff --git a/railties/lib/rails/tasks/dev.rake b/railties/lib/rails/tasks/dev.rake index 334e968123..b2447cbcfc 100644 --- a/railties/lib/rails/tasks/dev.rake +++ b/railties/lib/rails/tasks/dev.rake @@ -1,4 +1,4 @@ -require "rails/dev_caching" +require_relative "../dev_caching" namespace :dev do desc "Toggle development mode caching on/off" diff --git a/railties/lib/rails/tasks/engine.rake b/railties/lib/rails/tasks/engine.rake index 177b138090..a8d67322da 100644 --- a/railties/lib/rails/tasks/engine.rake +++ b/railties/lib/rails/tasks/engine.rake @@ -6,7 +6,7 @@ task "load_app" do task update: [ "update:bin" ] namespace :update do - require "rails/engine/updater" + require_relative "../engine/updater" # desc "Adds new executables to the engine bin/ directory" task :bin do Rails::Engine::Updater.run(:create_bin_files) diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake index 80720a42ff..f7e8f4f340 100644 --- a/railties/lib/rails/tasks/framework.rake +++ b/railties/lib/rails/tasks/framework.rake @@ -7,8 +7,8 @@ namespace :app do template = ENV["LOCATION"] raise "No LOCATION value given. Please set LOCATION either as path to a file or a URL" if template.blank? template = File.expand_path(template) if template !~ %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} - require "rails/generators" - require "rails/generators/rails/app/app_generator" + require_relative "../generators" + require_relative "../generators/rails/app/app_generator" generator = Rails::Generators::AppGenerator.new [Rails.root], {}, destination_root: Rails.root generator.apply template, verbose: false end @@ -43,8 +43,8 @@ namespace :app do def self.app_generator @app_generator ||= begin - require "rails/generators" - require "rails/generators/rails/app/app_generator" + require_relative "../generators" + require_relative "../generators/rails/app/app_generator" gen = Rails::Generators::AppGenerator.new ["rails"], { api: !!Rails.application.config.api_only, update: true }, destination_root: Rails.root diff --git a/railties/lib/rails/tasks/statistics.rake b/railties/lib/rails/tasks/statistics.rake index cb569be58b..0670050d34 100644 --- a/railties/lib/rails/tasks/statistics.rake +++ b/railties/lib/rails/tasks/statistics.rake @@ -24,6 +24,6 @@ end.select { |name, dir| File.directory?(dir) } desc "Report code statistics (KLOCs, etc) from the application or engine" task :stats do - require "rails/code_statistics" + require_relative "../code_statistics" CodeStatistics.new(*STATS_DIRECTORIES).to_s end diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index 81537d813e..05048eb2e1 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -2,12 +2,12 @@ # so fixtures aren't loaded into that environment abort("Abort testing: Your Rails environment is running in production mode!") if Rails.env.production? -require "rails/test_unit/minitest_plugin" +require_relative "test_unit/minitest_plugin" require "active_support/test_case" require "action_controller" require "action_controller/test_case" require "action_dispatch/testing/integration" -require "rails/generators/test_case" +require_relative "generators/test_case" require "active_support/testing/autorun" diff --git a/railties/lib/rails/test_unit/minitest_plugin.rb b/railties/lib/rails/test_unit/minitest_plugin.rb index 5d0cf1305f..3571274bcd 100644 --- a/railties/lib/rails/test_unit/minitest_plugin.rb +++ b/railties/lib/rails/test_unit/minitest_plugin.rb @@ -1,6 +1,6 @@ require "active_support/core_ext/module/attribute_accessors" -require "rails/test_unit/reporter" -require "rails/test_unit/test_requirer" +require_relative "reporter" +require_relative "test_requirer" require "shellwords" module Minitest diff --git a/railties/lib/rails/test_unit/railtie.rb b/railties/lib/rails/test_unit/railtie.rb index 443e743421..f1965f3b12 100644 --- a/railties/lib/rails/test_unit/railtie.rb +++ b/railties/lib/rails/test_unit/railtie.rb @@ -1,4 +1,4 @@ -require "rails/test_unit/line_filtering" +require_relative "line_filtering" if defined?(Rake.application) && Rake.application.top_level_tasks.grep(/^(default$|test(:|$))/).any? ENV["RAILS_ENV"] ||= Rake.application.options.show_tasks ? "development" : "test" diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index 33408081f1..486446b463 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -1,6 +1,6 @@ gem "minitest" require "minitest" -require "rails/test_unit/minitest_plugin" +require_relative "minitest_plugin" task default: :test diff --git a/railties/lib/rails/welcome_controller.rb b/railties/lib/rails/welcome_controller.rb index b757dc72ef..3b417f65ba 100644 --- a/railties/lib/rails/welcome_controller.rb +++ b/railties/lib/rails/welcome_controller.rb @@ -1,4 +1,4 @@ -require "rails/application_controller" +require_relative "application_controller" class Rails::WelcomeController < Rails::ApplicationController # :nodoc: layout false diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 06767167a9..983ea5c3e6 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -176,13 +176,11 @@ module ApplicationTests test "Rails.application responds to all instance methods" do app "development" - assert_respond_to Rails.application, :routes_reloader assert_equal Rails.application.routes_reloader, AppTemplate::Application.routes_reloader end test "Rails::Application responds to paths" do app "development" - assert_respond_to AppTemplate::Application, :paths assert_equal ["#{app_path}/app/views"], AppTemplate::Application.paths["app/views"].expanded end @@ -1132,6 +1130,8 @@ module ApplicationTests app "development" + ActionController::Base.object_id # force lazy load hooks to run + assert_equal :raise, ActionController::Parameters.action_on_unpermitted_parameters post "/posts", post: { "title" => "zomg" } @@ -1140,6 +1140,9 @@ module ApplicationTests test "config.action_controller.always_permitted_parameters are: controller, action by default" do app "development" + + ActionController::Base.object_id # force lazy load hooks to run + assert_equal %w(controller action), ActionController::Parameters.always_permitted_parameters end @@ -1150,6 +1153,8 @@ module ApplicationTests app "development" + ActionController::Base.object_id # force lazy load hooks to run + assert_equal %w( controller action format ), ActionController::Parameters.always_permitted_parameters end @@ -1172,6 +1177,8 @@ module ApplicationTests app "development" + ActionController::Base.object_id # force lazy load hooks to run + assert_equal :raise, ActionController::Parameters.action_on_unpermitted_parameters post "/posts", post: { "title" => "zomg" }, format: "json" @@ -1181,21 +1188,60 @@ module ApplicationTests test "config.action_controller.action_on_unpermitted_parameters is :log by default on development" do app "development" + ActionController::Base.object_id # force lazy load hooks to run + assert_equal :log, ActionController::Parameters.action_on_unpermitted_parameters end test "config.action_controller.action_on_unpermitted_parameters is :log by default on test" do app "test" + ActionController::Base.object_id # force lazy load hooks to run + assert_equal :log, ActionController::Parameters.action_on_unpermitted_parameters end test "config.action_controller.action_on_unpermitted_parameters is false by default on production" do app "production" + ActionController::Base.object_id # force lazy load hooks to run + assert_equal false, ActionController::Parameters.action_on_unpermitted_parameters end + test "config.action_controller.permit_all_parameters can be configured in an initializer" do + app_file "config/initializers/permit_all_parameters.rb", <<-RUBY + Rails.application.config.action_controller.permit_all_parameters = true + RUBY + + app "development" + + ActionController::Base.object_id # force lazy load hooks to run + assert_equal true, ActionController::Parameters.permit_all_parameters + end + + test "config.action_controller.always_permitted_parameters can be configured in an initializer" do + app_file "config/initializers/always_permitted_parameters.rb", <<-RUBY + Rails.application.config.action_controller.always_permitted_parameters = [] + RUBY + + app "development" + + ActionController::Base.object_id # force lazy load hooks to run + assert_equal [], ActionController::Parameters.always_permitted_parameters + end + + test "config.action_controller.action_on_unpermitted_parameters can be configured in an initializer" do + app_file "config/initializers/action_on_unpermitted_parameters.rb", <<-RUBY + Rails.application.config.action_controller.action_on_unpermitted_parameters = :raise + RUBY + + app "development" + + ActionController::Base.object_id # force lazy load hooks to run + assert_equal :raise, ActionController::Parameters.action_on_unpermitted_parameters + end + test "config.action_dispatch.ignore_accept_header" do make_basic_app do |application| application.config.action_dispatch.ignore_accept_header = true @@ -1220,7 +1266,6 @@ module ApplicationTests test "Rails.application#env_config exists and include some existing parameters" do make_basic_app - assert_respond_to app, :env_config assert_equal app.env_config["action_dispatch.parameter_filter"], app.config.filter_parameters assert_equal app.env_config["action_dispatch.show_exceptions"], app.config.action_dispatch.show_exceptions assert_equal app.env_config["action_dispatch.logger"], Rails.logger diff --git a/railties/test/application/dbconsole_test.rb b/railties/test/application/dbconsole_test.rb new file mode 100644 index 0000000000..7e5e9ea8aa --- /dev/null +++ b/railties/test/application/dbconsole_test.rb @@ -0,0 +1,66 @@ +require "isolation/abstract_unit" +begin + require "pty" +rescue LoadError +end + +module ApplicationTests + class DBConsoleTest < ActiveSupport::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + end + + def teardown + teardown_app + end + + def test_use_value_defined_in_environment_file_in_database_yml + skip "PTY unavailable" unless available_pty? + Dir.chdir(app_path) do + app_file "config/database.yml", <<-YAML + development: + database: <%= Rails.application.config.database %> + adapter: sqlite3 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + timeout: 5000 + YAML + + app_file "config/environments/development.rb", <<-RUBY + Rails.application.configure do + config.database = "db/development.sqlite3" + end + RUBY + end + + master, slave = PTY.open + spawn_dbconsole(slave) + assert_output("sqlite>", master) + ensure + master.puts ".exit" + end + + private + def spawn_dbconsole(fd) + Process.spawn("#{app_path}/bin/rails dbconsole", in: fd, out: fd, err: fd) + end + + def assert_output(expected, io, timeout = 5) + timeout = Time.now + timeout + + output = "" + until output.include?(expected) || Time.now > timeout + if IO.select([io], [], [], 0.1) + output << io.read(1) + end + end + + assert_includes output, expected, "#{expected.inspect} expected, but got:\n\n#{output}" + end + + def available_pty? + defined?(PTY) && PTY.respond_to?(:open) + end + end +end diff --git a/railties/test/application/rake/tmp_test.rb b/railties/test/application/rake/tmp_test.rb index bc9865b0de..8423a98f84 100644 --- a/railties/test/application/rake/tmp_test.rb +++ b/railties/test/application/rake/tmp_test.rb @@ -31,6 +31,13 @@ module ApplicationTests assert_not File.exist?("tmp/screenshots/fail.png") end end + + test "tmp:clear should work if folder missing" do + FileUtils.remove_dir("#{app_path}/tmp") + errormsg = Dir.chdir(app_path) { `bin/rails tmp:clear` } + assert_predicate $?, :success? + assert_empty errormsg + end end end end diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 1b64a0a1ca..5ae6ea925f 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -391,12 +391,5 @@ module ApplicationTests assert_match(/Hello, World!/, output) end - - def test_tmp_clear_should_work_if_folder_missing - FileUtils.remove_dir("#{app_path}/tmp") - errormsg = Dir.chdir(app_path) { `bin/rails tmp:clear` } - assert_predicate $?, :success? - assert_empty errormsg - end end end diff --git a/railties/test/command/base_test.rb b/railties/test/command/base_test.rb index ebfc4d0ba9..bac3285f48 100644 --- a/railties/test/command/base_test.rb +++ b/railties/test/command/base_test.rb @@ -6,6 +6,6 @@ require "rails/commands/secrets/secrets_command" class Rails::Command::BaseTest < ActiveSupport::TestCase test "printing commands" do assert_equal %w(generate), Rails::Command::GenerateCommand.printing_commands - assert_equal %w(secrets:setup secrets:edit), Rails::Command::SecretsCommand.printing_commands + assert_equal %w(secrets:setup secrets:edit secrets:show), Rails::Command::SecretsCommand.printing_commands end end diff --git a/railties/test/commands/secrets_test.rb b/railties/test/commands/secrets_test.rb index be610f3b47..3771919849 100644 --- a/railties/test/commands/secrets_test.rb +++ b/railties/test/commands/secrets_test.rb @@ -27,8 +27,21 @@ class Rails::Command::SecretsCommandTest < ActiveSupport::TestCase end end + test "show secrets" do + run_setup_command + assert_match(/external_api_key: 1466aac22e6a869134be3d09b9e89232fc2c2289/, run_show_command) + end + private def run_edit_command(editor: "cat") Dir.chdir(app_path) { `EDITOR="#{editor}" bin/rails secrets:edit` } end + + def run_show_command + Dir.chdir(app_path) { `bin/rails secrets:show` } + end + + def run_setup_command + Dir.chdir(app_path) { `bin/rails secrets:setup` } + end end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 9364f11a98..059c2692be 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -8,32 +8,70 @@ DEFAULT_APP_FILES = %w( Gemfile Rakefile config.ru + app/assets/config/manifest.js + app/assets/images app/assets/javascripts + app/assets/javascripts/application.js + app/assets/javascripts/cable.js + app/assets/javascripts/channels app/assets/stylesheets - app/assets/images + app/assets/stylesheets/application.css + app/channels/application_cable/channel.rb + app/channels/application_cable/connection.rb app/controllers + app/controllers/application_controller.rb app/controllers/concerns app/helpers + app/helpers/application_helper.rb app/mailers + app/mailers/application_mailer.rb app/models + app/models/application_record.rb app/models/concerns app/jobs + app/jobs/application_job.rb app/views/layouts + app/views/layouts/application.html.erb + app/views/layouts/mailer.html.erb + app/views/layouts/mailer.text.erb bin/bundle bin/rails bin/rake bin/setup + bin/update + bin/yarn + config/application.rb + config/boot.rb + config/cable.yml + config/environment.rb config/environments + config/environments/development.rb + config/environments/production.rb + config/environments/test.rb config/initializers + config/initializers/application_controller_renderer.rb + config/initializers/assets.rb + config/initializers/backtrace_silencers.rb + config/initializers/cookies_serializer.rb + config/initializers/filter_parameter_logging.rb + config/initializers/inflections.rb + config/initializers/mime_types.rb + config/initializers/wrap_parameters.rb config/locales - config/cable.yml + config/locales/en.yml config/puma.rb + config/routes.rb + config/secrets.yml config/spring.rb db + db/seeds.rb lib lib/tasks lib/assets log + package.json + public + test/application_system_test_case.rb test/test_helper.rb test/fixtures test/fixtures/files diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index e382a7a873..0379394f31 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -1341,6 +1341,92 @@ YAML assert_equal "/foo/bukkits/bukkit", last_response.body end + test "isolated engine can be mounted under multiple static locations" do + app_file "app/controllers/foos_controller.rb", <<-RUBY + class FoosController < ApplicationController + def through_fruits + render plain: fruit_bukkits.posts_path + end + + def through_vegetables + render plain: vegetable_bukkits.posts_path + end + end + RUBY + + app_file "config/routes.rb", <<-RUBY + Rails.application.routes.draw do + scope "/fruits" do + mount Bukkits::Engine => "/bukkits", as: :fruit_bukkits + end + + scope "/vegetables" do + mount Bukkits::Engine => "/bukkits", as: :vegetable_bukkits + end + + get "/through_fruits" => "foos#through_fruits" + get "/through_vegetables" => "foos#through_vegetables" + end + RUBY + + @plugin.write "config/routes.rb", <<-RUBY + Bukkits::Engine.routes.draw do + resources :posts, only: :index + end + RUBY + + boot_rails + + get("/through_fruits") + assert_equal "/fruits/bukkits/posts", last_response.body + + get("/through_vegetables") + assert_equal "/vegetables/bukkits/posts", last_response.body + end + + test "isolated engine can be mounted under multiple dynamic locations" do + app_file "app/controllers/foos_controller.rb", <<-RUBY + class FoosController < ApplicationController + def through_fruits + render plain: fruit_bukkits.posts_path(fruit_id: 1) + end + + def through_vegetables + render plain: vegetable_bukkits.posts_path(vegetable_id: 1) + end + end + RUBY + + app_file "config/routes.rb", <<-RUBY + Rails.application.routes.draw do + resources :fruits do + mount Bukkits::Engine => "/bukkits" + end + + resources :vegetables do + mount Bukkits::Engine => "/bukkits" + end + + get "/through_fruits" => "foos#through_fruits" + get "/through_vegetables" => "foos#through_vegetables" + end + RUBY + + @plugin.write "config/routes.rb", <<-RUBY + Bukkits::Engine.routes.draw do + resources :posts, only: :index + end + RUBY + + boot_rails + + get("/through_fruits") + assert_equal "/fruits/1/bukkits/posts", last_response.body + + get("/through_vegetables") + assert_equal "/vegetables/1/bukkits/posts", last_response.body + end + private def app Rails.application diff --git a/railties/test/secrets_test.rb b/railties/test/secrets_test.rb index 36c8ef1fd9..744d831406 100644 --- a/railties/test/secrets_test.rb +++ b/railties/test/secrets_test.rb @@ -111,6 +111,58 @@ class Rails::SecretsTest < ActiveSupport::TestCase end end + test "do not update secrets.yml.enc when secretes do not change" do + run_secrets_generator do + Dir.chdir(app_path) do + Rails::Secrets.read_for_editing do |tmp_path| + File.write(tmp_path, "Empty streets, empty nights. The Downtown Lights.") + end + + FileUtils.cp("config/secrets.yml.enc", "config/secrets.yml.enc.bk") + + Rails::Secrets.read_for_editing do |tmp_path| + File.write(tmp_path, "Empty streets, empty nights. The Downtown Lights.") + end + + assert_equal File.read("config/secrets.yml.enc.bk"), File.read("config/secrets.yml.enc") + end + end + end + + test "can read secrets written in binary" do + run_secrets_generator do + secrets = <<-end_of_secrets + production: + api_key: 00112233445566778899aabbccddeeff… + end_of_secrets + + Rails::Secrets.write(secrets.force_encoding(Encoding::ASCII_8BIT)) + + Rails::Secrets.read_for_editing do |tmp_path| + assert_match(/production:\n\s*api_key: 00112233445566778899aabbccddeeff…\n/, File.read(tmp_path)) + end + + assert_equal "00112233445566778899aabbccddeeff…\n", `bin/rails runner -e production "puts Rails.application.secrets.api_key"` + end + end + + test "can read secrets written in non-binary" do + run_secrets_generator do + secrets = <<-end_of_secrets + production: + api_key: 00112233445566778899aabbccddeeff… + end_of_secrets + + Rails::Secrets.write(secrets) + + Rails::Secrets.read_for_editing do |tmp_path| + assert_equal(secrets.force_encoding(Encoding::ASCII_8BIT), IO.binread(tmp_path)) + end + + assert_equal "00112233445566778899aabbccddeeff…\n", `bin/rails runner -e production "puts Rails.application.secrets.api_key"` + end + end + private def run_secrets_generator Dir.chdir(app_path) do |