activesupport 5.0.7.2 → 5.1.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 (210) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +215 -820
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +1 -1
  5. data/lib/active_support.rb +8 -4
  6. data/lib/active_support/all.rb +3 -3
  7. data/lib/active_support/array_inquirer.rb +7 -5
  8. data/lib/active_support/backtrace_cleaner.rb +4 -4
  9. data/lib/active_support/benchmarkable.rb +3 -3
  10. data/lib/active_support/builder.rb +1 -1
  11. data/lib/active_support/cache.rb +42 -49
  12. data/lib/active_support/cache/file_store.rb +12 -21
  13. data/lib/active_support/cache/mem_cache_store.rb +30 -40
  14. data/lib/active_support/cache/memory_store.rb +11 -13
  15. data/lib/active_support/cache/null_store.rb +4 -4
  16. data/lib/active_support/cache/strategy/local_cache.rb +16 -25
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +8 -9
  18. data/lib/active_support/callbacks.rb +647 -584
  19. data/lib/active_support/concurrency/share_lock.rb +20 -21
  20. data/lib/active_support/configurable.rb +5 -5
  21. data/lib/active_support/core_ext.rb +1 -2
  22. data/lib/active_support/core_ext/array.rb +7 -7
  23. data/lib/active_support/core_ext/array/access.rb +1 -1
  24. data/lib/active_support/core_ext/array/conversions.rb +15 -15
  25. data/lib/active_support/core_ext/array/grouping.rb +1 -1
  26. data/lib/active_support/core_ext/array/inquiry.rb +1 -1
  27. data/lib/active_support/core_ext/array/prepend_and_append.rb +1 -1
  28. data/lib/active_support/core_ext/benchmark.rb +1 -1
  29. data/lib/active_support/core_ext/big_decimal.rb +1 -1
  30. data/lib/active_support/core_ext/big_decimal/conversions.rb +4 -6
  31. data/lib/active_support/core_ext/class.rb +2 -2
  32. data/lib/active_support/core_ext/class/attribute.rb +5 -5
  33. data/lib/active_support/core_ext/class/attribute_accessors.rb +1 -1
  34. data/lib/active_support/core_ext/class/subclasses.rb +18 -4
  35. data/lib/active_support/core_ext/date.rb +5 -5
  36. data/lib/active_support/core_ext/date/acts_like.rb +1 -1
  37. data/lib/active_support/core_ext/date/blank.rb +1 -1
  38. data/lib/active_support/core_ext/date/calculations.rb +8 -8
  39. data/lib/active_support/core_ext/date/conversions.rb +12 -12
  40. data/lib/active_support/core_ext/date/zones.rb +2 -2
  41. data/lib/active_support/core_ext/date_and_time/calculations.rb +27 -22
  42. data/lib/active_support/core_ext/date_and_time/compatibility.rb +9 -1
  43. data/lib/active_support/core_ext/date_and_time/zones.rb +7 -8
  44. data/lib/active_support/core_ext/date_time.rb +5 -5
  45. data/lib/active_support/core_ext/date_time/acts_like.rb +2 -2
  46. data/lib/active_support/core_ext/date_time/blank.rb +1 -1
  47. data/lib/active_support/core_ext/date_time/calculations.rb +9 -9
  48. data/lib/active_support/core_ext/date_time/compatibility.rb +2 -13
  49. data/lib/active_support/core_ext/date_time/conversions.rb +12 -12
  50. data/lib/active_support/core_ext/digest/uuid.rb +4 -4
  51. data/lib/active_support/core_ext/enumerable.rb +46 -57
  52. data/lib/active_support/core_ext/file.rb +1 -1
  53. data/lib/active_support/core_ext/file/atomic.rb +4 -4
  54. data/lib/active_support/core_ext/hash.rb +9 -9
  55. data/lib/active_support/core_ext/hash/compact.rb +12 -9
  56. data/lib/active_support/core_ext/hash/conversions.rb +36 -37
  57. data/lib/active_support/core_ext/hash/indifferent_access.rb +1 -2
  58. data/lib/active_support/core_ext/hash/keys.rb +8 -8
  59. data/lib/active_support/core_ext/hash/reverse_merge.rb +1 -1
  60. data/lib/active_support/core_ext/hash/slice.rb +4 -4
  61. data/lib/active_support/core_ext/hash/transform_values.rb +1 -0
  62. data/lib/active_support/core_ext/integer.rb +3 -3
  63. data/lib/active_support/core_ext/integer/inflections.rb +1 -1
  64. data/lib/active_support/core_ext/integer/time.rb +2 -2
  65. data/lib/active_support/core_ext/kernel.rb +4 -4
  66. data/lib/active_support/core_ext/kernel/concern.rb +1 -1
  67. data/lib/active_support/core_ext/kernel/reporting.rb +1 -1
  68. data/lib/active_support/core_ext/load_error.rb +1 -18
  69. data/lib/active_support/core_ext/marshal.rb +2 -2
  70. data/lib/active_support/core_ext/module.rb +11 -12
  71. data/lib/active_support/core_ext/module/aliasing.rb +3 -48
  72. data/lib/active_support/core_ext/module/attr_internal.rb +4 -4
  73. data/lib/active_support/core_ext/module/attribute_accessors.rb +11 -5
  74. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +20 -13
  75. data/lib/active_support/core_ext/module/concerning.rb +1 -1
  76. data/lib/active_support/core_ext/module/delegation.rb +82 -16
  77. data/lib/active_support/core_ext/module/introspection.rb +3 -11
  78. data/lib/active_support/core_ext/module/reachable.rb +2 -2
  79. data/lib/active_support/core_ext/numeric.rb +4 -4
  80. data/lib/active_support/core_ext/numeric/conversions.rb +3 -9
  81. data/lib/active_support/core_ext/numeric/inquiry.rb +21 -21
  82. data/lib/active_support/core_ext/numeric/time.rb +5 -5
  83. data/lib/active_support/core_ext/object.rb +12 -12
  84. data/lib/active_support/core_ext/object/blank.rb +3 -1
  85. data/lib/active_support/core_ext/object/conversions.rb +4 -4
  86. data/lib/active_support/core_ext/object/deep_dup.rb +1 -1
  87. data/lib/active_support/core_ext/object/duplicable.rb +24 -4
  88. data/lib/active_support/core_ext/object/inclusion.rb +1 -1
  89. data/lib/active_support/core_ext/object/json.rb +26 -12
  90. data/lib/active_support/core_ext/object/to_param.rb +1 -1
  91. data/lib/active_support/core_ext/object/to_query.rb +4 -4
  92. data/lib/active_support/core_ext/object/try.rb +1 -1
  93. data/lib/active_support/core_ext/object/with_options.rb +1 -1
  94. data/lib/active_support/core_ext/range.rb +4 -4
  95. data/lib/active_support/core_ext/range/conversions.rb +1 -1
  96. data/lib/active_support/core_ext/regexp.rb +4 -0
  97. data/lib/active_support/core_ext/securerandom.rb +3 -3
  98. data/lib/active_support/core_ext/string.rb +13 -13
  99. data/lib/active_support/core_ext/string/access.rb +6 -6
  100. data/lib/active_support/core_ext/string/conversions.rb +2 -2
  101. data/lib/active_support/core_ext/string/filters.rb +3 -3
  102. data/lib/active_support/core_ext/string/indent.rb +4 -4
  103. data/lib/active_support/core_ext/string/inflections.rb +10 -14
  104. data/lib/active_support/core_ext/string/inquiry.rb +1 -1
  105. data/lib/active_support/core_ext/string/multibyte.rb +1 -1
  106. data/lib/active_support/core_ext/string/output_safety.rb +19 -20
  107. data/lib/active_support/core_ext/string/strip.rb +1 -1
  108. data/lib/active_support/core_ext/string/zones.rb +2 -2
  109. data/lib/active_support/core_ext/time.rb +5 -5
  110. data/lib/active_support/core_ext/time/acts_like.rb +1 -1
  111. data/lib/active_support/core_ext/time/calculations.rb +23 -29
  112. data/lib/active_support/core_ext/time/compatibility.rb +1 -10
  113. data/lib/active_support/core_ext/time/conversions.rb +12 -12
  114. data/lib/active_support/core_ext/time/zones.rb +3 -3
  115. data/lib/active_support/core_ext/uri.rb +2 -2
  116. data/lib/active_support/dependencies.rb +45 -47
  117. data/lib/active_support/dependencies/interlock.rb +1 -1
  118. data/lib/active_support/deprecation.rb +8 -8
  119. data/lib/active_support/deprecation/behaviors.rb +3 -3
  120. data/lib/active_support/deprecation/instance_delegator.rb +2 -2
  121. data/lib/active_support/deprecation/method_wrappers.rb +3 -3
  122. data/lib/active_support/deprecation/proxy_wrappers.rb +6 -4
  123. data/lib/active_support/deprecation/reporting.rb +7 -7
  124. data/lib/active_support/duration.rb +30 -26
  125. data/lib/active_support/duration/iso8601_parser.rb +66 -65
  126. data/lib/active_support/duration/iso8601_serializer.rb +11 -9
  127. data/lib/active_support/evented_file_update_checker.rb +59 -60
  128. data/lib/active_support/execution_wrapper.rb +3 -3
  129. data/lib/active_support/executor.rb +1 -1
  130. data/lib/active_support/file_update_checker.rb +54 -50
  131. data/lib/active_support/gem_version.rb +3 -3
  132. data/lib/active_support/gzip.rb +5 -5
  133. data/lib/active_support/hash_with_indifferent_access.rb +10 -20
  134. data/lib/active_support/i18n.rb +5 -5
  135. data/lib/active_support/i18n_railtie.rb +11 -10
  136. data/lib/active_support/inflections.rb +11 -11
  137. data/lib/active_support/inflector.rb +5 -5
  138. data/lib/active_support/inflector/inflections.rb +11 -9
  139. data/lib/active_support/inflector/methods.rb +51 -50
  140. data/lib/active_support/inflector/transliterate.rb +8 -11
  141. data/lib/active_support/json.rb +2 -2
  142. data/lib/active_support/json/decoding.rb +3 -3
  143. data/lib/active_support/json/encoding.rb +8 -7
  144. data/lib/active_support/key_generator.rb +17 -17
  145. data/lib/active_support/lazy_load_hooks.rb +12 -30
  146. data/lib/active_support/log_subscriber.rb +5 -5
  147. data/lib/active_support/log_subscriber/test_helper.rb +9 -9
  148. data/lib/active_support/logger.rb +3 -3
  149. data/lib/active_support/logger_silence.rb +3 -3
  150. data/lib/active_support/logger_thread_safe_level.rb +1 -1
  151. data/lib/active_support/message_encryptor.rb +72 -35
  152. data/lib/active_support/message_verifier.rb +7 -7
  153. data/lib/active_support/multibyte.rb +2 -2
  154. data/lib/active_support/multibyte/chars.rb +23 -21
  155. data/lib/active_support/multibyte/unicode.rb +68 -89
  156. data/lib/active_support/notifications.rb +5 -5
  157. data/lib/active_support/notifications/fanout.rb +3 -3
  158. data/lib/active_support/notifications/instrumenter.rb +5 -5
  159. data/lib/active_support/number_helper.rb +4 -4
  160. data/lib/active_support/number_helper/number_converter.rb +11 -11
  161. data/lib/active_support/number_helper/number_to_currency_converter.rb +3 -3
  162. data/lib/active_support/number_helper/number_to_delimited_converter.rb +1 -2
  163. data/lib/active_support/number_helper/number_to_human_converter.rb +6 -6
  164. data/lib/active_support/number_helper/number_to_human_size_converter.rb +6 -11
  165. data/lib/active_support/number_helper/number_to_percentage_converter.rb +1 -1
  166. data/lib/active_support/number_helper/number_to_phone_converter.rb +1 -3
  167. data/lib/active_support/number_helper/number_to_rounded_converter.rb +6 -6
  168. data/lib/active_support/option_merger.rb +1 -1
  169. data/lib/active_support/ordered_hash.rb +3 -3
  170. data/lib/active_support/ordered_options.rb +6 -4
  171. data/lib/active_support/per_thread_registry.rb +5 -5
  172. data/lib/active_support/rails.rb +12 -6
  173. data/lib/active_support/railtie.rb +3 -3
  174. data/lib/active_support/reloader.rb +1 -1
  175. data/lib/active_support/rescuable.rb +8 -14
  176. data/lib/active_support/security_utils.rb +1 -1
  177. data/lib/active_support/string_inquirer.rb +8 -2
  178. data/lib/active_support/subscriber.rb +9 -5
  179. data/lib/active_support/tagged_logging.rb +4 -4
  180. data/lib/active_support/test_case.rb +12 -29
  181. data/lib/active_support/testing/assertions.rb +100 -2
  182. data/lib/active_support/testing/autorun.rb +6 -2
  183. data/lib/active_support/testing/constant_lookup.rb +0 -1
  184. data/lib/active_support/testing/declarative.rb +1 -1
  185. data/lib/active_support/testing/deprecation.rb +3 -2
  186. data/lib/active_support/testing/isolation.rb +13 -22
  187. data/lib/active_support/testing/method_call_assertions.rb +1 -1
  188. data/lib/active_support/testing/setup_and_teardown.rb +2 -2
  189. data/lib/active_support/testing/stream.rb +28 -28
  190. data/lib/active_support/testing/tagged_logging.rb +1 -1
  191. data/lib/active_support/testing/time_helpers.rb +45 -12
  192. data/lib/active_support/time.rb +12 -12
  193. data/lib/active_support/time_with_zone.rb +16 -26
  194. data/lib/active_support/values/time_zone.rb +40 -46
  195. data/lib/active_support/values/unicode_tables.dat +0 -0
  196. data/lib/active_support/version.rb +1 -1
  197. data/lib/active_support/xml_mini.rb +34 -36
  198. data/lib/active_support/xml_mini/jdom.rb +112 -112
  199. data/lib/active_support/xml_mini/libxml.rb +15 -12
  200. data/lib/active_support/xml_mini/libxmlsax.rb +17 -15
  201. data/lib/active_support/xml_mini/nokogiri.rb +13 -11
  202. data/lib/active_support/xml_mini/nokogirisax.rb +15 -14
  203. data/lib/active_support/xml_mini/rexml.rb +9 -9
  204. metadata +8 -19
  205. data/lib/active_support/concurrency/latch.rb +0 -26
  206. data/lib/active_support/core_ext/kernel/debugger.rb +0 -3
  207. data/lib/active_support/core_ext/module/method_transplanting.rb +0 -3
  208. data/lib/active_support/core_ext/module/qualified_const.rb +0 -70
  209. data/lib/active_support/core_ext/struct.rb +0 -3
  210. data/lib/active_support/core_ext/time/marshal.rb +0 -3
