activesupport 5.1.7 → 5.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activesupport might be problematic. Click here for more details.

Files changed (238) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +303 -617
  3. data/README.rdoc +1 -1
  4. data/lib/active_support.rb +3 -12
  5. data/lib/active_support/all.rb +2 -0
  6. data/lib/active_support/array_inquirer.rb +2 -0
  7. data/lib/active_support/backtrace_cleaner.rb +2 -0
  8. data/lib/active_support/benchmarkable.rb +2 -0
  9. data/lib/active_support/builder.rb +2 -0
  10. data/lib/active_support/cache.rb +127 -58
  11. data/lib/active_support/cache/file_store.rb +4 -3
  12. data/lib/active_support/cache/mem_cache_store.rb +12 -4
  13. data/lib/active_support/cache/memory_store.rb +2 -0
  14. data/lib/active_support/cache/null_store.rb +2 -0
  15. data/lib/active_support/cache/redis_cache_store.rb +404 -0
  16. data/lib/active_support/cache/strategy/local_cache.rb +9 -2
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +2 -0
  18. data/lib/active_support/callbacks.rb +26 -37
  19. data/lib/active_support/concern.rb +3 -1
  20. data/lib/active_support/concurrency/share_lock.rb +2 -0
  21. data/lib/active_support/configurable.rb +2 -0
  22. data/lib/active_support/core_ext.rb +3 -1
  23. data/lib/active_support/core_ext/array.rb +2 -0
  24. data/lib/active_support/core_ext/array/access.rb +4 -2
  25. data/lib/active_support/core_ext/array/conversions.rb +2 -0
  26. data/lib/active_support/core_ext/array/extract_options.rb +2 -0
  27. data/lib/active_support/core_ext/array/grouping.rb +2 -0
  28. data/lib/active_support/core_ext/array/inquiry.rb +2 -0
  29. data/lib/active_support/core_ext/array/prepend_and_append.rb +4 -2
  30. data/lib/active_support/core_ext/array/wrap.rb +2 -0
  31. data/lib/active_support/core_ext/benchmark.rb +2 -0
  32. data/lib/active_support/core_ext/big_decimal.rb +2 -0
  33. data/lib/active_support/core_ext/big_decimal/conversions.rb +2 -0
  34. data/lib/active_support/core_ext/class.rb +2 -0
  35. data/lib/active_support/core_ext/class/attribute.rb +34 -16
  36. data/lib/active_support/core_ext/class/attribute_accessors.rb +2 -0
  37. data/lib/active_support/core_ext/class/subclasses.rb +1 -2
  38. data/lib/active_support/core_ext/date.rb +2 -0
  39. data/lib/active_support/core_ext/date/acts_like.rb +2 -0
  40. data/lib/active_support/core_ext/date/blank.rb +2 -0
  41. data/lib/active_support/core_ext/date/calculations.rb +2 -0
  42. data/lib/active_support/core_ext/date/conversions.rb +10 -9
  43. data/lib/active_support/core_ext/date/zones.rb +2 -0
  44. data/lib/active_support/core_ext/date_and_time/calculations.rb +42 -16
  45. data/lib/active_support/core_ext/date_and_time/compatibility.rb +3 -1
  46. data/lib/active_support/core_ext/date_and_time/zones.rb +2 -0
  47. data/lib/active_support/core_ext/date_time.rb +2 -0
  48. data/lib/active_support/core_ext/date_time/acts_like.rb +2 -0
  49. data/lib/active_support/core_ext/date_time/blank.rb +2 -0
  50. data/lib/active_support/core_ext/date_time/calculations.rb +2 -0
  51. data/lib/active_support/core_ext/date_time/compatibility.rb +6 -4
  52. data/lib/active_support/core_ext/date_time/conversions.rb +2 -0
  53. data/lib/active_support/core_ext/digest/uuid.rb +3 -1
  54. data/lib/active_support/core_ext/enumerable.rb +3 -1
  55. data/lib/active_support/core_ext/file.rb +2 -0
  56. data/lib/active_support/core_ext/file/atomic.rb +2 -0
  57. data/lib/active_support/core_ext/hash.rb +2 -0
  58. data/lib/active_support/core_ext/hash/compact.rb +2 -0
  59. data/lib/active_support/core_ext/hash/conversions.rb +2 -0
  60. data/lib/active_support/core_ext/hash/deep_merge.rb +8 -12
  61. data/lib/active_support/core_ext/hash/except.rb +2 -0
  62. data/lib/active_support/core_ext/hash/indifferent_access.rb +2 -0
  63. data/lib/active_support/core_ext/hash/keys.rb +2 -0
  64. data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
  65. data/lib/active_support/core_ext/hash/slice.rb +4 -4
  66. data/lib/active_support/core_ext/hash/transform_values.rb +2 -0
  67. data/lib/active_support/core_ext/integer.rb +2 -0
  68. data/lib/active_support/core_ext/integer/inflections.rb +2 -0
  69. data/lib/active_support/core_ext/integer/multiple.rb +2 -0
  70. data/lib/active_support/core_ext/integer/time.rb +7 -14
  71. data/lib/active_support/core_ext/kernel.rb +2 -0
  72. data/lib/active_support/core_ext/kernel/agnostics.rb +2 -0
  73. data/lib/active_support/core_ext/kernel/concern.rb +2 -0
  74. data/lib/active_support/core_ext/kernel/reporting.rb +2 -0
  75. data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
  76. data/lib/active_support/core_ext/load_error.rb +2 -7
  77. data/lib/active_support/core_ext/marshal.rb +2 -0
  78. data/lib/active_support/core_ext/module.rb +3 -0
  79. data/lib/active_support/core_ext/module/aliasing.rb +2 -0
  80. data/lib/active_support/core_ext/module/anonymous.rb +2 -0
  81. data/lib/active_support/core_ext/module/attr_internal.rb +2 -0
  82. data/lib/active_support/core_ext/module/attribute_accessors.rb +21 -24
  83. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +2 -0
  84. data/lib/active_support/core_ext/module/concerning.rb +2 -0
  85. data/lib/active_support/core_ext/module/delegation.rb +29 -24
  86. data/lib/active_support/core_ext/module/deprecation.rb +2 -0
  87. data/lib/active_support/core_ext/module/introspection.rb +2 -0
  88. data/lib/active_support/core_ext/module/reachable.rb +3 -0
  89. data/lib/active_support/core_ext/module/redefine_method.rb +49 -0
  90. data/lib/active_support/core_ext/module/remove_method.rb +5 -23
  91. data/lib/active_support/core_ext/name_error.rb +2 -0
  92. data/lib/active_support/core_ext/numeric.rb +2 -0
  93. data/lib/active_support/core_ext/numeric/bytes.rb +2 -0
  94. data/lib/active_support/core_ext/numeric/conversions.rb +9 -7
  95. data/lib/active_support/core_ext/numeric/inquiry.rb +2 -0
  96. data/lib/active_support/core_ext/numeric/time.rb +7 -15
  97. data/lib/active_support/core_ext/object.rb +2 -0
  98. data/lib/active_support/core_ext/object/acts_like.rb +12 -1
  99. data/lib/active_support/core_ext/object/blank.rb +2 -0
  100. data/lib/active_support/core_ext/object/conversions.rb +2 -0
  101. data/lib/active_support/core_ext/object/deep_dup.rb +2 -0
  102. data/lib/active_support/core_ext/object/duplicable.rb +10 -8
  103. data/lib/active_support/core_ext/object/inclusion.rb +2 -0
  104. data/lib/active_support/core_ext/object/instance_variables.rb +2 -0
  105. data/lib/active_support/core_ext/object/json.rb +8 -0
  106. data/lib/active_support/core_ext/object/to_param.rb +2 -0
  107. data/lib/active_support/core_ext/object/to_query.rb +4 -5
  108. data/lib/active_support/core_ext/object/try.rb +2 -0
  109. data/lib/active_support/core_ext/object/with_options.rb +3 -1
  110. data/lib/active_support/core_ext/range.rb +3 -0
  111. data/lib/active_support/core_ext/range/conversions.rb +9 -1
  112. data/lib/active_support/core_ext/range/each.rb +5 -1
  113. data/lib/active_support/core_ext/range/include_range.rb +2 -0
  114. data/lib/active_support/core_ext/range/include_time_with_zone.rb +23 -0
  115. data/lib/active_support/core_ext/range/overlaps.rb +2 -0
  116. data/lib/active_support/core_ext/regexp.rb +2 -0
  117. data/lib/active_support/core_ext/securerandom.rb +2 -0
  118. data/lib/active_support/core_ext/string.rb +2 -0
  119. data/lib/active_support/core_ext/string/access.rb +2 -0
  120. data/lib/active_support/core_ext/string/behavior.rb +2 -0
  121. data/lib/active_support/core_ext/string/conversions.rb +2 -0
  122. data/lib/active_support/core_ext/string/exclude.rb +2 -0
  123. data/lib/active_support/core_ext/string/filters.rb +2 -0
  124. data/lib/active_support/core_ext/string/indent.rb +2 -0
  125. data/lib/active_support/core_ext/string/inflections.rb +26 -12
  126. data/lib/active_support/core_ext/string/inquiry.rb +2 -0
  127. data/lib/active_support/core_ext/string/multibyte.rb +2 -0
  128. data/lib/active_support/core_ext/string/output_safety.rb +6 -7
  129. data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -0
  130. data/lib/active_support/core_ext/string/strip.rb +2 -0
  131. data/lib/active_support/core_ext/string/zones.rb +2 -0
  132. data/lib/active_support/core_ext/time.rb +2 -0
  133. data/lib/active_support/core_ext/time/acts_like.rb +2 -0
  134. data/lib/active_support/core_ext/time/calculations.rb +23 -15
  135. data/lib/active_support/core_ext/time/compatibility.rb +4 -2
  136. data/lib/active_support/core_ext/time/conversions.rb +2 -0
  137. data/lib/active_support/core_ext/time/zones.rb +6 -4
  138. data/lib/active_support/core_ext/uri.rb +4 -1
  139. data/lib/active_support/current_attributes.rb +195 -0
  140. data/lib/active_support/dependencies.rb +15 -25
  141. data/lib/active_support/dependencies/autoload.rb +2 -0
  142. data/lib/active_support/dependencies/interlock.rb +2 -0
  143. data/lib/active_support/deprecation.rb +4 -2
  144. data/lib/active_support/deprecation/behaviors.rb +23 -8
  145. data/lib/active_support/deprecation/constant_accessor.rb +3 -1
  146. data/lib/active_support/deprecation/instance_delegator.rb +2 -0
  147. data/lib/active_support/deprecation/method_wrappers.rb +2 -7
  148. data/lib/active_support/deprecation/proxy_wrappers.rb +4 -1
  149. data/lib/active_support/deprecation/reporting.rb +4 -2
  150. data/lib/active_support/descendants_tracker.rb +2 -0
  151. data/lib/active_support/duration.rb +8 -14
  152. data/lib/active_support/duration/iso8601_parser.rb +4 -2
  153. data/lib/active_support/duration/iso8601_serializer.rb +4 -2
  154. data/lib/active_support/encrypted_configuration.rb +48 -0
  155. data/lib/active_support/encrypted_file.rb +99 -0
  156. data/lib/active_support/evented_file_update_checker.rb +2 -0
  157. data/lib/active_support/execution_wrapper.rb +2 -0
  158. data/lib/active_support/executor.rb +2 -0
  159. data/lib/active_support/file_update_checker.rb +2 -0
  160. data/lib/active_support/gem_version.rb +5 -3
  161. data/lib/active_support/gzip.rb +2 -0
  162. data/lib/active_support/hash_with_indifferent_access.rb +33 -1
  163. data/lib/active_support/i18n.rb +3 -1
  164. data/lib/active_support/i18n_railtie.rb +5 -11
  165. data/lib/active_support/inflections.rb +2 -0
  166. data/lib/active_support/inflector.rb +2 -0
  167. data/lib/active_support/inflector/inflections.rb +19 -3
  168. data/lib/active_support/inflector/methods.rb +40 -23
  169. data/lib/active_support/inflector/transliterate.rb +17 -8
  170. data/lib/active_support/json.rb +2 -0
  171. data/lib/active_support/json/decoding.rb +2 -0
  172. data/lib/active_support/json/encoding.rb +2 -0
  173. data/lib/active_support/key_generator.rb +3 -1
  174. data/lib/active_support/lazy_load_hooks.rb +2 -0
  175. data/lib/active_support/log_subscriber.rb +3 -2
  176. data/lib/active_support/log_subscriber/test_helper.rb +2 -0
  177. data/lib/active_support/logger.rb +2 -0
  178. data/lib/active_support/logger_silence.rb +3 -2
  179. data/lib/active_support/logger_thread_safe_level.rb +2 -0
  180. data/lib/active_support/message_encryptor.rb +94 -22
  181. data/lib/active_support/message_verifier.rb +78 -7
  182. data/lib/active_support/messages/metadata.rb +71 -0
  183. data/lib/active_support/messages/rotation_configuration.rb +22 -0
  184. data/lib/active_support/messages/rotator.rb +56 -0
  185. data/lib/active_support/multibyte.rb +2 -0
  186. data/lib/active_support/multibyte/chars.rb +2 -0
  187. data/lib/active_support/multibyte/unicode.rb +3 -1
  188. data/lib/active_support/notifications.rb +2 -0
  189. data/lib/active_support/notifications/fanout.rb +2 -0
  190. data/lib/active_support/notifications/instrumenter.rb +2 -0
  191. data/lib/active_support/number_helper.rb +2 -0
  192. data/lib/active_support/number_helper/number_converter.rb +2 -0
  193. data/lib/active_support/number_helper/number_to_currency_converter.rb +2 -0
  194. data/lib/active_support/number_helper/number_to_delimited_converter.rb +2 -0
  195. data/lib/active_support/number_helper/number_to_human_converter.rb +2 -0
  196. data/lib/active_support/number_helper/number_to_human_size_converter.rb +2 -0
  197. data/lib/active_support/number_helper/number_to_percentage_converter.rb +2 -0
  198. data/lib/active_support/number_helper/number_to_phone_converter.rb +3 -1
  199. data/lib/active_support/number_helper/number_to_rounded_converter.rb +2 -20
  200. data/lib/active_support/number_helper/rounding_helper.rb +5 -3
  201. data/lib/active_support/option_merger.rb +2 -0
  202. data/lib/active_support/ordered_hash.rb +2 -0
  203. data/lib/active_support/ordered_options.rb +4 -2
  204. data/lib/active_support/per_thread_registry.rb +2 -0
  205. data/lib/active_support/proxy_object.rb +2 -0
  206. data/lib/active_support/rails.rb +2 -0
  207. data/lib/active_support/railtie.rb +27 -8
  208. data/lib/active_support/reloader.rb +7 -5
  209. data/lib/active_support/rescuable.rb +3 -2
  210. data/lib/active_support/security_utils.rb +15 -11
  211. data/lib/active_support/string_inquirer.rb +2 -0
  212. data/lib/active_support/subscriber.rb +2 -0
  213. data/lib/active_support/tagged_logging.rb +2 -0
  214. data/lib/active_support/test_case.rb +2 -1
  215. data/lib/active_support/testing/assertions.rb +6 -4
  216. data/lib/active_support/testing/autorun.rb +2 -0
  217. data/lib/active_support/testing/constant_lookup.rb +2 -0
  218. data/lib/active_support/testing/declarative.rb +2 -0
  219. data/lib/active_support/testing/deprecation.rb +2 -0
  220. data/lib/active_support/testing/file_fixtures.rb +2 -0
  221. data/lib/active_support/testing/isolation.rb +5 -5
  222. data/lib/active_support/testing/method_call_assertions.rb +2 -0
  223. data/lib/active_support/testing/setup_and_teardown.rb +2 -0
  224. data/lib/active_support/testing/stream.rb +2 -0
  225. data/lib/active_support/testing/tagged_logging.rb +2 -0
  226. data/lib/active_support/testing/time_helpers.rb +31 -2
  227. data/lib/active_support/time.rb +2 -0
  228. data/lib/active_support/time_with_zone.rb +38 -0
  229. data/lib/active_support/values/time_zone.rb +20 -12
  230. data/lib/active_support/version.rb +2 -0
  231. data/lib/active_support/xml_mini.rb +2 -0
  232. data/lib/active_support/xml_mini/jdom.rb +4 -2
  233. data/lib/active_support/xml_mini/libxml.rb +3 -1
  234. data/lib/active_support/xml_mini/libxmlsax.rb +4 -2
  235. data/lib/active_support/xml_mini/nokogiri.rb +3 -1
  236. data/lib/active_support/xml_mini/nokogirisax.rb +3 -1
  237. data/lib/active_support/xml_mini/rexml.rb +3 -1
  238. metadata +19 -15
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/module/delegation"
2
4
  require "active_support/core_ext/object/blank"
