activesupport 3.2.22.5 → 4.0.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 (214) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +325 -136
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +4 -2
  5. data/lib/active_support.rb +8 -21
  6. data/lib/active_support/backtrace_cleaner.rb +33 -25
  7. data/lib/active_support/basic_object.rb +7 -17
  8. data/lib/active_support/benchmarkable.rb +19 -15
  9. data/lib/active_support/buffered_logger.rb +9 -113
  10. data/lib/active_support/cache.rb +203 -171
  11. data/lib/active_support/cache/file_store.rb +12 -12
  12. data/lib/active_support/cache/mem_cache_store.rb +24 -30
  13. data/lib/active_support/cache/memory_store.rb +2 -0
  14. data/lib/active_support/callbacks.rb +195 -247
  15. data/lib/active_support/concern.rb +16 -23
  16. data/lib/active_support/concurrency/latch.rb +27 -0
  17. data/lib/active_support/configurable.rb +69 -12
  18. data/lib/active_support/core_ext.rb +1 -0
  19. data/lib/active_support/core_ext/array.rb +0 -1
  20. data/lib/active_support/core_ext/array/access.rb +17 -9
  21. data/lib/active_support/core_ext/array/conversions.rb +113 -55
  22. data/lib/active_support/core_ext/array/extract_options.rb +2 -2
  23. data/lib/active_support/core_ext/array/grouping.rb +21 -22
  24. data/lib/active_support/core_ext/array/uniq_by.rb +12 -9
  25. data/lib/active_support/core_ext/array/wrap.rb +11 -14
  26. data/lib/active_support/core_ext/big_decimal/conversions.rb +7 -24
  27. data/lib/active_support/core_ext/class/attribute.rb +12 -8
  28. data/lib/active_support/core_ext/class/attribute_accessors.rb +14 -12
  29. data/lib/active_support/core_ext/class/delegating_attributes.rb +15 -19
  30. data/lib/active_support/core_ext/class/subclasses.rb +11 -5
  31. data/lib/active_support/core_ext/date.rb +6 -0
  32. data/lib/active_support/core_ext/date/calculations.rb +34 -188
  33. data/lib/active_support/core_ext/date/conversions.rb +16 -38
  34. data/lib/active_support/core_ext/date/infinite_comparable.rb +5 -0
  35. data/lib/active_support/core_ext/date/zones.rb +25 -2
  36. data/lib/active_support/core_ext/date_and_time/calculations.rb +232 -0
  37. data/lib/active_support/core_ext/date_time.rb +5 -0
  38. data/lib/active_support/core_ext/date_time/acts_like.rb +0 -1
  39. data/lib/active_support/core_ext/date_time/calculations.rb +73 -65
  40. data/lib/active_support/core_ext/date_time/conversions.rb +21 -33
  41. data/lib/active_support/core_ext/date_time/infinite_comparable.rb +5 -0
  42. data/lib/active_support/core_ext/date_time/zones.rb +11 -8
  43. data/lib/active_support/core_ext/enumerable.rb +26 -73
  44. data/lib/active_support/core_ext/file.rb +0 -1
  45. data/lib/active_support/core_ext/file/atomic.rb +27 -11
  46. data/lib/active_support/core_ext/hash.rb +0 -1
  47. data/lib/active_support/core_ext/hash/conversions.rb +145 -79
  48. data/lib/active_support/core_ext/hash/deep_merge.rb +14 -8
  49. data/lib/active_support/core_ext/hash/diff.rb +5 -4
  50. data/lib/active_support/core_ext/hash/except.rb +1 -9
  51. data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -5
  52. data/lib/active_support/core_ext/hash/keys.rb +108 -24
  53. data/lib/active_support/core_ext/hash/reverse_merge.rb +2 -3
  54. data/lib/active_support/core_ext/hash/slice.rb +12 -12
  55. data/lib/active_support/core_ext/infinite_comparable.rb +35 -0
  56. data/lib/active_support/core_ext/integer/inflections.rb +13 -1
  57. data/lib/active_support/core_ext/integer/time.rb +17 -12
  58. data/lib/active_support/core_ext/kernel/debugger.rb +2 -2
  59. data/lib/active_support/core_ext/kernel/reporting.rb +36 -22
  60. data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -7
  61. data/lib/active_support/core_ext/load_error.rb +7 -5
  62. data/lib/active_support/core_ext/logger.rb +7 -23
  63. data/lib/active_support/core_ext/marshal.rb +19 -0
  64. data/lib/active_support/core_ext/module.rb +1 -3
  65. data/lib/active_support/core_ext/module/aliasing.rb +8 -9
  66. data/lib/active_support/core_ext/module/anonymous.rb +2 -7
  67. data/lib/active_support/core_ext/module/attr_internal.rb +0 -1
  68. data/lib/active_support/core_ext/module/attribute_accessors.rb +12 -10
  69. data/lib/active_support/core_ext/module/delegation.rb +57 -40
  70. data/lib/active_support/core_ext/module/deprecation.rb +19 -3
  71. data/lib/active_support/core_ext/module/introspection.rb +17 -27
  72. data/lib/active_support/core_ext/module/qualified_const.rb +8 -20
  73. data/lib/active_support/core_ext/module/remove_method.rb +1 -5
  74. data/lib/active_support/core_ext/numeric.rb +2 -0
  75. data/lib/active_support/core_ext/numeric/conversions.rb +135 -0
  76. data/lib/active_support/core_ext/numeric/infinite_comparable.rb +9 -0
  77. data/lib/active_support/core_ext/numeric/time.rb +6 -6
  78. data/lib/active_support/core_ext/object.rb +1 -0
  79. data/lib/active_support/core_ext/object/acts_like.rb +4 -4
  80. data/lib/active_support/core_ext/object/blank.rb +7 -23
  81. data/lib/active_support/core_ext/object/deep_dup.rb +46 -0
  82. data/lib/active_support/core_ext/object/duplicable.rb +1 -30
  83. data/lib/active_support/core_ext/object/inclusion.rb +6 -6
  84. data/lib/active_support/core_ext/object/instance_variables.rb +7 -12
  85. data/lib/active_support/core_ext/object/to_json.rb +8 -0
  86. data/lib/active_support/core_ext/object/to_param.rb +5 -2
  87. data/lib/active_support/core_ext/object/try.rb +46 -25
  88. data/lib/active_support/core_ext/object/with_options.rb +7 -8
  89. data/lib/active_support/core_ext/proc.rb +3 -0
  90. data/lib/active_support/core_ext/range.rb +0 -2
  91. data/lib/active_support/core_ext/range/conversions.rb +0 -2
  92. data/lib/active_support/core_ext/range/include_range.rb +1 -1
  93. data/lib/active_support/core_ext/range/overlaps.rb +1 -1
  94. data/lib/active_support/core_ext/string.rb +2 -2
  95. data/lib/active_support/core_ext/string/access.rb +95 -90
  96. data/lib/active_support/core_ext/string/conversions.rb +29 -38
  97. data/lib/active_support/core_ext/string/encoding.rb +6 -9
  98. data/lib/active_support/core_ext/string/filters.rb +24 -18
  99. data/lib/active_support/core_ext/string/indent.rb +43 -0
  100. data/lib/active_support/core_ext/string/inflections.rb +70 -60
  101. data/lib/active_support/core_ext/string/inquiry.rb +2 -2
  102. data/lib/active_support/core_ext/string/multibyte.rb +41 -64
  103. data/lib/active_support/core_ext/string/output_safety.rb +59 -51
  104. data/lib/active_support/core_ext/string/zones.rb +13 -0
  105. data/lib/active_support/core_ext/struct.rb +6 -0
  106. data/lib/active_support/core_ext/thread.rb +74 -0
  107. data/lib/active_support/core_ext/time.rb +6 -0
  108. data/lib/active_support/core_ext/time/calculations.rb +105 -193
  109. data/lib/active_support/core_ext/time/conversions.rb +27 -51
  110. data/lib/active_support/core_ext/time/infinite_comparable.rb +5 -0
  111. data/lib/active_support/core_ext/time/marshal.rb +0 -27
  112. data/lib/active_support/core_ext/time/zones.rb +27 -17
  113. data/lib/active_support/core_ext/uri.rb +13 -17
  114. data/lib/active_support/dependencies.rb +160 -141
  115. data/lib/active_support/dependencies/autoload.rb +47 -20
  116. data/lib/active_support/deprecation.rb +39 -14
  117. data/lib/active_support/deprecation/behaviors.rb +44 -30
  118. data/lib/active_support/deprecation/instance_delegator.rb +24 -0
  119. data/lib/active_support/deprecation/method_wrappers.rb +33 -18
  120. data/lib/active_support/deprecation/proxy_wrappers.rb +58 -13
  121. data/lib/active_support/deprecation/reporting.rb +40 -11
  122. data/lib/active_support/descendants_tracker.rb +34 -19
  123. data/lib/active_support/duration.rb +6 -8
  124. data/lib/active_support/file_update_checker.rb +63 -47
  125. data/lib/active_support/gzip.rb +11 -5
  126. data/lib/active_support/hash_with_indifferent_access.rb +112 -37
  127. data/lib/active_support/i18n.rb +4 -0
  128. data/lib/active_support/i18n_railtie.rb +5 -22
  129. data/lib/active_support/inflections.rb +14 -12
  130. data/lib/active_support/inflector/inflections.rb +108 -71
  131. data/lib/active_support/inflector/methods.rb +181 -160
  132. data/lib/active_support/inflector/transliterate.rb +16 -17
  133. data/lib/active_support/json/decoding.rb +18 -17
  134. data/lib/active_support/json/encoding.rb +93 -39
  135. data/lib/active_support/json/variable.rb +10 -1
  136. data/lib/active_support/key_generator.rb +75 -0
  137. data/lib/active_support/lazy_load_hooks.rb +21 -19
  138. data/lib/active_support/locale/en.yml +100 -3
  139. data/lib/active_support/log_subscriber.rb +56 -36
  140. data/lib/active_support/log_subscriber/test_helper.rb +18 -15
  141. data/lib/active_support/logger.rb +57 -0
  142. data/lib/active_support/logger_silence.rb +24 -0
  143. data/lib/active_support/message_encryptor.rb +32 -29
  144. data/lib/active_support/message_verifier.rb +8 -14
  145. data/lib/active_support/multibyte.rb +5 -28
  146. data/lib/active_support/multibyte/chars.rb +80 -333
  147. data/lib/active_support/multibyte/unicode.rb +74 -64
  148. data/lib/active_support/notifications.rb +57 -25
  149. data/lib/active_support/notifications/fanout.rb +105 -18
  150. data/lib/active_support/notifications/instrumenter.rb +32 -13
  151. data/lib/active_support/number_helper.rb +636 -0
  152. data/lib/active_support/ordered_hash.rb +8 -190
  153. data/lib/active_support/ordered_options.rb +21 -23
  154. data/lib/active_support/proxy_object.rb +13 -0
  155. data/lib/active_support/rails.rb +27 -0
  156. data/lib/active_support/railtie.rb +12 -32
  157. data/lib/active_support/rescuable.rb +9 -4
  158. data/lib/active_support/string_inquirer.rb +13 -8
  159. data/lib/active_support/tagged_logging.rb +51 -73
  160. data/lib/active_support/test_case.rb +46 -17
  161. data/lib/active_support/testing/assertions.rb +56 -26
  162. data/lib/active_support/testing/autorun.rb +5 -0
  163. data/lib/active_support/testing/constant_lookup.rb +52 -0
  164. data/lib/active_support/testing/declarative.rb +1 -1
  165. data/lib/active_support/testing/deprecation.rb +0 -19
  166. data/lib/active_support/testing/isolation.rb +25 -58
  167. data/lib/active_support/testing/pending.rb +5 -43
  168. data/lib/active_support/testing/setup_and_teardown.rb +6 -92
  169. data/lib/active_support/testing/tagged_logging.rb +25 -0
  170. data/lib/active_support/time.rb +6 -21
  171. data/lib/active_support/time_with_zone.rb +78 -43
  172. data/lib/active_support/values/time_zone.rb +77 -58
  173. data/lib/active_support/values/unicode_tables.dat +0 -0
  174. data/lib/active_support/version.rb +4 -4
  175. data/lib/active_support/xml_mini.rb +35 -17
  176. data/lib/active_support/xml_mini/jdom.rb +9 -17
  177. data/lib/active_support/xml_mini/libxml.rb +1 -2
  178. data/lib/active_support/xml_mini/libxmlsax.rb +1 -2
  179. data/lib/active_support/xml_mini/nokogiri.rb +1 -2
  180. data/lib/active_support/xml_mini/nokogirisax.rb +1 -2
  181. data/lib/active_support/xml_mini/rexml.rb +6 -8
  182. metadata +107 -77
  183. data/lib/active_support/base64.rb +0 -54
  184. data/lib/active_support/core_ext/array/random_access.rb +0 -30
  185. data/lib/active_support/core_ext/date/freeze.rb +0 -33
  186. data/lib/active_support/core_ext/exception.rb +0 -3
  187. data/lib/active_support/core_ext/file/path.rb +0 -5
  188. data/lib/active_support/core_ext/float.rb +0 -1
  189. data/lib/active_support/core_ext/float/rounding.rb +0 -19
  190. data/lib/active_support/core_ext/hash/deep_dup.rb +0 -18
  191. data/lib/active_support/core_ext/io.rb +0 -15
  192. data/lib/active_support/core_ext/module/method_names.rb +0 -14
  193. data/lib/active_support/core_ext/module/synchronization.rb +0 -45
  194. data/lib/active_support/core_ext/process.rb +0 -1
  195. data/lib/active_support/core_ext/process/daemon.rb +0 -23
  196. data/lib/active_support/core_ext/range/blockless_step.rb +0 -29
  197. data/lib/active_support/core_ext/range/cover.rb +0 -3
  198. data/lib/active_support/core_ext/rexml.rb +0 -46
  199. data/lib/active_support/core_ext/string/interpolation.rb +0 -2
  200. data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +0 -10
  201. data/lib/active_support/memoizable.rb +0 -116
  202. data/lib/active_support/multibyte/exceptions.rb +0 -8
  203. data/lib/active_support/multibyte/utils.rb +0 -60
  204. data/lib/active_support/ruby/shim.rb +0 -22
  205. data/lib/active_support/security_utils.rb +0 -27
  206. data/lib/active_support/testing/mochaing.rb +0 -7
  207. data/lib/active_support/testing/performance.rb +0 -317
  208. data/lib/active_support/testing/performance/jruby.rb +0 -115
  209. data/lib/active_support/testing/performance/rubinius.rb +0 -113
  210. data/lib/active_support/testing/performance/ruby.rb +0 -152
  211. data/lib/active_support/testing/performance/ruby/mri.rb +0 -57
  212. data/lib/active_support/testing/performance/ruby/yarv.rb +0 -57
  213. data/lib/active_support/time/autoload.rb +0 -5
  214. data/lib/active_support/whiny_nil.rb +0 -24