@@ -1,7 +1,7 @@
1
- require 'active_support/core_ext/module/delegation'
2
- require 'active_support/core_ext/object/blank'
3
- require 'logger'
4
- require 'active_support/logger'
1
+ require "active_support/core_ext/module/delegation"
2
+ require "active_support/core_ext/object/blank"
3
+ require "logger"
4
+ require "active_support/logger"
5
5
 
6
6
  module ActiveSupport
7
7
  # Wraps any standard Logger object to provide tagging capabilities.
@@ -1,15 +1,15 @@
1
- gem 'minitest' # make sure we get the gem, not stdlib
2
- require 'minitest'
3
- require 'active_support/testing/tagged_logging'
4
- require 'active_support/testing/setup_and_teardown'
5
- require 'active_support/testing/assertions'
6
- require 'active_support/testing/deprecation'
7
- require 'active_support/testing/declarative'
8
- require 'active_support/testing/isolation'
9
- require 'active_support/testing/constant_lookup'
10
- require 'active_support/testing/time_helpers'
11
- require 'active_support/testing/file_fixtures'
12
- require 'active_support/core_ext/kernel/reporting'
1
+ gem "minitest" # make sure we get the gem, not stdlib
2
+ require "minitest"
3
+ require "active_support/testing/tagged_logging"
4
+ require "active_support/testing/setup_and_teardown"
5
+ require "active_support/testing/assertions"
6
+ require "active_support/testing/deprecation"
7
+ require "active_support/testing/declarative"
8
+ require "active_support/testing/isolation"
9
+ require "active_support/testing/constant_lookup"
10
+ require "active_support/testing/time_helpers"
11
+ require "active_support/testing/file_fixtures"
12
+ require "active_support/core_ext/kernel/reporting"
13
13
 