3
5
  require "logger"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  gem "minitest" # make sure we get the gem, not stdlib
2
4
  require "minitest"
3
5
  require "active_support/testing/tagged_logging"
@@ -9,7 +11,6 @@ require "active_support/testing/isolation"
9
11
  require "active_support/testing/constant_lookup"
10
12
  require "active_support/testing/time_helpers"
11
13
  require "active_support/testing/file_fixtures"
12
- require "active_support/core_ext/kernel/reporting"
13
14
 
14
15
  module ActiveSupport
15
16
  class TestCase < ::Minitest::Test
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveSupport
2
4
  module Testing
3
5
  module Assertions
@@ -155,9 +157,9 @@ module ActiveSupport
155
157
  after = exp.call
156
158
 
157
159
  if to == UNTRACKED
158
- error = "#{expression.inspect} didn't changed"
160
+ error = "#{expression.inspect} didn't change"
159
161
  error = "#{message}.\n#{error}" if message
160
- assert_not_equal before, after, error
162
+ assert before != after, error
161
163
  else
162
164
  error = "#{expression.inspect} didn't change to #{to}"
163
165
  error = "#{message}.\n#{error}" if message
@@ -167,7 +169,7 @@ module ActiveSupport
167
169
  retval
168
170
  end
169
171
 
