diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-12-29 22:20:14 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-12-29 22:20:14 +0000 |
commit | 0ac66caac5581c4793d120c8ad4a2cf4137f6ce2 (patch) | |
tree | 6de0b3cdd589c648a525c2c3d6e1878c9bf4df78 /activesupport | |
parent | 43433b3fb4b9c054e0bcaaa1f7456b3fececd268 (diff) | |
download | rails-0ac66caac5581c4793d120c8ad4a2cf4137f6ce2.tar.gz rails-0ac66caac5581c4793d120c8ad4a2cf4137f6ce2.tar.bz2 rails-0ac66caac5581c4793d120c8ad4a2cf4137f6ce2.zip |
Fix Duration#to_json
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/duration.rb | 4 | ||||
-rw-r--r-- | activesupport/test/core_ext/duration_test.rb | 5 |
2 files changed, 9 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index de3ded1e1f..00c67a470d 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -80,6 +80,10 @@ module ActiveSupport parts.to_sentence(:locale => :en) end + def as_json(options = nil) #:nodoc: + to_i + end + protected def sum(sign, time = ::Time.current) #:nodoc: diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index bb453b8d7f..6a01eeed6b 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'active_support/time' +require 'active_support/json' class DurationTest < ActiveSupport::TestCase def test_is_a @@ -138,6 +139,10 @@ class DurationTest < ActiveSupport::TestCase assert_equal counter, 60 end + def test_to_json + assert_equal '172800', 2.days.to_json + end + protected def with_env_tz(new_tz = 'US/Eastern') old_tz, ENV['TZ'] = ENV['TZ'], new_tz |