14
14
  module ActiveSupport
15
15
  class TestCase < ::Minitest::Test
@@ -66,23 +66,6 @@ module ActiveSupport
66
66
  alias :assert_not_respond_to :refute_respond_to
67
67
  alias :assert_not_same :refute_same
68
68
 
69
-
70
- # Assertion that the block should not raise an exception.
71
- #
72
- # Passes if evaluated code in the yielded block raises no exception.
73
- #
74
- # assert_nothing_raised do
75
- # perform_service(param: 'no_exception')
76
- # end
77
- def assert_nothing_raised(*args)
78
- if args.present?
79
- ActiveSupport::Deprecation.warn(
80
- "Passing arguments to assert_nothing_raised " \
81
- "is deprecated and will be removed in Rails 5.1.")
82
- end
83
- yield
84
- end
85
-
86
69
  ActiveSupport.run_load_hooks(:active_support_test_case, self)
87
70
  end
88
71
  end
@@ -1,8 +1,8 @@
1
- require 'active_support/core_ext/object/blank'
2
-
3
1
  module ActiveSupport
4
2
  module Testing
5
3
  module Assertions
4
+ UNTRACKED = Object.new # :nodoc:
5
+
6
6
  # Asserts that an expression is not truthy. Passes if <tt>object</tt> is