170
- # Assertion that the result of evaluating an expression is changed before
172
+ # Assertion that the result of evaluating an expression is not changed before
171
173
  # and after invoking the passed in block.
172
174
  #
173
175
  # assert_no_changes 'Status.all_good?' do
@@ -188,7 +190,7 @@ module ActiveSupport
188
190
 
189
191
  error = "#{expression.inspect} did change to #{after}"
190
192
  error = "#{message}.\n#{error}" if message
191
- assert_equal before, after, error
193
+ assert before == after, error
192
194
 
193
195
  retval
194
196
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  gem "minitest"
2
4
 
3
5
  require "minitest"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/concern"
2
4
  require "active_support/inflector"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveSupport
2
4
  module Testing
3
5
  module Declarative
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/deprecation"
2
4
  require "active_support/core_ext/regexp"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveSupport
2
4
  module Testing
3
5
  # Adds simple access to sample files called file fixtures.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveSupport
2
4
  module Testing
3
5
  module Isolation
@@ -43,8 +45,7 @@ module ActiveSupport
43
45
  end
44
46
  }
45
47
  end
46
- test_result = defined?(Minitest::Result) ? Minitest::Result.from(self) : dup
47
- result = Marshal.dump(test_result)
48
+ result = Marshal.dump(dup)
48
49
  end
