Skip to content

Commit

Permalink
Fix Duration#to_json
Browse files Browse the repository at this point in the history
  • Loading branch information
lifo committed Dec 29, 2010
1 parent 43433b3 commit 0ac66ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions activesupport/lib/active_support/duration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions activesupport/test/core_ext/duration_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'abstract_unit'
require 'active_support/time'
require 'active_support/json'

class DurationTest < ActiveSupport::TestCase
def test_is_a
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0ac66ca

Please sign in to comment.