7
7
  # +nil+ or +false+. "Truthy" means "considered true in a conditional"
8
8
  # like <tt>if foo</tt>.
@@ -19,6 +19,17 @@ module ActiveSupport
19
19
  assert !object, message
20
20
  end
21
21
 
22
+ # Assertion that the block should not raise an exception.
23
+ #
24
+ # Passes if evaluated code in the yielded block raises no exception.
25
+ #
26
+ # assert_nothing_raised do
27
+ # perform_service(param: 'no_exception')
28
+ # end
29
+ def assert_nothing_raised
30
+ yield
31
+ end
32
+
22
33
  # Test numeric difference between the return value of an expression as a
23
34
  # result of what is evaluated in the yielded block.
24
35
  #
@@ -94,6 +105,93 @@ module ActiveSupport
94
105
  def assert_no_difference(expression, message = nil, &block)
95
106
  assert_difference expression, 0, message, &block
96
107
  end
108
+
109
+ # Assertion that the result of evaluating an expression is changed before
110
+ # and after invoking the passed in block.
111
+ #
112
+ # assert_changes 'Status.all_good?' do
113
+ # post :create, params: { status: { ok: false } }
114
+ # end
115
+ #
116
+ # You can pass the block as a string to be evaluated in the context of
117
+ # the block. A lambda can be passed for the block as well.
118
+ #
119
+ # assert_changes -> { Status.all_good? } do
120
+ # post :create, params: { status: { ok: false } }
121
+ # end
122
+ #
123
+ # The assertion is useful to test side effects. The passed block can be
124
+ # anything that can be converted to string with #to_s.
125
+ #
126
+ # assert_changes :@object do
127
+ # @object = 42
128
+ # end
129
+ #
130
+ # The keyword arguments :from and :to can be given to specify the
131
+ # expected initial value and the expected value after the block was
132
+ # executed.
133
+ #
134
+ # assert_changes :@object, from: nil, to: :foo do
135
+ # @object = :foo
136
+ # end
137
+ #
138
+ # An error message can be specified.
139
+ #
140
+ # assert_changes -> { Status.all_good? }, 'Expected the status to be bad' do
141
+ # post :create, params: { status: { incident: true } }
142
+ # end
143
+ def assert_changes(expression, message = nil, from: UNTRACKED, to: UNTRACKED, &block)
144
+ exp = expression.respond_to?(:call) ? expression : -> { eval(expression.to_s, block.binding) }
145
+
146
+ before = exp.call
147
+ retval = yield
148
+
149
+ unless from == UNTRACKED
150
+ error = "#{expression.inspect} isn't #{from.inspect}"
151
+ error = "#{message}.\n#{error}" if message
152
+ assert from === before, error
153
+ end
154
+
155
+ after = exp.call
156
+
157
+ if to == UNTRACKED
158
+ error = "#{expression.inspect} didn't changed"
159
+ error = "#{message}.\n#{error}" if message
160
+ assert_not_equal before, after, error
161
+ else
162
+ error = "#{expression.inspect} didn't change to #{to}"
163
+ error = "#{message}.\n#{error}" if message
164
+ assert to === after, error
165
+ end
166
+
167
+ retval
168
+ end
169
+
170
+ # Assertion that the result of evaluating an expression is changed before
171
+ # and after invoking the passed in block.
172
+ #
173
+ # assert_no_changes 'Status.all_good?' do
174
+ # post :create, params: { status: { ok: true } }
175
+ # end
176
+ #
177
+ # An error message can be specified.
178
+ #
179
+ # assert_no_changes -> { Status.all_good? }, 'Expected the status to be good' do
180
+ # post :create, params: { status: { ok: false } }
181
+ # end
182
+ def assert_no_changes(expression, message = nil, &block)
183
+ exp = expression.respond_to?(:call) ? expression : -> { eval(expression.to_s, block.binding) }
184
+
185
+ before = exp.call
186
+ retval = yield
187
+ after = exp.call
188
+
189
+ error = "#{expression.inspect} did change to #{after}"
190
+ error = "#{message}.\n#{error}" if message
191
+ assert_equal before, after, error
192
+
193
+ retval
194
+ end
97
195
  end