49
50
 
50
51
  write.puts [result].pack("m")
@@ -54,7 +55,7 @@ module ActiveSupport
54
55
  write.close
55
56
  result = read.read
56
57
  Process.wait2(pid)
57
- return result.unpack("m")[0]
58
+ result.unpack("m")[0]
58
59
  end
59
60
  end
60
61
 
@@ -68,9 +69,8 @@ module ActiveSupport
68
69
 
69
70
  if ENV["ISOLATION_TEST"]
70
71
  yield
71
- test_result = defined?(Minitest::Result) ? Minitest::Result.from(self) : dup
72
72
  File.open(ENV["ISOLATION_OUTPUT"], "w") do |file|
73
- file.puts [Marshal.dump(test_result)].pack("m")
73
+ file.puts [Marshal.dump(dup)].pack("m")
74
74
  end
75
75
  exit!
76
76
  else
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "minitest/mock"
2
4
 
3
5
  module ActiveSupport
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/concern"
2
4
  require "active_support/callbacks"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveSupport
2
4
  module Testing
3
5
  module Stream #:nodoc:
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveSupport
2
4
  module Testing
3
5
  # Logs a "PostsControllerTest: test name" heading before each test to
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/string/strip" # for strip_heredoc
2
4
  require "active_support/core_ext/time/calculations"
