mirror of
https://github.com/github/rails.git
synced 2026-01-30 00:38:00 -05:00
Date, Time, and DateTime#to_json. Closes #8399.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6773 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Date, Time, and DateTime#to_json. #8399 [wycats]
|
||||
|
||||
* Simplify API of assert_difference by passing in an expression that is evaluated before and after the passed in block. See documenation for examples of new API. [Marcel Molina Jr.]
|
||||
|
||||
* Added assert_difference and assert_no_difference to test/unit assertions [Tobias Luetke]
|
||||
|
||||
5
activesupport/lib/active_support/json/encoders/date.rb
Normal file
5
activesupport/lib/active_support/json/encoders/date.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class Date
|
||||
def to_json #:nodoc:
|
||||
%("#{strftime("%m/%d/%Y")}")
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class DateTime
|
||||
def to_json #:nodoc:
|
||||
%("#{strftime("%m/%d/%Y %H:%M:%S %Z")}")
|
||||
end
|
||||
end
|
||||
5
activesupport/lib/active_support/json/encoders/time.rb
Normal file
5
activesupport/lib/active_support/json/encoders/time.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class Time
|
||||
def to_json #:nodoc:
|
||||
%("#{strftime("%m/%d/%Y %H:%M:%S %Z")}")
|
||||
end
|
||||
end
|
||||
@@ -29,6 +29,10 @@ class TestJSONEncoding < Test::Unit::TestCase
|
||||
[ ActiveSupport::JSON::Variable.new('alert("foo")'), 'alert("foo")']]
|
||||
RegexpTests = [[ /^a/, '/^a/' ], [/^\w{1,2}[a-z]+/ix, '/^\\w{1,2}[a-z]+/ix']]
|
||||
|
||||
DateTests = [[ Date.new(2005,1,1), %("01/01/2005") ]]
|
||||
TimeTests = [[ Time.at(0), %("12/31/1969 16:00:00 #{Time.at(0).zone}") ]]
|
||||
DateTimeTests = [[ Time.at(0), %("12/31/1969 16:00:00 #{Time.at(0).zone}") ]]
|
||||
|
||||
constants.grep(/Tests$/).each do |class_tests|
|
||||
define_method("test_#{class_tests[0..-6].downcase}") do
|
||||
self.class.const_get(class_tests).each do |pair|
|
||||
|
||||
Reference in New Issue
Block a user