Permalink
Browse files

Fix Duration#to_json

  • Loading branch information...
1 parent 43433b3 commit 0ac66caac5581c4793d120c8ad4a2cf4137f6ce2 @lifo lifo committed Dec 29, 2010
Showing with 9 additions and 0 deletions.
  1. +4 −0 activesupport/lib/active_support/duration.rb
  2. +5 −0 activesupport/test/core_ext/duration_test.rb
@@ -80,6 +80,10 @@ def inspect #:nodoc:
parts.to_sentence(:locale => :en)
end
+ def as_json(options = nil) #:nodoc:
+ to_i
+ end
+
protected
def sum(sign, time = ::Time.current) #:nodoc:
@@ -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 @@ def test_delegation_with_block_works
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

0 comments on commit 0ac66ca

Please sign in to comment.