3
5
  require "concurrent/map"
@@ -49,8 +51,14 @@ module ActiveSupport
49
51
 
50
52
  # Contains helpers that help you test passage of time.
51
53
  module TimeHelpers
54
+ def after_teardown
55
+ travel_back
56
+ super
57
+ end
58
+
52
59
  # Changes current time to the time in the future or in the past by a given time difference by
53
- # stubbing +Time.now+, +Date.today+, and +DateTime.now+.
60
+ # stubbing +Time.now+, +Date.today+, and +DateTime.now+. The stubs are automatically removed
61
+ # at the end of the test.
54
62
  #
55
63
  # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
56
64
  # travel 1.day
@@ -72,6 +80,7 @@ module ActiveSupport
72
80
 
73
81
  # Changes current time to the given time by stubbing +Time.now+,
74
82
  # +Date.today+, and +DateTime.now+ to return the time or date passed into this method.
83
+ # The stubs are automatically removed at the end of the test.
75
84
  #
76
85
  # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
77
86
  # travel_to Time.zone.local(2004, 11, 24, 01, 04, 44)
@@ -149,7 +158,7 @@ module ActiveSupport
149
158
  end
150
159
 
151
160
  # Returns the current time back to its original state, by removing the stubs added by
152
- # `travel` and `travel_to`.
161
+ # +travel+ and +travel_to+.
153
162
  #
