From 2f78c8a7ec28064c7d2413e32f215d987c2e9d88 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 15 Mar 2015 14:09:48 +0000 Subject: [PATCH] Merged r14101 (#19354). git-svn-id: http://svn.redmine.org/redmine/branches/3.0-stable@14111 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/views/builders/structure.rb | 17 ++++++++++++++--- test/integration/api_test/api_test.rb | 12 +++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/redmine/views/builders/structure.rb b/lib/redmine/views/builders/structure.rb index a420dc497..b11e255ec 100644 --- a/lib/redmine/views/builders/structure.rb +++ b/lib/redmine/views/builders/structure.rb @@ -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 diff --git a/test/integration/api_test/api_test.rb b/test/integration/api_test/api_test.rb index 1387fa905..b81f8e0ad 100644 --- a/test/integration/api_test/api_test.rb +++ b/test/integration/api_test/api_test.rb @@ -34,4 +34,14 @@ class Redmine::ApiTest::ApiTest < Redmine::ApiTest::Base ensure ActionController::Base.allow_forgery_protection = false end -end \ No newline at end of file + + 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 '2006-07-19T17:12:21Z', response.body + end +end -- 2.39.5