98
196
  end
99
197
  end
@@ -1,5 +1,9 @@
1
- gem 'minitest'
1
+ gem "minitest"
2
2
 
3
- require 'minitest'
3
+ require "minitest"
4
+
5
+ if Minitest.respond_to?(:run_via) && !Minitest.run_via.set?
6
+ Minitest.run_via = :ruby
7
+ end
4
8
 
5
9
  Minitest.autorun
@@ -44,7 +44,6 @@ module ActiveSupport
44
44
  end
45
45
  end
46
46
  end
47
-
48
47
  end
49
48
  end
50
49
  end
@@ -9,7 +9,7 @@ module ActiveSupport
9
9
  # ...
10
10
  # end
11
11
  def test(name, &block)
12
- test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
12
+ test_name = "test_#{name.gsub(/\s+/, '_')}".to_sym
13
13
  defined = method_defined? test_name
14
14
  raise "#{test_name} is already defined in #{self}" if defined
15
15
  if block_given?
@@ -1,4 +1,5 @@
1
- require 'active_support/deprecation'
1
+ require "active_support/deprecation"
2
+ require "active_support/core_ext/regexp"
2
3
 
3
4
  module ActiveSupport
4
5
  module Testing
@@ -8,7 +9,7 @@ module ActiveSupport
8
9
  assert !warnings.empty?, "Expected a deprecation warning within the block but received none"