154
163
  # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
155
164
  # travel_to Time.zone.local(2004, 11, 24, 01, 04, 44)
@@ -160,6 +169,26 @@ module ActiveSupport
160
169
  simple_stubs.unstub_all!
161
170
  end
162
171
 
172
+ # Calls +travel_to+ with +Time.now+.
173
+ #
174
+ # Time.current # => Sun, 09 Jul 2017 15:34:49 EST -05:00
175
+ # freeze_time
176
+ # sleep(1)
177
+ # Time.current # => Sun, 09 Jul 2017 15:34:49 EST -05:00
178
+ #
179
+ # This method also accepts a block, which will return the current time back to its original
180
+ # state at the end of the block:
181
+ #
182
+ # Time.current # => Sun, 09 Jul 2017 15:34:49 EST -05:00
183
+ # freeze_time do
184
+ # sleep(1)
185
+ # User.create.created_at # => Sun, 09 Jul 2017 15:34:49 EST -05:00
186
+ # end
187
+ # Time.current # => Sun, 09 Jul 2017 15:34:50 EST -05:00
188
+ def freeze_time(&block)
189
+ travel_to Time.now, &block
190
+ end
191
+
163
192
  private
164
193
 
165
194
  def simple_stubs
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveSupport
2
4
  autoload :Duration, "active_support/duration"
3
5
  autoload :TimeWithZone, "active_support/time_with_zone"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/duration"
2
4
  require "active_support/values/time_zone"
3
5
  require "active_support/core_ext/object/acts_like"
@@ -330,6 +332,42 @@ module ActiveSupport
330
332
  since(-other)
331
333
  end
332
334
 
335
+ # Returns a new +ActiveSupport::TimeWithZone+ where one or more of the elements have
336
+ # been changed according to the +options+ parameter. The time options (<tt>:hour</tt>,
337
+ # <tt>:min</tt>, <tt>:sec</tt>, <tt>:usec</tt>, <tt>:nsec</tt>) reset cascadingly,
338
+ # so if only the hour is passed, then minute, sec, usec and nsec is set to 0. If the
339
+ # hour and minute is passed, then sec, usec and nsec is set to 0. The +options+
340
+ # parameter takes a hash with any of these keys: <tt>:year</tt>, <tt>:month</tt>,
341
+ # <tt>:day</tt>, <tt>:hour</tt>, <tt>:min</tt>, <tt>:sec</tt>, <tt>:usec</tt>,
342
+ # <tt>:nsec</tt>, <tt>:offset</tt>, <tt>:zone</tt>. Pass either <tt>:usec</tt>
343
+ # or <tt>:nsec</tt>, not both. Similarly, pass either <tt>:zone</tt> or
344
+ # <tt>:offset</tt>, not both.
345
+ #
346
+ # t = Time.zone.now # => Fri, 14 Apr 2017 11:45:15 EST -05:00
347
+ # t.change(year: 2020) # => Tue, 14 Apr 2020 11:45:15 EST -05:00
348
+ # t.change(hour: 12) # => Fri, 14 Apr 2017 12:00:00 EST -05:00
349
+ # t.change(min: 30) # => Fri, 14 Apr 2017 11:30:00 EST -05:00
350
+ # t.change(offset: "-10:00") # => Fri, 14 Apr 2017 11:45:15 HST -10:00
351
+ # t.change(zone: "Hawaii") # => Fri, 14 Apr 2017 11:45:15 HST -10:00
352
+ def change(options)
353
+ if options[:zone] && options[:offset]
354
+ raise ArgumentError, "Can't change both :offset and :zone at the same time: #{options.inspect}"
355
+ end
356
+
357
+ new_time = time.change(options)
358
+
359
+ if options[:zone]
360
+ new_zone = ::Time.find_zone(options[:zone])
361
+ elsif options[:offset]
362
+ new_zone = ::Time.find_zone(new_time.utc_offset)
363
+ end
364
+
365
+ new_zone ||= time_zone
366
+ periods = new_zone.periods_for_local(new_time)
367
+
368
+ self.class.new(nil, new_zone, new_time, periods.include?(period) ? period : nil)
369
+ end
370
+
333
371
  # Uses Date to provide precise Time calculations for years, months, and days