@@ -1,4 +1,6 @@
1
1
  require 'rbconfig'
2
+ require 'minitest/parallel_each'
3
+
2
4
  module ActiveSupport
3
5
  module Testing
4
6
  class RemoteError < StandardError
@@ -41,61 +43,41 @@ module ActiveSupport
41
43
  end
42
44
 
43
45
  module Isolation
44
- def self.forking_env?
45
- !ENV["NO_FORK"] && ((RbConfig::CONFIG['host_os'] !~ /mswin|mingw/) && (RUBY_PLATFORM !~ /java/))
46
- end
46
+ require 'thread'
47
47
 
48
- def self.included(base)
49
- if defined?(::MiniTest) && base < ::MiniTest::Unit::TestCase
50
- base.send :include, MiniTest
51
- elsif defined?(Test::Unit)
52
- base.send :include, TestUnit
53
- end
48
+ def self.included(klass) #:nodoc:
49
+ klass.extend(Module.new {
50
+ def test_methods
51
+ ParallelEach.new super
52
+ end
53
+ })
54
54
  end
55
55
 
56
- def _run_class_setup # class setup method should only happen in parent
57
- unless defined?(@@ran_class_setup) || ENV['ISOLATION_TEST']
58
- self.class.setup if self.class.respond_to?(:setup)
59
- @@ran_class_setup = true
60
- end
56
+ def self.forking_env?
57
+ !ENV["NO_FORK"] && ((RbConfig::CONFIG['host_os'] !~ /mswin|mingw/) && (RUBY_PLATFORM !~ /java/))
61
58
  end
