mirror of
https://github.com/redmine/redmine.git
synced 2025-11-15 09:46:02 +01:00
Don't include milliseconds in JSON API responses (#19354).
git-svn-id: http://svn.redmine.org/redmine/trunk@14101 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -37,6 +37,16 @@ module Redmine
|
||||
@struct.last.merge!(options) if options
|
||||
end
|
||||
|
||||
def encode_value(value)
|
||||
if value.is_a?(Time)
|
||||
# Rails uses a global setting to format JSON times
|
||||
# Don't rely on it for the API as it could have been changed
|
||||
value.xmlschema(0)
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
def method_missing(sym, *args, &block)
|
||||
if args.any?
|
||||
if args.first.is_a?(Hash)
|
||||
@@ -46,14 +56,15 @@ module Redmine
|
||||
@struct.last[sym] = args.first
|
||||
end
|
||||
else
|
||||
value = encode_value(args.first)
|
||||
if @struct.last.is_a?(Array)
|
||||
if args.size == 1 && !block_given?
|
||||
@struct.last << args.first
|
||||
@struct.last << value
|
||||
else
|
||||
@struct.last << (args.last || {}).merge(:value => args.first)
|
||||
@struct.last << (args.last || {}).merge(:value => value)
|
||||
end
|
||||
else
|
||||
@struct.last[sym] = args.first
|
||||
@struct.last[sym] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,4 +34,14 @@ class Redmine::ApiTest::ApiTest < Redmine::ApiTest::Base
|
||||
ensure
|
||||
ActionController::Base.allow_forgery_protection = false
|
||||
end
|
||||
|
||||
def test_json_datetime_format
|
||||
get '/users/1.json', {}, credentials('admin')
|
||||
assert_include '"created_on":"2006-07-19T17:12:21Z"', response.body
|
||||
end
|
||||
|
||||
def test_xml_datetime_format
|
||||
get '/users/1.xml', {}, credentials('admin')
|
||||
assert_include '<created_on>2006-07-19T17:12:21Z</created_on>', response.body
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user