9
10
  if match
10
11
  match = Regexp.new(Regexp.escape(match)) unless match.is_a?(Regexp)
11
- assert warnings.any? { |w| w =~ match }, "No deprecation warning matched #{match}: #{warnings.join(', ')}"
12
+ assert warnings.any? { |w| match.match?(w) }, "No deprecation warning matched #{match}: #{warnings.join(', ')}"
12
13
  end
13
14
  result
14
15
  end
@@ -1,7 +1,7 @@
1
1
  module ActiveSupport
2
2
  module Testing
3
3
  module Isolation
4
- require 'thread'
4
+ require "thread"
5
5
 
6
6
  def self.included(klass) #:nodoc:
7
7
  klass.class_eval do
@@ -13,17 +13,6 @@ module ActiveSupport
13
13
  !ENV["NO_FORK"] && Process.respond_to?(:fork)
14
14
  end
15
15
 
16
- @@class_setup_mutex = Mutex.new
17
-
18
- def _run_class_setup # class setup method should only happen in parent
19
- @@class_setup_mutex.synchronize do
20
- unless defined?(@@ran_class_setup) || ENV['ISOLATION_TEST']
21
- self.class.setup if self.class.respond_to?(:setup)
22
- @@ran_class_setup = true
23
- end
24
- end
25
- end
26
-
27
16
  def run
28
17
  serialized = run_in_isolation do
29
18
  super
@@ -54,7 +43,7 @@ module ActiveSupport
54
43
  end
55
44
  }
56
45
  end
57
- result = Marshal.dump(self.dup)
46
+ result = Marshal.dump(dup)
58
47
  end
59
48
 
60
49
  write.puts [result].pack("m")
@@ -79,23 +68,25 @@ module ActiveSupport
79
68
  if ENV["ISOLATION_TEST"]
80
69
  yield
81
70
  File.open(ENV["ISOLATION_OUTPUT"], "w") do |file|
82
- file.puts [Marshal.dump(self.dup)].pack("m")
71
+ file.puts [Marshal.dump(dup)].pack("m")
83
72
  end