62
59
 
63
- module TestUnit
64
- def run(result)
65
- _run_class_setup
60
+ @@class_setup_mutex = Mutex.new
66
61
 
67
- yield(Test::Unit::TestCase::STARTED, name)
68
-
69
- @_result = result
70
-
71
- serialized = run_in_isolation do |proxy|
72
- begin
73
- super(proxy) { }
74
- rescue Exception => e
75
- proxy.add_error(Test::Unit::Error.new(name, e))
76
- end
62
+ def _run_class_setup # class setup method should only happen in parent
63
+ @@class_setup_mutex.synchronize do
64
+ unless defined?(@@ran_class_setup) || ENV['ISOLATION_TEST']
65
+ self.class.setup if self.class.respond_to?(:setup)
66
+ @@ran_class_setup = true
77
67
  end
78
-
79
- retval, proxy = Marshal.load(serialized)
80
- proxy.__replay__(@_result)
81
-
82
- yield(Test::Unit::TestCase::FINISHED, name)
83
- retval
84
68
  end
85
69
  end
86
70
 
87
- module MiniTest
88
- def run(runner)
89
- _run_class_setup
71
+ def run(runner)
72
+ _run_class_setup
90
73
 
91
- serialized = run_in_isolation do |isolated_runner|
92
- super(isolated_runner)
93
- end
94
-
95
- retval, proxy = Marshal.load(serialized)
96
- proxy.__replay__(runner)
97
- retval
74
+ serialized = run_in_isolation do |isolated_runner|
75
+ super(isolated_runner)
98
76
  end
77
+
78
+ retval, proxy = Marshal.load(serialized)
79
+ proxy.__replay__(runner)
80
+ retval
99
81
  end
100
82
 
101
83
  module Forking
@@ -153,18 +135,3 @@ module ActiveSupport
153
135
  end
154
136
  end
155
137
  end
156
-
157
- # Only in subprocess for windows / jruby.
158
- if ENV['ISOLATION_TEST']
159
- begin
160
- require "test/unit/collector/objectspace"
161
- rescue LoadError => e
162
- raise LoadError, "Please add test-unit gem to your Gemfile: `gem 'test-unit', '~> 3.0'` (#{e.message})", e.backtrace
163
- end
164
-
165
- class Test::Unit::Collector::ObjectSpace
166
- def include?(test)
167
- super && test.method_name == ENV['ISOLATION_TEST']
168
- end
169
- end
170
- end
@@ -1,52 +1,14 @@
1
- # Some code from jeremymcanally's "pending"
2
- # https://github.com/jeremymcanally/pending/tree/master
1
+ require 'active_support/deprecation'
3
2
 
4
3
  module ActiveSupport
5
4
  module Testing
6
- module Pending
7
-
8
- unless defined?(Spec)
9
-
10
- @@pending_cases = []
11
- @@at_exit = false
12
-
5
+ module Pending # :nodoc:
6
+ unless defined?(Spec)
13
7
  def pending(description = "", &block)
