diff options
41 files changed, 270 insertions, 109 deletions
diff --git a/.travis.yml b/.travis.yml index 8bebd3f484..585791f757 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,7 @@ env: matrix: - "GEM=railties" - "GEM=ap" - - "GEM=ac" + - "GEM=ac TESTOPTS=-vs26" - "GEM=ac:integration" - "GEM=am,amo,as,av,aj" - "GEM=as PRESERVE_TIMEZONES=1" @@ -44,7 +44,7 @@ end # Active Support. gem "dalli", ">= 2.2.1" -gem "listen", "~> 3.0.5", require: false +gem "listen", ">= 3.0.5", "< 3.2", require: false # Active Job. group :job do diff --git a/Gemfile.lock b/Gemfile.lock index 46a50ef39e..14635a8cb2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,10 +1,10 @@ GIT remote: https://github.com/QueueClassic/queue_classic.git - revision: 1ef197b9db8149a895e59077badcb5b94d4c8b44 + revision: 51d56ca6fa2fdf1eeffdffd702ae1cc0940b5156 branch: master specs: queue_classic (3.2.0.RC1) - pg (>= 0.17, < 0.19) + pg (>= 0.17, < 0.20) GIT remote: https://github.com/collectiveidea/delayed_job.git @@ -31,7 +31,7 @@ GIT GIT remote: https://github.com/resque/resque.git - revision: a3a66389618b830de0e6acf862b0dc9fde05cf49 + revision: 20d885065ac19e7f7d7a982f4ed1296083db0300 specs: resque (1.27.0) mono_logger (~> 1.0) @@ -112,8 +112,9 @@ GEM addressable (2.4.0) amq-protocol (2.0.1) arel (7.1.2) - backburner (1.3.0) + backburner (1.3.1) beaneater (~> 1.0) + concurrent-ruby (~> 1.0.1) dante (> 0.1.5) bcrypt (3.1.11) bcrypt (3.1.11-x64-mingw32) @@ -141,7 +142,7 @@ GEM builder (3.2.2) bunny (2.2.2) amq-protocol (>= 2.0.1) - byebug (9.0.5) + byebug (9.0.6) childprocess (0.5.9) ffi (~> 1.0, >= 1.0.11) coffee-rails (4.2.1) @@ -177,7 +178,7 @@ GEM execjs (2.7.0) faraday (0.9.2) multipart-post (>= 1.2, < 3) - faye (1.1.1) + faye (1.2.2) cookiejar (>= 0.3.0) em-http-request (>= 0.3.0) eventmachine (>= 0.12.0) @@ -204,9 +205,10 @@ GEM kindlerb (0.1.1) mustache nokogiri - listen (3.0.8) + listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) + ruby_dep (~> 1.2) loofah (2.0.3) nokogiri (>= 1.5.9) mail (2.6.4) @@ -237,9 +239,9 @@ GEM nokogiri (1.6.8-x86-mingw32) mini_portile2 (~> 2.1.0) pkg-config (~> 1.1.7) - pg (0.18.4) - pg (0.18.4-x64-mingw32) - pg (0.18.4-x86-mingw32) + pg (0.19.0) + pg (0.19.0-x64-mingw32) + pg (0.19.0-x86-mingw32) pkg-config (1.1.7) psych (2.1.1) puma (3.6.0) @@ -263,7 +265,7 @@ GEM nokogiri (~> 1.6.0) rails-html-sanitizer (1.0.3) loofah (~> 2.0) - rake (11.2.2) + rake (11.3.0) rb-fsevent (0.9.7) rdoc (4.2.2) json (~> 1.4) @@ -276,6 +278,7 @@ GEM redis (~> 3.3) resque (~> 1.26) rufus-scheduler (~> 3.2) + ruby_dep (1.4.0) rubyzip (1.2.0) rufus-scheduler (3.2.2) sass-rails (5.0.6) @@ -291,10 +294,10 @@ GEM childprocess (~> 0.5) rubyzip (~> 1.0) websocket (~> 1.0) - sequel (4.38.0) + sequel (4.39.0) serverengine (1.5.11) sigdump (~> 0.2.2) - sidekiq (4.2.0) + sidekiq (4.2.2) concurrent-ruby (~> 1.0) connection_pool (~> 2.2, >= 2.2.0) rack-protection (~> 1.5) @@ -319,7 +322,7 @@ GEM sqlite3 (1.3.11) sqlite3 (1.3.11-x64-mingw32) sqlite3 (1.3.11-x86-mingw32) - stackprof (0.2.9) + stackprof (0.2.10) sucker_punch (2.0.2) concurrent-ruby (~> 1.0.0) thin (1.7.0) @@ -335,7 +338,7 @@ GEM turbolinks-source (5.0.0) tzinfo (1.2.2) thread_safe (~> 0.1) - tzinfo-data (1.2016.6) + tzinfo-data (1.2016.7) tzinfo (>= 1.0.0) uglifier (3.0.2) execjs (>= 0.3.0, < 3) @@ -377,7 +380,7 @@ DEPENDENCIES hiredis jquery-rails kindlerb (= 0.1.1) - listen (~> 3.0.5) + listen (>= 3.0.5, < 3.2) minitest (< 5.3.4) mocha (~> 0.14) mysql2 (>= 0.4.4) @@ -414,4 +417,4 @@ DEPENDENCIES websocket-client-simple BUNDLED WITH - 1.13.1 + 1.13.2 diff --git a/actioncable/README.md b/actioncable/README.md index 28e2602cbf..a0b7412dd4 100644 --- a/actioncable/README.md +++ b/actioncable/README.md @@ -167,7 +167,7 @@ App.cable.subscriptions.create "AppearanceChannel", buttonSelector = "[data-behavior~=appear_away]" install: -> - $(document).on "page:change.appearance", => + $(document).on "turbolinks:load.appearance", => @appear() $(document).on "click.appearance", buttonSelector, => diff --git a/actioncable/lib/action_cable/server/base.rb b/actioncable/lib/action_cable/server/base.rb index 67ada7cc2e..419eccd73c 100644 --- a/actioncable/lib/action_cable/server/base.rb +++ b/actioncable/lib/action_cable/server/base.rb @@ -37,9 +37,13 @@ module ActionCable connections.each(&:close) @mutex.synchronize do - worker_pool.halt if @worker_pool - + # Shutdown the worker pool + @worker_pool.halt if @worker_pool @worker_pool = nil + + # Shutdown the pub/sub adapter + @pubsub.shutdown if @pubsub + @pubsub = nil end end diff --git a/actioncable/lib/action_cable/server/worker.rb b/actioncable/lib/action_cable/server/worker.rb index 7460472551..43639c27af 100644 --- a/actioncable/lib/action_cable/server/worker.rb +++ b/actioncable/lib/action_cable/server/worker.rb @@ -25,7 +25,7 @@ module ActionCable # Stop processing work: any work that has not already started # running will be discarded from the queue def halt - @executor.kill + @executor.shutdown end def stopping? diff --git a/actioncable/test/server/base_test.rb b/actioncable/test/server/base_test.rb new file mode 100644 index 0000000000..f0a51c5a7d --- /dev/null +++ b/actioncable/test/server/base_test.rb @@ -0,0 +1,33 @@ +require "test_helper" +require "stubs/test_server" +require "active_support/core_ext/hash/indifferent_access" + +class BaseTest < ActiveSupport::TestCase + def setup + @server = ActionCable::Server::Base.new + @server.config.cable = { adapter: "async" }.with_indifferent_access + end + + class FakeConnection + def close + end + end + + test "#restart closes all open connections" do + conn = FakeConnection.new + @server.add_connection(conn) + + conn.expects(:close) + @server.restart + end + + test "#restart shuts down worker pool" do + @server.worker_pool.expects(:halt) + @server.restart + end + + test "#restart shuts down pub/sub adapter" do + @server.pubsub.expects(:shutdown) + @server.restart + end +end diff --git a/actioncable/test/subscription_adapter/common.rb b/actioncable/test/subscription_adapter/common.rb index 8cf0b5c684..3aa88c2caa 100644 --- a/actioncable/test/subscription_adapter/common.rb +++ b/actioncable/test/subscription_adapter/common.rb @@ -20,7 +20,7 @@ module CommonSubscriptionAdapterTest end def teardown - [@rx_adapter, @tx_adapter].uniq.each(&:shutdown) + [@rx_adapter, @tx_adapter].uniq.compact.each(&:shutdown) end def subscribe_as_queue(channel, adapter = @rx_adapter) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index e7b8e1b628..5ffbc2ea5d 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,10 @@ +* Show an "unmatched constraints" error when params fail to match constraints + on a matched route, rather than a "missing keys" error. + + Fixes #26470. + + *Chris Carter* + * Fix adding implicitly rendered template digests to ETags. Fixes a case when modifying an implicitly rendered template for a diff --git a/actionpack/lib/action_dispatch/journey/formatter.rb b/actionpack/lib/action_dispatch/journey/formatter.rb index a289c34e8b..dc8b24b089 100644 --- a/actionpack/lib/action_dispatch/journey/formatter.rb +++ b/actionpack/lib/action_dispatch/journey/formatter.rb @@ -44,8 +44,12 @@ module ActionDispatch return [route.format(parameterized_parts), params] end + 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 << " missing required keys: #{missing_keys.sort.inspect}" if missing_keys && !missing_keys.empty? + 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? raise ActionController::UrlGenerationError, message end diff --git a/actionpack/lib/action_dispatch/middleware/request_id.rb b/actionpack/lib/action_dispatch/middleware/request_id.rb index bd4c781267..1925ffd9dd 100644 --- a/actionpack/lib/action_dispatch/middleware/request_id.rb +++ b/actionpack/lib/action_dispatch/middleware/request_id.rb @@ -2,8 +2,9 @@ require "securerandom" require "active_support/core_ext/string/access" module ActionDispatch - # Makes a unique request id available to the action_dispatch.request_id env variable (which is then accessible through - # ActionDispatch::Request#uuid or the alias ActionDispatch::Request#request_id) and sends the same id to the client via the X-Request-Id header. + # Makes a unique request id available to the +action_dispatch.request_id+ env variable (which is then accessible + # through <tt>ActionDispatch::Request#request_id</tt> or the alias <tt>ActionDispatch::Request#uuid</tt>) and sends + # the same id to the client via the X-Request-Id header. # # The unique request id is either based on the X-Request-Id header in the request, which would typically be generated # by a firewall, load balancer, or the web server, or, if this header is not available, a random uuid. If the @@ -12,7 +13,7 @@ module ActionDispatch # The unique request id can be used to trace a request end-to-end and would typically end up being part of log files # from multiple pieces of the stack. class RequestId - X_REQUEST_ID = "X-Request-Id".freeze # :nodoc: + X_REQUEST_ID = "X-Request-Id".freeze #:nodoc: def initialize(app) @app = app diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 5abf59402d..a1bc357c8b 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -210,7 +210,7 @@ module ActionDispatch } constraints = Hash[@route.requirements.merge(params).sort_by { |k,v| k.to_s }] message = "No route matches #{constraints.inspect}" - message << " missing required keys: #{missing_keys.sort.inspect}" + message << ", missing required keys: #{missing_keys.sort.inspect}" raise ActionController::UrlGenerationError, message end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 6ba52e37b6..9b6e060955 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -4684,22 +4684,25 @@ class TestUrlGenerationErrors < ActionDispatch::IntegrationTest include Routes.url_helpers - test "url helpers raise a helpful error message when generation fails" do + test "url helpers raise a 'missing keys' error for a nil param with optimized helpers" do url, missing = { action: "show", controller: "products", id: nil }, [:id] - message = "No route matches #{url.inspect} missing required keys: #{missing.inspect}" + message = "No route matches #{url.inspect}, missing required keys: #{missing.inspect}" - # Optimized url helper error = assert_raises(ActionController::UrlGenerationError) { product_path(nil) } assert_equal message, error.message + end + + test "url helpers raise a 'constraint failure' error for a nil param with non-optimized helpers" do + url, missing = { action: "show", controller: "products", id: nil }, [:id] + message = "No route matches #{url.inspect}, possible unmatched constraints: #{missing.inspect}" - # Non-optimized url helper error = assert_raises(ActionController::UrlGenerationError, message) { product_path(id: nil) } assert_equal message, error.message end - test "url helpers raise message with mixed parameters when generation fails " do + test "url helpers raise message with mixed parameters when generation fails" do url, missing = { action: "show", controller: "products", id: nil, "id"=>"url-tested" }, [:id] - message = "No route matches #{url.inspect} missing required keys: #{missing.inspect}" + message = "No route matches #{url.inspect}, possible unmatched constraints: #{missing.inspect}" # Optimized url helper error = assert_raises(ActionController::UrlGenerationError) { product_path(nil, "id"=>"url-tested") } diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb index 2b99637f56..7b5916eb72 100644 --- a/actionpack/test/journey/router_test.rb +++ b/actionpack/test/journey/router_test.rb @@ -297,7 +297,7 @@ module ActionDispatch } request_parameters = primarty_parameters.merge(redirection_parameters).merge(missing_parameters) - message = "No route matches #{Hash[request_parameters.sort_by { |k,v|k.to_s }].inspect} missing required keys: #{[missing_key.to_sym].inspect}" + message = "No route matches #{Hash[request_parameters.sort_by { |k,v|k.to_s }].inspect}, missing required keys: #{[missing_key.to_sym].inspect}" error = assert_raises(ActionController::UrlGenerationError) do @formatter.generate( diff --git a/actionview/lib/action_view/digestor.rb b/actionview/lib/action_view/digestor.rb index 2d6ad8f6d9..0658d8601d 100644 --- a/actionview/lib/action_view/digestor.rb +++ b/actionview/lib/action_view/digestor.rb @@ -6,6 +6,12 @@ module ActionView class Digestor @@digest_mutex = Mutex.new + module PerExecutionDigestCacheExpiry + def self.before(target) + ActionView::LookupContext::DetailsKey.clear + end + end + class << self # Supported options: # diff --git a/actionview/lib/action_view/railtie.rb b/actionview/lib/action_view/railtie.rb index dfb99f4ea9..42795ca2c7 100644 --- a/actionview/lib/action_view/railtie.rb +++ b/actionview/lib/action_view/railtie.rb @@ -40,7 +40,7 @@ module ActionView initializer "action_view.per_request_digest_cache" do |app| ActiveSupport.on_load(:action_view) do if app.config.consider_all_requests_local - app.executor.to_run { ActionView::LookupContext::DetailsKey.clear } + app.executor.to_run ActionView::Digestor::PerExecutionDigestCacheExpiry end end end diff --git a/activemodel/lib/active_model/type/float.rb b/activemodel/lib/active_model/type/float.rb index 94bb7e700c..4d0d2771a0 100644 --- a/activemodel/lib/active_model/type/float.rb +++ b/activemodel/lib/active_model/type/float.rb @@ -7,6 +7,15 @@ module ActiveModel :float end + def type_cast_for_schema(value) + return "::Float::NAN" if value.try(:nan?) + case value + when ::Float::INFINITY then "::Float::INFINITY" + when -::Float::INFINITY then "-::Float::INFINITY" + else super + end + end + alias serialize cast private diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 4d0c1a4178..879c4a87cf 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,7 @@ +* Made ActiveRecord consistently use `ActiveRecord::Type` (not `ActiveModel::Type`) + + *Iain Beeston* + * Serialize JSON attribute value `nil` as SQL `NULL`, not JSON `null` *Trung Duc Tran* diff --git a/activerecord/lib/active_record/attribute_methods/query.rb b/activerecord/lib/active_record/attribute_methods/query.rb index 10498f4322..05f0e974b6 100644 --- a/activerecord/lib/active_record/attribute_methods/query.rb +++ b/activerecord/lib/active_record/attribute_methods/query.rb @@ -19,7 +19,7 @@ module ActiveRecord if Numeric === value || value !~ /[^0-9]/ !value.to_i.zero? else - return false if ActiveModel::Type::Boolean::FALSE_VALUES.include?(value) + return false if ActiveRecord::Type::Boolean::FALSE_VALUES.include?(value) !value.blank? end elsif value.respond_to?(:zero?) diff --git a/activerecord/lib/active_record/integration.rb b/activerecord/lib/active_record/integration.rb index e4c7a55541..3c54c6048d 100644 --- a/activerecord/lib/active_record/integration.rb +++ b/activerecord/lib/active_record/integration.rb @@ -53,18 +53,21 @@ module ActiveRecord # # Person.find(5).cache_key(:updated_at, :last_reviewed_at) def cache_key(*timestamp_names) - case - when new_record? + if new_record? "#{model_name.cache_key}/new" - when timestamp_names.any? - timestamp = max_updated_column_timestamp(timestamp_names) - timestamp = timestamp.utc.to_s(cache_timestamp_format) - "#{model_name.cache_key}/#{id}-#{timestamp}" - when timestamp = max_updated_column_timestamp - timestamp = timestamp.utc.to_s(cache_timestamp_format) - "#{model_name.cache_key}/#{id}-#{timestamp}" else - "#{model_name.cache_key}/#{id}" + timestamp = if timestamp_names.any? + max_updated_column_timestamp(timestamp_names) + else + max_updated_column_timestamp + end + + if timestamp + timestamp = timestamp.utc.to_s(cache_timestamp_format) + "#{model_name.cache_key}/#{id}-#{timestamp}" + else + "#{model_name.cache_key}/#{id}" + end end end diff --git a/activerecord/lib/active_record/query_cache.rb b/activerecord/lib/active_record/query_cache.rb index 387dd8e9bd..c45c8c1697 100644 --- a/activerecord/lib/active_record/query_cache.rb +++ b/activerecord/lib/active_record/query_cache.rb @@ -34,16 +34,14 @@ module ActiveRecord def self.complete(enabled) ActiveRecord::Base.connection.clear_query_cache ActiveRecord::Base.connection.disable_query_cache! unless enabled + + unless ActiveRecord::Base.connected? && ActiveRecord::Base.connection.transaction_open? + ActiveRecord::Base.clear_active_connections! + end end def self.install_executor_hooks(executor = ActiveSupport::Executor) executor.register_hook(self) - - executor.to_complete do - unless ActiveRecord::Base.connected? && ActiveRecord::Base.connection.transaction_open? - ActiveRecord::Base.clear_active_connections! - end - end end end end diff --git a/activerecord/lib/active_record/type.rb b/activerecord/lib/active_record/type.rb index 0b48d2186a..84373dddf2 100644 --- a/activerecord/lib/active_record/type.rb +++ b/activerecord/lib/active_record/type.rb @@ -1,4 +1,6 @@ require "active_model/type" +require "active_record/type/helpers" +require "active_record/type/value" require "active_record/type/internal/abstract_json" require "active_record/type/internal/timezone" @@ -48,7 +50,6 @@ module ActiveRecord end end - Helpers = ActiveModel::Type::Helpers BigInteger = ActiveModel::Type::BigInteger Binary = ActiveModel::Type::Binary Boolean = ActiveModel::Type::Boolean @@ -59,7 +60,6 @@ module ActiveRecord String = ActiveModel::Type::String Text = ActiveModel::Type::Text UnsignedInteger = ActiveModel::Type::UnsignedInteger - Value = ActiveModel::Type::Value register(:big_integer, Type::BigInteger, override: false) register(:binary, Type::Binary, override: false) diff --git a/activerecord/lib/active_record/type/helpers.rb b/activerecord/lib/active_record/type/helpers.rb new file mode 100644 index 0000000000..a32ccd4bc3 --- /dev/null +++ b/activerecord/lib/active_record/type/helpers.rb @@ -0,0 +1,5 @@ +module ActiveRecord + module Type + Helpers = ActiveModel::Type::Helpers + end +end diff --git a/activerecord/lib/active_record/type/internal/abstract_json.rb b/activerecord/lib/active_record/type/internal/abstract_json.rb index e19c5a14da..67028546e4 100644 --- a/activerecord/lib/active_record/type/internal/abstract_json.rb +++ b/activerecord/lib/active_record/type/internal/abstract_json.rb @@ -1,8 +1,8 @@ module ActiveRecord module Type module Internal # :nodoc: - class AbstractJson < ActiveModel::Type::Value # :nodoc: - include ActiveModel::Type::Helpers::Mutable + class AbstractJson < Type::Value # :nodoc: + include Type::Helpers::Mutable def type :json diff --git a/activerecord/lib/active_record/type/serialized.rb b/activerecord/lib/active_record/type/serialized.rb index ac9134bfcb..ca12c83b1a 100644 --- a/activerecord/lib/active_record/type/serialized.rb +++ b/activerecord/lib/active_record/type/serialized.rb @@ -1,7 +1,7 @@ module ActiveRecord module Type - class Serialized < DelegateClass(ActiveModel::Type::Value) # :nodoc: - include ActiveModel::Type::Helpers::Mutable + class Serialized < DelegateClass(Type::Value) # :nodoc: + include Type::Helpers::Mutable attr_reader :subtype, :coder diff --git a/activerecord/lib/active_record/type/value.rb b/activerecord/lib/active_record/type/value.rb new file mode 100644 index 0000000000..89ef29106b --- /dev/null +++ b/activerecord/lib/active_record/type/value.rb @@ -0,0 +1,5 @@ +module ActiveRecord + module Type + class Value < ActiveModel::Type::Value; end + end +end diff --git a/activerecord/test/cases/integration_test.rb b/activerecord/test/cases/integration_test.rb index 766917b196..00457965d7 100644 --- a/activerecord/test/cases/integration_test.rb +++ b/activerecord/test/cases/integration_test.rb @@ -172,4 +172,10 @@ class IntegrationTest < ActiveRecord::TestCase owner = owners(:blackbeard) assert_equal "owners/#{owner.id}-#{owner.happy_at.utc.to_s(:usec)}", owner.cache_key(:updated_at, :happy_at) end + + def test_cache_key_when_named_timestamp_is_nil + owner = owners(:blackbeard) + owner.happy_at = nil + assert_equal "owners/#{owner.id}", owner.cache_key(:happy_at) + end end diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb index 57b1bc889a..8b604ba930 100644 --- a/activerecord/test/cases/schema_dumper_test.rb +++ b/activerecord/test/cases/schema_dumper_test.rb @@ -423,6 +423,13 @@ class SchemaDumperDefaultsTest < ActiveRecord::TestCase t.datetime :datetime_with_default, default: "2014-06-05 07:17:04" t.time :time_with_default, default: "07:17:04" end + + if current_adapter?(:PostgreSQLAdapter) + @connection.create_table :infinity_defaults, force: true do |t| + t.float :float_with_inf_default, default: Float::INFINITY + t.float :float_with_nan_default, default: Float::NAN + end + end end teardown do @@ -438,4 +445,11 @@ class SchemaDumperDefaultsTest < ActiveRecord::TestCase assert_match %r{t\.datetime\s+"datetime_with_default",\s+default: '2014-06-05 07:17:04'}, output assert_match %r{t\.time\s+"time_with_default",\s+default: '2000-01-01 07:17:04'}, output end + + def test_schema_dump_with_float_column_infinity_default + skip unless current_adapter?(:PostgreSQLAdapter) + output = dump_table_schema('infinity_defaults') + assert_match %r{t\.float\s+"float_with_inf_default",\s+default: ::Float::INFINITY}, output + assert_match %r{t\.float\s+"float_with_nan_default",\s+default: ::Float::NAN}, output + end end diff --git a/activerecord/test/cases/serialized_attribute_test.rb b/activerecord/test/cases/serialized_attribute_test.rb index bebd856faf..8e9514de7c 100644 --- a/activerecord/test/cases/serialized_attribute_test.rb +++ b/activerecord/test/cases/serialized_attribute_test.rb @@ -313,8 +313,8 @@ class SerializedAttributeTest < ActiveRecord::TestCase return if value.nil? value.gsub(" encoded", "") end - type = Class.new(ActiveModel::Type::Value) do - include ActiveModel::Type::Helpers::Mutable + type = Class.new(ActiveRecord::Type::Value) do + include ActiveRecord::Type::Helpers::Mutable def serialize(value) return if value.nil? diff --git a/activerecord/test/cases/type/date_time_test.rb b/activerecord/test/cases/type/date_time_test.rb index bc4900e1c2..6848619ece 100644 --- a/activerecord/test/cases/type/date_time_test.rb +++ b/activerecord/test/cases/type/date_time_test.rb @@ -3,7 +3,7 @@ require "models/task" module ActiveRecord module Type - class IntegerTest < ActiveRecord::TestCase + class DateTimeTest < ActiveRecord::TestCase def test_datetime_seconds_precision_applied_to_timestamp skip "This test is invalid if subsecond precision isn't supported" unless subsecond_precision_supported? p = Task.create!(starting: ::Time.now) diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 499310975e..f840783059 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,25 +1,3 @@ -* Fix `ActiveSupport::TimeWithZone#localtime` when called with different - `utc_offset` values. - - Previously memoization in `localtime` wasn't taking the `utc_offset` - parameter into account when returning a cached value. It now caches the - computed value depending on the `utc_offset` parameter, e.g: - - Time.zone = "US/Eastern" - - t = Time.zone.local(2016,5,2,11) - # => Mon, 02 May 2016 11:00:00 EDT -04:00 - - t.localtime(-7200) - # => 2016-05-02 13:00:00 -0200 - - t.localtime(-3600) - # => 2016-05-02 14:00:00 -0100 - - Fixes #26644. - - *Thomas Balthazar* - * Fix `ActiveSupport::TimeWithZone#in` across DST boundaries. Previously calls to `in` were being sent to the non-DST aware 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 3f4e236ab7..db95ae0db5 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 @@ -12,7 +12,11 @@ module DateAndTime mattr_accessor(:preserve_timezone, instance_writer: false) { false } def to_time - preserve_timezone ? getlocal(utc_offset) : getlocal + if preserve_timezone + @_to_time_with_instance_offset ||= getlocal(utc_offset) + else + @_to_time_with_system_offset ||= getlocal + end end end end diff --git a/activesupport/lib/active_support/deprecation/instance_delegator.rb b/activesupport/lib/active_support/deprecation/instance_delegator.rb index 8efa6aabdc..6d390f3b37 100644 --- a/activesupport/lib/active_support/deprecation/instance_delegator.rb +++ b/activesupport/lib/active_support/deprecation/instance_delegator.rb @@ -6,6 +6,7 @@ module ActiveSupport module InstanceDelegator # :nodoc: def self.included(base) base.extend(ClassMethods) + base.singleton_class.prepend(OverrideDelegators) base.public_class_method :new end @@ -19,6 +20,18 @@ module ActiveSupport singleton_class.delegate(method_name, to: :instance) end end + + module OverrideDelegators # :nodoc: + def warn(message = nil, callstack = nil) + callstack ||= caller_locations(2) + super + end + + def deprecation_warning(deprecated_method_name, message = nil, caller_backtrace = nil) + caller_backtrace ||= caller_locations(2) + super + end + end end end end diff --git a/activesupport/lib/active_support/execution_wrapper.rb b/activesupport/lib/active_support/execution_wrapper.rb index 4c8b03c9df..3384d12d5b 100644 --- a/activesupport/lib/active_support/execution_wrapper.rb +++ b/activesupport/lib/active_support/execution_wrapper.rb @@ -19,6 +19,23 @@ module ActiveSupport set_callback(:complete, *args, &block) end + class RunHook < Struct.new(:hook) # :nodoc: + def before(target) + hook_state = target.send(:hook_state) + hook_state[hook] = hook.run + end + end + + class CompleteHook < Struct.new(:hook) # :nodoc: + def before(target) + hook_state = target.send(:hook_state) + if hook_state.key?(hook) + hook.complete hook_state[hook] + end + end + alias after before + end + # Register an object to be invoked during both the +run+ and # +complete+ steps. # @@ -29,19 +46,11 @@ module ActiveSupport # invoked in that situation.) def self.register_hook(hook, outer: false) if outer - run_args = [prepend: true] - complete_args = [:after] + to_run RunHook.new(hook), prepend: true + to_complete :after, CompleteHook.new(hook) else - run_args = complete_args = [] - end - - to_run(*run_args) do - hook_state[hook] = hook.run - end - to_complete(*complete_args) do - if hook_state.key?(hook) - hook.complete hook_state[hook] - end + to_run RunHook.new(hook) + to_complete CompleteHook.new(hook) end end diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index acea38176f..889f71c4f3 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -80,8 +80,7 @@ module ActiveSupport # Returns a <tt>Time</tt> instance of the simultaneous time in the system timezone. def localtime(utc_offset = nil) - @localtime ||= {} - @localtime[utc_offset] ||= utc.getlocal(utc_offset) + utc.getlocal(utc_offset) end alias_method :getlocal, :localtime diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 5c940da1e3..e35aa6e154 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -54,12 +54,6 @@ class TimeWithZoneTest < ActiveSupport::TestCase assert_instance_of Time, @dt_twz.localtime end - def test_localtime_with_offset - assert_equal 0, @twz.localtime.gmt_offset - assert_equal (-3600), @twz.localtime(-3600).gmt_offset - assert_equal (-7200), @twz.localtime(-7200).gmt_offset - end - def test_utc? assert_equal false, @twz.utc? diff --git a/activesupport/test/executor_test.rb b/activesupport/test/executor_test.rb index 0b56ea008f..d409216206 100644 --- a/activesupport/test/executor_test.rb +++ b/activesupport/test/executor_test.rb @@ -158,6 +158,61 @@ class ExecutorTest < ActiveSupport::TestCase assert_equal :some_state, supplied_state end + def test_hook_insertion_order + invoked = [] + supplied_state = [] + + hook_class = Class.new do + attr_accessor :letter + + define_method(:initialize) do |letter| + self.letter = letter + end + + define_method(:run) do + invoked << :"run_#{letter}" + :"state_#{letter}" + end + + define_method(:complete) do |state| + invoked << :"complete_#{letter}" + supplied_state << state + end + end + + executor.register_hook(hook_class.new(:a)) + executor.register_hook(hook_class.new(:b)) + executor.register_hook(hook_class.new(:c), outer: true) + executor.register_hook(hook_class.new(:d)) + + executor.wrap {} + + assert_equal [:run_c, :run_a, :run_b, :run_d, :complete_a, :complete_b, :complete_d, :complete_c], invoked + assert_equal [:state_a, :state_b, :state_d, :state_c], supplied_state + end + + def test_class_serial_is_unaffected + hook = Class.new do + define_method(:run) do + nil + end + + define_method(:complete) do |state| + nil + end + end.new + + executor.register_hook(hook) + + before = RubyVM.stat(:class_serial) + executor.wrap {} + executor.wrap {} + executor.wrap {} + after = RubyVM.stat(:class_serial) + + assert_equal before, after + end + def test_separate_classes_can_wrap other_executor = Class.new(ActiveSupport::Executor) diff --git a/guides/source/action_cable_overview.md b/guides/source/action_cable_overview.md index 4b9a22101a..a66a8ff484 100644 --- a/guides/source/action_cable_overview.md +++ b/guides/source/action_cable_overview.md @@ -422,7 +422,7 @@ App.cable.subscriptions.create "AppearanceChannel", buttonSelector = "[data-behavior~=appear_away]" install: -> - $(document).on "page:change.appearance", => + $(document).on "turbolinks:load.appearance", => @appear() $(document).on "click.appearance", buttonSelector, => diff --git a/guides/source/configuring.md b/guides/source/configuring.md index fbf3c27957..3df8a0ed26 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -1296,7 +1296,7 @@ evented file system monitor to detect changes when `config.cache_classes` is ```ruby group :development do - gem 'listen', '~> 3.0.4' + gem 'listen', '>= 3.0.5', '< 3.2' end ``` diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index b03c87e9ba..b488e4ed8e 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,7 @@ +* Allow the use of listen's 3.1.x branch + + *Esteban Santana Santana* + * Run `Minitest.after_run` hooks when running `rails test`. *Michael Grosser* diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 7af5fcd3c1..422217286c 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -39,7 +39,7 @@ group :development do <%- end -%> <%- end -%> <% if depend_on_listen? -%> - gem 'listen', '~> 3.0.5' + gem 'listen', '>= 3.0.5', '< 3.2' <% end -%> <% if spring_install? -%> # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring |