@@ -37,6 +37,16 module Redmine | |||||
37 | @struct.last.merge!(options) if options |
|
37 | @struct.last.merge!(options) if options | |
38 | end |
|
38 | end | |
39 |
|
39 | |||
|
40 | def encode_value(value) | |||
|
41 | if value.is_a?(Time) | |||
|
42 | # Rails uses a global setting to format JSON times | |||
|
43 | # Don't rely on it for the API as it could have been changed | |||
|
44 | value.xmlschema(0) | |||
|
45 | else | |||
|
46 | value | |||
|
47 | end | |||
|
48 | end | |||
|
49 | ||||
40 | def method_missing(sym, *args, &block) |
|
50 | def method_missing(sym, *args, &block) | |
41 | if args.any? |
|
51 | if args.any? | |
42 | if args.first.is_a?(Hash) |
|
52 | if args.first.is_a?(Hash) | |
@@ -46,14 +56,15 module Redmine | |||||
46 | @struct.last[sym] = args.first |
|
56 | @struct.last[sym] = args.first | |
47 | end |
|
57 | end | |
48 | else |
|
58 | else | |
|
59 | value = encode_value(args.first) | |||
49 | if @struct.last.is_a?(Array) |
|
60 | if @struct.last.is_a?(Array) | |
50 | if args.size == 1 && !block_given? |
|
61 | if args.size == 1 && !block_given? | |
51 |
@struct.last << |
|
62 | @struct.last << value | |
52 | else |
|
63 | else | |
53 |
@struct.last << (args.last || {}).merge(:value => |
|
64 | @struct.last << (args.last || {}).merge(:value => value) | |
54 | end |
|
65 | end | |
55 | else |
|
66 | else | |
56 |
@struct.last[sym] = |
|
67 | @struct.last[sym] = value | |
57 | end |
|
68 | end | |
58 | end |
|
69 | end | |
59 | end |
|
70 | end |
@@ -34,4 +34,14 class Redmine::ApiTest::ApiTest < Redmine::ApiTest::Base | |||||
34 | ensure |
|
34 | ensure | |
35 | ActionController::Base.allow_forgery_protection = false |
|
35 | ActionController::Base.allow_forgery_protection = false | |
36 | end |
|
36 | end | |
37 | end No newline at end of file |
|
37 | ||
|
38 | def test_json_datetime_format | |||
|
39 | get '/users/1.json', {}, credentials('admin') | |||
|
40 | assert_include '"created_on":"2006-07-19T17:12:21Z"', response.body | |||
|
41 | end | |||
|
42 | ||||
|
43 | def test_xml_datetime_format | |||
|
44 | get '/users/1.xml', {}, credentials('admin') | |||
|
45 | assert_include '<created_on>2006-07-19T17:12:21Z</created_on>', response.body | |||
|
46 | end | |||
|
47 | end |
General Comments 0
You need to be logged in to leave comments.
Login now