14
- if defined?(::MiniTest)
15
- skip(description.blank? ? nil : description)
16
- else
17
- if description.is_a?(Symbol)
18
- is_pending = $tags[description]
19
- return block.call unless is_pending
20
- end
21
-
22
- if block_given?
23
- failed = false
24
-
25
- begin
26
- block.call
27
- rescue Exception
28
- failed = true
29
- end
30
-
31
- flunk("<#{description}> did not fail.") unless failed
32
- end
33
-
34
- caller[0] =~ (/(.*):(.*):in `(.*)'/)
35
- @@pending_cases << "#{$3} at #{$1}, line #{$2}"
36
- print "P"
37
-
38
- @@at_exit ||= begin
39
- at_exit do
40
- puts "\nPending Cases:"
41
- @@pending_cases.each do |test_case|
42
- puts test_case
43
- end
44
- end
45
- end
46
- end
8
+ ActiveSupport::Deprecation.warn("#pending is deprecated and will be removed in Rails 4.1, please use #skip instead.")
9
+ skip(description.blank? ? nil : description)
47
10
  end
48
11
  end
49
-
50
12
  end
51
13
  end
52
14
  end
@@ -9,12 +9,6 @@ module ActiveSupport
9
9
  included do
10
10
  include ActiveSupport::Callbacks
11
11
  define_callbacks :setup, :teardown
12
-
13
- if defined?(MiniTest::Assertions) && TestCase < MiniTest::Assertions
14
- include ForMiniTest
15
- else
16
- include ForClassicTestUnit
17
- end
18
12
  end
19
13
 
20
14
  module ClassMethods
@@ -27,94 +21,14 @@ module ActiveSupport
27
21
  end
28
22
  end
29
23
 
30
- module ForMiniTest
31
- PASSTHROUGH_EXCEPTIONS = MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS rescue [NoMemoryError, SignalException, Interrupt, SystemExit]
32
- def run(runner)
33
- result = '.'
34
- begin
35
- run_callbacks :setup do
36
- result = super
37
- end
38
- rescue *PASSTHROUGH_EXCEPTIONS => e
39
- raise e
40
- rescue Exception => e
41
- result = runner.puke(self.class, method_name, e)
42
- ensure
43
- begin
44
- run_callbacks :teardown
45
- rescue *PASSTHROUGH_EXCEPTIONS => e
46
- raise e
47
- rescue Exception => e
48
- result = runner.puke(self.class, method_name, e)
49
- end
50
- end
51
- result
52
- end
24
+ def before_setup
25
+ super
26
+ run_callbacks :setup
53
27
  end
54
28
 
55
- module ForClassicTestUnit
56
- # For compatibility with Ruby < 1.8.6
57
- PASSTHROUGH_EXCEPTIONS = Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS rescue [NoMemoryError, SignalException, Interrupt, SystemExit]
58
-
59
- # This redefinition is unfortunate but test/unit shows us no alternative.
60
- # Doubly unfortunate: hax to support Mocha's hax.
61
- def run(result)
62
- return if @method_name.to_s == "default_test"
63
-
64
- mocha_counter = retrieve_mocha_counter(self, result)
65
- yield(Test::Unit::TestCase::STARTED, name)
66
- @_result = result
67
-
68
- begin
69
- begin
70
- run_callbacks :setup do
71
- setup
72
- __send__(@method_name)
73
- mocha_verify(mocha_counter) if mocha_counter
74
- end
75
- rescue Mocha::ExpectationError => e
76
- add_failure(e.message, e.backtrace)
77
- rescue Test::Unit::AssertionFailedError => e
78
- add_failure(e.message, e.backtrace)
79
- rescue Exception => e
80
- raise if PASSTHROUGH_EXCEPTIONS.include?(e.class)
81
- add_error(e)
82
- ensure
83
- begin
84
- teardown
85
- run_callbacks :teardown
86
- rescue Mocha::ExpectationError => e
87
- add_failure(e.message, e.backtrace)
88
- rescue Test::Unit::AssertionFailedError => e
89
- add_failure(e.message, e.backtrace)
90
- rescue Exception => e
91
- raise if PASSTHROUGH_EXCEPTIONS.include?(e.class)
92
- add_error(e)
93
- end
94
- end
95
- ensure
96
- mocha_teardown if mocha_counter
97
- end
98
-
99
- result.add_run
100
- yield(Test::Unit::TestCase::FINISHED, name)
101
- end
102
-
103
- protected
104
-
105
- def retrieve_mocha_counter(test_case, result) #:nodoc:
106
- if respond_to?(:mocha_verify) # using mocha
107
- if defined?(Mocha::TestCaseAdapter::AssertionCounter)
108
- Mocha::TestCaseAdapter::AssertionCounter.new(result)
109
- elsif defined?(Mocha::Integration::TestUnit::AssertionCounter)
110
- Mocha::Integration::TestUnit::AssertionCounter.new(result)
111
- elsif defined?(Mocha::MonkeyPatching::TestUnit::AssertionCounter)
112
- Mocha::MonkeyPatching::TestUnit::AssertionCounter.new(result)
113
- else
114
- Mocha::Integration::AssertionCounter.new(test_case)
115
- end
116
- end
117
- end
29
+ def after_teardown
30
+ run_callbacks :teardown
31
+ super
118
32
  end
119
33
  end
120
34
  end
@@ -0,0 +1,25 @@
1
+ module ActiveSupport
2
+ module Testing
3
+ # Logs a "PostsControllerTest: test name" heading before each test to
4
+ # make test.log easier to search and follow along with.
5
+ module TaggedLogging #:nodoc:
6
+ attr_writer :tagged_logger
7
+
8
+ def before_setup
9
+ if tagged_logger
10
+ heading = "#{self.class}: #{__name__}"
11
+ divider = '-' * heading.size
12
+ tagged_logger.info divider
13
+ tagged_logger.info heading
14
+ tagged_logger.info divider
15
+ end
16
+ super
17
+ end
18
+
19
+ private
20
+ def tagged_logger
21
+ @tagged_logger ||= (defined?(Rails.logger) && Rails.logger)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -4,32 +4,17 @@ module ActiveSupport
4
4
  autoload :Duration, 'active_support/duration'
5
5
  autoload :TimeWithZone, 'active_support/time_with_zone'
6
6
  autoload :TimeZone, 'active_support/values/time_zone'
7
-
8
- on_load_all do
9
- [Duration, TimeWithZone, TimeZone]
10
- end
11
7
  end
12
8
 
13
9
  require 'date'
14
10
  require 'time'
15
11
 
16
- require 'active_support/core_ext/time/publicize_conversion_methods'
17
- require 'active_support/core_ext/time/marshal'
18
- require 'active_support/core_ext/time/acts_like'
19
- require 'active_support/core_ext/time/calculations'
20
- require 'active_support/core_ext/time/conversions'
21
- require 'active_support/core_ext/time/zones'
22
-
23
- require 'active_support/core_ext/date/acts_like'
24
- require 'active_support/core_ext/date/freeze'
25
- require 'active_support/core_ext/date/calculations'
26
- require 'active_support/core_ext/date/conversions'
27
- require 'active_support/core_ext/date/zones'
28
-
29
- require 'active_support/core_ext/date_time/acts_like'
30
- require 'active_support/core_ext/date_time/calculations'
31
- require 'active_support/core_ext/date_time/conversions'
32
- require 'active_support/core_ext/date_time/zones'
12
+ require 'active_support/core_ext/time'
13
+ require 'active_support/core_ext/date'
14
+ require 'active_support/core_ext/date_time'
33
15
 
34
16
  require 'active_support/core_ext/integer/time'
35
17
  require 'active_support/core_ext/numeric/time'
18
+
19
+ require 'active_support/core_ext/string/conversions'
20
+ require 'active_support/core_ext/string/zones'
@@ -1,14 +1,14 @@
1
- require "active_support/values/time_zone"
1
+ require 'active_support/values/time_zone'
2
2
  require 'active_support/core_ext/object/acts_like'
3
- require 'active_support/core_ext/object/inclusion'
4
3
 
5
4
  module ActiveSupport
6
- # A Time-like class that can represent a time in any time zone. Necessary because standard Ruby Time instances are
7
- # limited to UTC and the system's <tt>ENV['TZ']</tt> zone.
5
+ # A Time-like class that can represent a time in any time zone. Necessary
6
+ # because standard Ruby Time instances are limited to UTC and the
7
+ # system's <tt>ENV['TZ']</tt> zone.
8
8
  #
9
- # You shouldn't ever need to create a TimeWithZone instance directly via <tt>new</tt> . Instead use methods
10
- # +local+, +parse+, +at+ and +now+ on TimeZone instances, and +in_time_zone+ on Time and DateTime instances.
11
- # Examples:
9
+ # You shouldn't ever need to create a TimeWithZone instance directly via +new+.
10
+ # Instead use methods +local+, +parse+, +at+ and +now+ on TimeZone instances,
11
+ # and +in_time_zone+ on Time and DateTime instances.
12
12
  #
13
13
  # Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
14
14
  # Time.zone.local(2007, 2, 10, 15, 30, 45) # => Sat, 10 Feb 2007 15:30:45 EST -05:00
@@ -19,8 +19,8 @@ module ActiveSupport
19
19
  #
20
20
  # See Time and TimeZone for further documentation of these methods.
21
21
  #
22
- # TimeWithZone instances implement the same API as Ruby Time instances, so that Time and TimeWithZone instances are interchangeable.
23
- # Examples:
22
+ # TimeWithZone instances implement the same API as Ruby Time instances, so
23
+ # that Time and TimeWithZone instances are interchangeable.
24
24
  #
25
25
  # t = Time.zone.now # => Sun, 18 May 2008 13:27:25 EDT -04:00
26
26
  # t.hour # => 13
@@ -33,10 +33,11 @@ module ActiveSupport
33
33
  # t > Time.utc(1999) # => true
34
34
  # t.is_a?(Time) # => true
35
35
  # t.is_a?(ActiveSupport::TimeWithZone) # => true
36
- #
37
36
  class TimeWithZone
37
+
38
+ # Report class name as 'Time' to thwart type checking.
38
39
  def self.name
39
- 'Time' # Report class name as 'Time' to thwart type checking
40
+ 'Time'
40
41
  end
41
42
 
42
43
  include Comparable
@@ -72,33 +73,56 @@ module ActiveSupport
72
73
  utc.in_time_zone(new_zone)
73
74
  end
74
75
 
75
- # Returns a <tt>Time.local()</tt> instance of the simultaneous time in your system's <tt>ENV['TZ']</tt> zone
76
+ # Returns a <tt>Time.local()</tt> instance of the simultaneous time in your
77
+ # system's <tt>ENV['TZ']</tt> zone.
76
78
  def localtime
77
79
  utc.respond_to?(:getlocal) ? utc.getlocal : utc.to_time.getlocal
78
80
  end
79
81
  alias_method :getlocal, :localtime
80
82
 
83
+ # Returns true if the current time is within Daylight Savings Time for the
84
+ # specified time zone.
85
+ #
86
+ # Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
87
+ # Time.zone.parse("2012-5-30").dst? # => true
88
+ # Time.zone.parse("2012-11-30").dst? # => false
81
89
  def dst?
82
90
  period.dst?
83
91
  end
84
92
  alias_method :isdst, :dst?
85
93
 
94
+ # Returns true if the current time zone is set to UTC.
95
+ #
96
+ # Time.zone = 'UTC' # => 'UTC'
97
+ # Time.zone.now.utc? # => true
98
+ # Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
99
+ # Time.zone.now.utc? # => false
86
100
  def utc?
87
101
  time_zone.name == 'UTC'
88
102
  end
89
103
  alias_method :gmt?, :utc?
90
104
 
105
+ # Returns the offset from current time to UTC time in seconds.
91
106
  def utc_offset
92
107
  period.utc_total_offset
93
108
  end
94
109
  alias_method :gmt_offset, :utc_offset
95
110
  alias_method :gmtoff, :utc_offset
96
111
 
112
+ # Returns a formatted string of the offset from UTC, or an alternative
113
+ # string if the time zone is already UTC.
114
+ #
115
+ # Time.zone = 'Eastern Time (US & Canada)' # => "Eastern Time (US & Canada)"
116
+ # Time.zone.now.formatted_offset(true) # => "-05:00"
117
+ # Time.zone.now.formatted_offset(false) # => "-0500"
118
+ # Time.zone = 'UTC' # => "UTC"
119
+ # Time.zone.now.formatted_offset(true, "0") # => "0"
97
120
  def formatted_offset(colon = true, alternate_utc_string = nil)
98
121
  utc? && alternate_utc_string || TimeZone.seconds_to_utc_offset(utc_offset, colon)
99
122
  end
100
123
 
101
- # Time uses +zone+ to display the time zone abbreviation, so we're duck-typing it.
124
+ # Time uses +zone+ to display the time zone abbreviation, so we're
125
+ # duck-typing it.
102
126
  def zone
103
127
  period.zone_identifier.to_s
104
128
  end
@@ -116,11 +140,10 @@ module ActiveSupport
116
140
  end
117
141
  alias_method :iso8601, :xmlschema
118
142
 
119
- # Coerces time to a string for JSON encoding. The default format is ISO 8601. You can get
120
- # %Y/%m/%d %H:%M:%S +offset style by setting <tt>ActiveSupport::JSON::Encoding.use_standard_json_time_format</tt>
121
- # to false.
122
- #
123
- # ==== Examples
143
+ # Coerces time to a string for JSON encoding. The default format is ISO 8601.
144
+ # You can get %Y/%m/%d %H:%M:%S +offset style by setting
145
+ # <tt>ActiveSupport::JSON::Encoding.use_standard_json_time_format</tt>
146
+ # to +false+.
124
147
  #
125
148
  # # With ActiveSupport::JSON::Encoding.use_standard_json_time_format = true
126
149
  # Time.utc(2005,2,1,15,15,10).in_time_zone.to_json
@@ -129,10 +152,9 @@ module ActiveSupport
129
152
  # # With ActiveSupport::JSON::Encoding.use_standard_json_time_format = false
130
153
  # Time.utc(2005,2,1,15,15,10).in_time_zone.to_json
131
154
  # # => "2005/02/01 15:15:10 +0000"
132
- #
133
155
  def as_json(options = nil)
134
156
  if ActiveSupport::JSON::Encoding.use_standard_json_time_format
135
- xmlschema
157
+ xmlschema(3)
136
158
  else
137
159
  %(#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)})
138
160
  end
@@ -146,16 +168,18 @@ module ActiveSupport
146
168
  end
147
169
  end
148
170
 
149
- def to_yaml(options = {})
150
- return super if defined?(YAML::ENGINE) && !YAML::ENGINE.syck?
151
-
152
- utc.to_yaml(options)
153
- end
154
-
171
+ # Returns a string of the object's date and time in the format used by
172
+ # HTTP requests.
173
+ #
174
+ # Time.zone.now.httpdate # => "Tue, 01 Jan 2013 04:39:43 GMT"
155
175
  def httpdate
156
176
  utc.httpdate
157
177
  end
158
178
 
179
+ # Returns a string of the object's date and time in the RFC 2822 standard
180
+ # format.
181
+ #
182
+ # Time.zone.now.rfc2822 # => "Tue, 01 Jan 2013 04:51:39 +0000"
159
183
  def rfc2822
160
184
  to_s(:rfc822)
161
185
  end
@@ -174,14 +198,14 @@ module ActiveSupport
174
198
  end
175
199
  alias_method :to_formatted_s, :to_s
176
200
 
177
- # Replaces <tt>%Z</tt> and <tt>%z</tt> directives with +zone+ and +formatted_offset+, respectively, before passing to
178
- # Time#strftime, so that zone information is correct
201
+ # Replaces <tt>%Z</tt> and <tt>%z</tt> directives with +zone+ and
202
+ # +formatted_offset+, respectively, before passing to Time#strftime, so
203
+ # that zone information is correct
179
204
  def strftime(format)
180
- format = format.gsub('%Z', zone).
181
- gsub('%z', formatted_offset(false)).
182
- gsub('%:z', formatted_offset(true)).
183
- gsub('%::z', formatted_offset(true) + ":00")
184
-
205
+ format = format.gsub('%Z', zone)
206
+ .gsub('%z', formatted_offset(false))
207
+ .gsub('%:z', formatted_offset(true))
208
+ .gsub('%::z', formatted_offset(true) + ":00")
185
209
  time.strftime(format)
186
210
  end
187
211
 
@@ -190,18 +214,24 @@ module ActiveSupport
190
214
  utc <=> other
191
215
  end
192
216
 
217
+ # Returns true if the current object's time is within the specified
218
+ # +min+ and +max+ time.
193
219
  def between?(min, max)
194
220
  utc.between?(min, max)
195
221
  end
196
222
 
223
+ # Returns true if the current object's time is in the past.
197
224
  def past?
198
225
  utc.past?
199
226
  end
200
227
 
228
+ # Returns true if the current object's time falls within
229
+ # the current day.
201
230
  def today?
202
231
  time.today?
203
232
  end
204
233
 
234
+ # Returns true if the current object's time is in the future.
205
235
  def future?
206
236
  utc.future?
207
237
  end
@@ -287,9 +317,13 @@ module ActiveSupport
287
317
  end
288
318
  alias_method :tv_sec, :to_i
289
319
 
290
- # A TimeWithZone acts like a Time, so just return +self+.
320
+ def to_r
321
+ utc.to_r
322
+ end
323
+
324
+ # Return an instance of Time in the system timezone.
291
325
  def to_time
292
- utc
326
+ utc.to_time
293
327
  end
294
328
 
295
329
  def to_datetime
@@ -320,14 +354,16 @@ module ActiveSupport
320
354
  initialize(variables[0].utc, ::Time.find_zone(variables[1]), variables[2].utc)
321
355
  end
322
356
 
323
- # Ensure proxy class responds to all methods that underlying time instance responds to.
324
- def respond_to?(sym, include_priv = false)
357
+ # Ensure proxy class responds to all methods that underlying time instance
358
+ # responds to.
359
+ def respond_to_missing?(sym, include_priv)
325
360
  # consistently respond false to acts_like?(:date), regardless of whether #time is a Time or DateTime
326
- return false if sym.to_s == 'acts_like_date?'
327
- super || time.respond_to?(sym, include_priv)
361
+ return false if sym.to_sym == :acts_like_date?
362
+ time.respond_to?(sym, include_priv)
328
363
  end
329
364
 
330
- # Send the missing method to +time+ instance, and wrap result in a new TimeWithZone with the existing +time_zone+.
365
+ # Send the missing method to +time+ instance, and wrap result in a new
366
+ # TimeWithZone with the existing +time_zone+.
331
367
  def method_missing(sym, *args, &block)
332
368
  wrap_with_time_zone time.__send__(sym, *args, &block)
333
369
  end
@@ -347,12 +383,11 @@ module ActiveSupport
347
383
  end
348
384
 
349
385
  def transfer_time_values_to_utc_constructor(time)
350
- usec = time.respond_to?(:nsec) ? Rational(time.nsec, 1000) : (time.respond_to?(:usec) ? time.usec : 0)
351
- ::Time.utc_time(time.year, time.month, time.day, time.hour, time.min, time.sec, usec)
386
+ ::Time.utc(time.year, time.month, time.day, time.hour, time.min, time.sec, Rational(time.nsec, 1000))
352
387
  end
353
388
 
354
389
  def duration_of_variable_length?(obj)
355
- ActiveSupport::Duration === obj && obj.parts.any? {|p| p[0].in?([:years, :months, :days]) }
390
+ ActiveSupport::Duration === obj && obj.parts.any? {|p| [:years, :months, :days].include?(p[0]) }
356
391
  end
357
392
 
358
393
  def wrap_with_time_zone(time)