334
372
  # according to the proleptic Gregorian calendar. The result is returned as a
335
373
  # new TimeWithZone object.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "tzinfo"
2
4
  require "concurrent/map"
3
5
  require "active_support/core_ext/object/blank"
@@ -6,7 +8,7 @@ module ActiveSupport
6
8
  # The TimeZone class serves as a wrapper around TZInfo::Timezone instances.
7
9
  # It allows us to do the following:
8
10
  #
9
- # * Limit the set of zones provided by TZInfo to a meaningful subset of 146
11
+ # * Limit the set of zones provided by TZInfo to a meaningful subset of 134
10
12
  # zones.
11
13
  # * Retrieve and display zones with a friendlier name
12
14
  # (e.g., "Eastern Time (US & Canada)" instead of "America/New_York").
@@ -28,7 +30,7 @@ module ActiveSupport
28
30
  class TimeZone
29
31
  # Keys are Rails TimeZone names, values are TZInfo identifiers.
30
32
  MAPPING = {
31
- "International Date Line West" => "Pacific/Midway",
33
+ "International Date Line West" => "Etc/GMT+12",
32
34
  "Midway Island" => "Pacific/Midway",
33
35
  "American Samoa" => "Pacific/Pago_Pago",
34
36
  "Hawaii" => "Pacific/Honolulu",
@@ -59,6 +61,7 @@ module ActiveSupport
59
61
  "Buenos Aires" => "America/Argentina/Buenos_Aires",
60
62
  "Montevideo" => "America/Montevideo",
61
63
  "Georgetown" => "America/Guyana",
64
+ "Puerto Rico" => "America/Puerto_Rico",
62
65
  "Greenland" => "America/Godthab",
63
66
  "Mid-Atlantic" => "Atlantic/South_Georgia",
64
67
  "Azores" => "Atlantic/Azores",
@@ -253,25 +256,28 @@ module ActiveSupport
253
256
  @country_zones[code] ||= load_country_zones(code)
254
257
  end
255
258
 
259
+ def clear #:nodoc:
260
+ @lazy_zones_map = Concurrent::Map.new
261
+ @country_zones = Concurrent::Map.new
262
+ @zones = nil
263
+ @zones_map = nil
264
+ end
265
+
256
266
  private
257
267
  def load_country_zones(code)
258
268
  country = TZInfo::Country.get(code)
259
269
  country.zone_identifiers.map do |tz_id|
260
270
  if MAPPING.value?(tz_id)
261
- MAPPING.inject([]) do |memo, (key, value)|
262
- memo << self[key] if value == tz_id
263
- memo
264
- end
271
+ self[MAPPING.key(tz_id)]
265
272
  else
266
273
  create(tz_id, nil, TZInfo::Timezone.new(tz_id))
267
274
  end
268
- end.flatten(1).sort!
275
+ end.sort!
269
276
  end
270
277
 
271
278
  def zones_map
272
- @zones_map ||= begin
273
- MAPPING.each_key { |place| self[place] } # load all the zones
274
- @lazy_zones_map
279
+ @zones_map ||= MAPPING.each_with_object({}) do |(name, _), zones|
280
+ zones[name] = self[name]
275
281
  end
276
282
  end
277
283
  end
@@ -361,7 +367,7 @@ module ActiveSupport
361
367
  # Time.zone.iso8601('1999-12-31') # => Fri, 31 Dec 1999 00:00:00 HST -10:00
362
368
  #
363
369
  # If the string is invalid then an +ArgumentError+ will be raised unlike +parse+
364
- # which returns +nil+ when given an invalid date string.
370
+ # which usually returns +nil+ when given an invalid date string.
365
371
  def iso8601(str)
366
372
  parts = Date._iso8601(str)
367
373
 
@@ -400,6 +406,8 @@ module ActiveSupport
400
406
  # components are supplied, then the day of the month defaults to 1:
401
407
  #
402
408
  # Time.zone.parse('Mar 2000') # => Wed, 01 Mar 2000 00:00:00 HST -10:00
409
+ #
410
+ # If the string is invalid then an +ArgumentError+ could be raised.
403
411
  def parse(str, now = now())
404
412
  parts_to_time(Date._parse(str, false), now)
405
413
  end
@@ -504,7 +512,7 @@ module ActiveSupport
504
512
  # Available so that TimeZone instances respond like TZInfo::Timezone
505
513
  # instances.
506
514
  def period_for_local(time, dst = true)
507
- tzinfo.period_for_local(time, dst)
515
+ tzinfo.period_for_local(time, dst) { |periods| periods.last }
508
516
  end
509
517
 
510
518
  def periods_for_local(time) #:nodoc:
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "gem_version"
2
4
 
3
5
  module ActiveSupport
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "time"
2
4
  require "base64"
3
5
  require "bigdecimal"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  raise "JRuby is required to use the JDOM backend for XmlMini" unless RUBY_PLATFORM.include?("java")
2
4
 
3
5
  require "jruby"
@@ -38,7 +40,7 @@ module ActiveSupport
38
40
  else
39
41
  @dbf = DocumentBuilderFactory.new_instance
40
42
  # secure processing of java xml
41
- # http://www.ibm.com/developerworks/xml/library/x-tipcfsx/index.html
43
+ # https://archive.is/9xcQQ
42
44
  @dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
43
45
  @dbf.setFeature("http://xml.org/sax/features/external-general-entities", false)
44
46
  @dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false)
