aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/compact.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/hash/transform_values.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/module/delegation.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/numeric/inquiry.rb2
-rw-r--r--activesupport/lib/active_support/evented_file_update_checker.rb24
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb34
-rw-r--r--activesupport/test/evented_file_update_checker_test.rb28
-rw-r--r--activesupport/test/time_travel_test.rb17
8 files changed, 77 insertions, 34 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/compact.rb b/activesupport/lib/active_support/core_ext/hash/compact.rb
index 28c8d86b9b..5cb858af5c 100644
--- a/activesupport/lib/active_support/core_ext/hash/compact.rb
+++ b/activesupport/lib/active_support/core_ext/hash/compact.rb
@@ -2,4 +2,4 @@
require "active_support/deprecation"
-ActiveSupport::Deprecation.warn "Ruby 2.4+ (required by Rails 6) provides Hash#compact and Hash#compact! natively, so requiring active_support/core_ext/hash/compact is no longer necessary. Requiring it will raise LoadError in Rails 6.1."
+ActiveSupport::Deprecation.warn "Ruby 2.5+ (required by Rails 6) provides Hash#compact and Hash#compact! natively, so requiring active_support/core_ext/hash/compact is no longer necessary. Requiring it will raise LoadError in Rails 6.1."
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 fc15130c9e..e4aeb0e891 100644
--- a/activesupport/lib/active_support/core_ext/hash/transform_values.rb
+++ b/activesupport/lib/active_support/core_ext/hash/transform_values.rb
@@ -2,4 +2,4 @@
require "active_support/deprecation"
-ActiveSupport::Deprecation.warn "Ruby 2.4+ (required by Rails 6) provides Hash#transform_values natively, so requiring active_support/core_ext/hash/transform_values is no longer necessary. Requiring it will raise LoadError in Rails 6.1."
+ActiveSupport::Deprecation.warn "Ruby 2.5+ (required by Rails 6) provides Hash#transform_values natively, so requiring active_support/core_ext/hash/transform_values is no longer necessary. Requiring it will raise LoadError in Rails 6.1."
diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb
index 3128539112..be90390ae4 100644
--- a/activesupport/lib/active_support/core_ext/module/delegation.rb
+++ b/activesupport/lib/active_support/core_ext/module/delegation.rb
@@ -19,7 +19,7 @@ class Module
# public methods as your own.
#
# ==== Options
- # * <tt>:to</tt> - Specifies the target object
+ # * <tt>:to</tt> - Specifies the target object name as a symbol or string
# * <tt>:prefix</tt> - Prefixes the new method with the target name or a custom prefix
# * <tt>:allow_nil</tt> - If set to true, prevents a +Module::DelegationError+
# from being raised
diff --git a/activesupport/lib/active_support/core_ext/numeric/inquiry.rb b/activesupport/lib/active_support/core_ext/numeric/inquiry.rb
index e05e40825b..6b5240d051 100644
--- a/activesupport/lib/active_support/core_ext/numeric/inquiry.rb
+++ b/activesupport/lib/active_support/core_ext/numeric/inquiry.rb
@@ -2,4 +2,4 @@
require "active_support/deprecation"
-ActiveSupport::Deprecation.warn "Ruby 2.4+ (required by Rails 6) provides Numeric#positive? and Numeric#negative? natively, so requiring active_support/core_ext/numeric/inquiry is no longer necessary. Requiring it will raise LoadError in Rails 6.1."
+ActiveSupport::Deprecation.warn "Ruby 2.5+ (required by Rails 6) provides Numeric#positive? and Numeric#negative? natively, so requiring active_support/core_ext/numeric/inquiry is no longer necessary. Requiring it will raise LoadError in Rails 6.1."
diff --git a/activesupport/lib/active_support/evented_file_update_checker.rb b/activesupport/lib/active_support/evented_file_update_checker.rb
index b2ae3dd274..54bc5c0ae5 100644
--- a/activesupport/lib/active_support/evented_file_update_checker.rb
+++ b/activesupport/lib/active_support/evented_file_update_checker.rb
@@ -52,7 +52,10 @@ module ActiveSupport
@pid = Process.pid
@boot_mutex = Mutex.new
- if (@dtw = directories_to_watch).any?
+ dtw = directories_to_watch
+ @dtw, @missing = dtw.partition(&:exist?)
+
+ if @dtw.any?
# Loading listen triggers warnings. These are originated by a legit
# usage of attr_* macros for private attributes, but adds a lot of noise
# to our test suite. Thus, we lazy load it and disable warnings locally.
@@ -73,6 +76,19 @@ module ActiveSupport
@updated.make_true
end
end
+
+ if @missing.any?(&:exist?)
+ @boot_mutex.synchronize do
+ appeared, @missing = @missing.partition(&:exist?)
+ shutdown!
+
+ @dtw += appeared
+ boot!
+
+ @updated.make_true
+ end
+ end
+
@updated.true?
end
@@ -94,6 +110,10 @@ module ActiveSupport
Listen.to(*@dtw, &method(:changed)).start
end
+ def shutdown!
+ Listen.stop
+ end
+
def changed(modified, added, removed)
unless updated?
@updated.make_true if (modified + added + removed).any? { |f| watching?(f) }
@@ -121,7 +141,7 @@ module ActiveSupport
end
def directories_to_watch
- dtw = (@files + @dirs.keys).map { |f| @ph.existing_parent(f) }
+ dtw = @files.map(&:dirname) + @dirs.keys
dtw.compact!
dtw.uniq!
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index afbc90f6d7..95fdcb8faf 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -310,30 +310,16 @@ class HashExtTest < ActiveSupport::TestCase
assert_equal expected, merged
end
- def test_slice
- original = { a: "x", b: "y", c: 10 }
- expected = { a: "x", b: "y" }
-
- # Should return a new hash with only the given keys.
- assert_equal expected, original.slice(:a, :b)
- assert_not_equal expected, original
- end
-
def test_slice_inplace
original = { a: "x", b: "y", c: 10 }
- expected = { c: 10 }
+ expected_return = { c: 10 }
+ expected_original = { a: "x", b: "y" }
- # Should replace the hash with only the given keys.
- assert_equal expected, original.slice!(:a, :b)
- end
+ # Should return a hash containing the removed key/value pairs.
+ assert_equal expected_return, original.slice!(:a, :b)
- def test_slice_with_an_array_key
- original = { :a => "x", :b => "y", :c => 10, [:a, :b] => "an array key" }
- expected = { [:a, :b] => "an array key", :c => 10 }
-
- # Should return a new hash with only the given keys when given an array key.
- assert_equal expected, original.slice([:a, :b], :c)
- assert_not_equal expected, original
+ # Should replace the hash with only the given keys.
+ assert_equal expected_original, original
end
def test_slice_inplace_with_an_array_key
@@ -344,14 +330,6 @@ class HashExtTest < ActiveSupport::TestCase
assert_equal expected, original.slice!([:a, :b], :c)
end
- def test_slice_with_splatted_keys
- original = { :a => "x", :b => "y", :c => 10, [:a, :b] => "an array key" }
- expected = { a: "x", b: "y" }
-
- # Should grab each of the splatted keys.
- assert_equal expected, original.slice(*[:a, :b])
- end
-
def test_slice_bang_does_not_override_default
hash = Hash.new(0)
hash.update(a: 1, b: 2)
diff --git a/activesupport/test/evented_file_update_checker_test.rb b/activesupport/test/evented_file_update_checker_test.rb
index a557608986..b2d5eb94c2 100644
--- a/activesupport/test/evented_file_update_checker_test.rb
+++ b/activesupport/test/evented_file_update_checker_test.rb
@@ -76,6 +76,34 @@ class EventedFileUpdateCheckerTest < ActiveSupport::TestCase
Process.wait(pid)
end
+
+ test "updated should become true when nonexistent directory is added later" do
+ Dir.mktmpdir do |dir|
+ watched_dir = File.join(dir, "app")
+ unwatched_dir = File.join(dir, "node_modules")
+ not_exist_watched_dir = File.join(dir, "test")
+
+ Dir.mkdir(watched_dir)
+ Dir.mkdir(unwatched_dir)
+
+ checker = new_checker([], watched_dir => ".rb", not_exist_watched_dir => ".rb") { }
+
+ FileUtils.touch(File.join(watched_dir, "a.rb"))
+ wait
+ assert_predicate checker, :updated?
+ assert checker.execute_if_updated
+
+ Dir.mkdir(not_exist_watched_dir)
+ wait
+ assert_predicate checker, :updated?
+ assert checker.execute_if_updated
+
+ FileUtils.touch(File.join(unwatched_dir, "a.rb"))
+ wait
+ assert_not_predicate checker, :updated?
+ assert_not checker.execute_if_updated
+ end
+ end
end
class EventedFileUpdateCheckerPathHelperTest < ActiveSupport::TestCase
diff --git a/activesupport/test/time_travel_test.rb b/activesupport/test/time_travel_test.rb
index 4dec0dc334..9c61ab0ab5 100644
--- a/activesupport/test/time_travel_test.rb
+++ b/activesupport/test/time_travel_test.rb
@@ -3,8 +3,11 @@
require "abstract_unit"
require "active_support/core_ext/date_time"
require "active_support/core_ext/numeric/time"
+require "time_zone_test_helpers"
class TimeTravelTest < ActiveSupport::TestCase
+ include TimeZoneTestHelpers
+
class TimeSubclass < ::Time; end
class DateSubclass < ::Date; end
class DateTimeSubclass < ::DateTime; end
@@ -67,6 +70,20 @@ class TimeTravelTest < ActiveSupport::TestCase
end
end
+ def test_time_helper_travel_to_with_time_zone
+ with_env_tz "US/Eastern" do
+ with_tz_default ActiveSupport::TimeZone["UTC"] do
+ Time.stub(:now, Time.now) do
+ expected_time = 5.minutes.ago
+
+ travel_to 5.minutes.ago do
+ assert_equal expected_time.to_s(:db), Time.zone.now.to_s(:db)
+ end
+ end
+ end
+ end
+ end
+
def test_time_helper_travel_back
Time.stub(:now, Time.now) do
expected_time = Time.new(2004, 11, 24, 01, 04, 44)