84
73
  exit!
85
74
  else
86
75
  Tempfile.open("isolation") do |tmpfile|
87
76
  env = {
88
- 'ISOLATION_TEST' => self.class.name,
89
- 'ISOLATION_OUTPUT' => tmpfile.path
77
+ "ISOLATION_TEST" => self.class.name,
78
+ "ISOLATION_OUTPUT" => tmpfile.path
90
79
  }
91
80
 
92
- load_paths = $-I.map {|p| "-I\"#{File.expand_path(p)}\"" }.join(" ")
93
- orig_args = ORIG_ARGV.join(" ")
94
- test_opts = "-n#{self.class.name}##{self.name}"
95
- command = "#{Gem.ruby} #{load_paths} #{$0} '#{orig_args}' #{test_opts}"
81
+ test_opts = "-n#{self.class.name}##{name}"
82
+
83
+ load_path_args = []
84
+ $-I.each do |p|
85
+ load_path_args << "-I"
86
+ load_path_args << File.expand_path(p)
87
+ end
96
88
 
97
- # IO.popen lets us pass env in a cross-platform way
98
- child = IO.popen(env, command)
89
+ child = IO.popen([env, Gem.ruby, *load_path_args, $0, *ORIG_ARGV, test_opts])
99
90
 
100
91
  begin
101
92
  Process.wait(child.pid)
@@ -1,4 +1,4 @@
1
- require 'minitest/mock'
1
+ require "minitest/mock"
2
2
 
3
3
  module ActiveSupport
4
4
  module Testing
@@ -1,5 +1,5 @@
1
- require 'active_support/concern'
2
- require 'active_support/callbacks'
1
+ require "active_support/concern"
2
+ require "active_support/callbacks"
3
3
 
4
4
  module ActiveSupport
5
5
  module Testing
@@ -3,40 +3,40 @@ module ActiveSupport
3
3
  module Stream #:nodoc:
4
4
  private
5
5
 
6
- def silence_stream(stream)
7
- old_stream = stream.dup
8
- stream.reopen(IO::NULL)
9
- stream.sync = true
10
- yield
11
- ensure
12
- stream.reopen(old_stream)
13
- old_stream.close
14
- end
6
+ def silence_stream(stream)
7
+ old_stream = stream.dup
8
+ stream.reopen(IO::NULL)
9
+ stream.sync = true
10
+ yield
11
+ ensure
12
+ stream.reopen(old_stream)
13
+ old_stream.close
14
+ end
15
15
 
16
- def quietly
17
- silence_stream(STDOUT) do
18
- silence_stream(STDERR) do
19
- yield
16
+ def quietly
17
+ silence_stream(STDOUT) do
18
+ silence_stream(STDERR) do
19
+ yield
20
+ end
20
21
  end
21
22
  end
22
- end
23
23
 
24
- def capture(stream)
25
- stream = stream.to_s
26
- captured_stream = Tempfile.new(stream)
27
- stream_io = eval("$#{stream}")
28
- origin_stream = stream_io.dup
29
- stream_io.reopen(captured_stream)
24
+ def capture(stream)
25
+ stream = stream.to_s
26
+ captured_stream = Tempfile.new(stream)
27
+ stream_io = eval("$#{stream}")
28
+ origin_stream = stream_io.dup
29
+ stream_io.reopen(captured_stream)
30
30
 
31
- yield
31
+ yield
32
32
 
33
- stream_io.rewind
34
- return captured_stream.read
35
- ensure
36
- captured_stream.close
37
- captured_stream.unlink
38
- stream_io.reopen(origin_stream)
39
- end
33
+ stream_io.rewind
34
+ return captured_stream.read
35
+ ensure
36
+ captured_stream.close
37
+ captured_stream.unlink
38
+ stream_io.reopen(origin_stream)
39
+ end
40
40
  end
41
41
  end
42
42
  end
@@ -8,7 +8,7 @@ module ActiveSupport
8
8
  def before_setup
9
9
  if tagged_logger && tagged_logger.info?
10
10
  heading = "#{self.class}: #{name}"
11
- divider = '-' * heading.size
11
+ divider = "-" * heading.size
12
12
  tagged_logger.info divider
13
13
  tagged_logger.info heading
14
14
  tagged_logger.info divider