@@ -167,7 +169,7 @@ module ActiveSupport
167
169
  # element::
168
170
  # XML element to be checked.
169
171
  def empty_content?(element)
170
- text = ""
172
+ text = "".dup
171
173
  child_nodes = element.child_nodes
172
174
  (0...child_nodes.length).each do |i|
173
175
  item = child_nodes.item(i)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "libxml"
2
4
  require "active_support/core_ext/object/blank"
3
5
  require "stringio"
@@ -53,7 +55,7 @@ module LibXML #:nodoc:
53
55
  if c.element?
54
56
  c.to_hash(node_hash)
55
57
  elsif c.text? || c.cdata?
56
- node_hash[CONTENT_ROOT] ||= ""
58
+ node_hash[CONTENT_ROOT] ||= "".dup
57
59
  node_hash[CONTENT_ROOT] << c.content
58
60
  end
59
61
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "libxml"
2
4
  require "active_support/core_ext/object/blank"
3
5
  require "stringio"
@@ -21,7 +23,7 @@ module ActiveSupport
21
23
  end
22
24
 
23
25
  def on_start_document
24
- @hash = { CONTENT_KEY => "" }
26
+ @hash = { CONTENT_KEY => "".dup }
25
27
  @hash_stack = [@hash]
26
28
  end
27
29
 
@@ -31,7 +33,7 @@ module ActiveSupport
31
33
  end
32
34
 
33
35
  def on_start_element(name, attrs = {})
34
- new_hash = { CONTENT_KEY => "" }.merge!(attrs)
36
+ new_hash = { CONTENT_KEY => "".dup }.merge!(attrs)
35
37
  new_hash[HASH_SIZE_KEY] = new_hash.size + 1
36
38
 
37
39
  case current_hash[name]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require "nokogiri"
3
5
  rescue LoadError => e
@@ -57,7 +59,7 @@ module ActiveSupport
57
59
  if c.element?
58
60
  c.to_hash(node_hash)
59
61
  elsif c.text? || c.cdata?
60
- node_hash[CONTENT_ROOT] ||= ""
62
+ node_hash[CONTENT_ROOT] ||= "".dup
61
63
  node_hash[CONTENT_ROOT] << c.content
62
64
  end
63
65
  end