@@ -1,4 +1,5 @@
1
- require "active_support/core_ext/time/calculations"
1
+ require "active_support/core_ext/string/strip" # for strip_heredoc
2
+ require "concurrent/map"
2
3
 
3
4
  module ActiveSupport
4
5
  module Testing
@@ -6,29 +7,33 @@ module ActiveSupport
6
7
  Stub = Struct.new(:object, :method_name, :original_method)
7
8
 
8
9
  def initialize
9
- @stubs = {}
10
+ @stubs = Concurrent::Map.new { |h, k| h[k] = {} }
10
11
  end
11
12
 
12
13
  def stub_object(object, method_name, &block)
13
- key = [object.object_id, method_name]
14
-
15
- if stub = @stubs[key]
14
+ if stub = stubbing(object, method_name)
16
15
  unstub_object(stub)
17
16
  end
18
17
 
19
18
  new_name = "__simple_stub__#{method_name}"
20
19
 
21
- @stubs[key] = Stub.new(object, method_name, new_name)
20
+ @stubs[object.object_id][method_name] = Stub.new(object, method_name, new_name)
22
21
 
23
22
  object.singleton_class.send :alias_method, new_name, method_name
24
23
  object.define_singleton_method(method_name, &block)
25
24
  end
26
25
 
27
26
  def unstub_all!
28
- @stubs.each_value do |stub|
29
- unstub_object(stub)
27
+ @stubs.each_value do |object_stubs|
28
+ object_stubs.each_value do |stub|
29
+ unstub_object(stub)
30
+ end
30
31
  end
31
- @stubs = {}
32
+ @stubs.clear
33
+ end
34
+
35
+ def stubbing(object, method_name)
36
+ @stubs[object.object_id][method_name]
32
37
  end
33
38
 
34
39
  private
@@ -68,7 +73,7 @@ module ActiveSupport
68
73
  # +Date.today+, and +DateTime.now+ to return the time or date passed into this method.
69
74
  #
70
75
  # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
71
- # travel_to Time.new(2004, 11, 24, 01, 04, 44)
76
+ # travel_to Time.zone.local(2004, 11, 24, 01, 04, 44)
72
77
  # Time.current # => Wed, 24 Nov 2004 01:04:44 EST -05:00
73
78
  # Date.current # => Wed, 24 Nov 2004
74
79
  # DateTime.current # => Wed, 24 Nov 2004 01:04:44 -0500
@@ -90,11 +95,39 @@ module ActiveSupport
90
95
  # state at the end of the block:
91
96
  #
92
97
  # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
93
- # travel_to Time.new(2004, 11, 24, 01, 04, 44) do
98
+ # travel_to Time.zone.local(2004, 11, 24, 01, 04, 44) do
94
99
  # Time.current # => Wed, 24 Nov 2004 01:04:44 EST -05:00
95
100
  # end
96
101
  # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
97
102
  def travel_to(date_or_time)
103
+ if block_given? && simple_stubs.stubbing(Time, :now)
104
+ travel_to_nested_block_call = <<-MSG.strip_heredoc
105
+
106
+ Calling `travel_to` with a block, when we have previously already made a call to `travel_to`, can lead to confusing time stubbing.
107
+
108
+ Instead of:
109
+
110
+ travel_to 2.days.from_now do
111
+ # 2 days from today
112
+ travel_to 3.days.from_now do
113
+ # 5 days from today
114
+ end
115
+ end
116
+
117
+ preferred way to achieve above is:
118
+
119
+ travel 2.days do
120
+ # 2 days from today
121
+ end
122
+
123
+ travel 5.days do
124
+ # 5 days from today
125
+ end
126
+
127
+ MSG
128
+ raise travel_to_nested_block_call
129
+ end
130
+
98
131
  if date_or_time.is_a?(Date) && !date_or_time.is_a?(DateTime)
99
132
  now = date_or_time.midnight.to_time
100
133
  else
@@ -118,7 +151,7 @@ module ActiveSupport
118
151
  # `travel` and `travel_to`.
119
152
  #
120
153
  # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
121
- # travel_to Time.new(2004, 11, 24, 01, 04, 44)
154
+ # travel_to Time.zone.local(2004, 11, 24, 01, 04, 44)
122
155
  # Time.current # => Wed, 24 Nov 2004 01:04:44 EST -05:00
123
156
  # travel_back
124
157
  # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00