@@ -56,7 +56,7 @@ class ProjectsApiTest < Redmine::IntegrationTest
56
56
57
57
end
58
58
59
- test 'should include geojson on demand' do
59
+ test 'should include geojson ( on demand) ' do
60
60
geo = {
61
61
'type' => 'Feature' ,
62
62
'geometry' => {
@@ -69,21 +69,64 @@ class ProjectsApiTest < Redmine::IntegrationTest
69
69
geojson = geo . to_json
70
70
71
71
@project . update_attribute :geojson , geojson
72
- @subproject1 . update_attribute :geojson , geojson
72
+ # xml format - index api
73
73
get '/projects.xml?include=geometry'
74
74
assert_response :success
75
75
xml = xml_data
76
- assert projects = xml . xpath ( '/projects/project' )
77
- assert json = projects . xpath ( 'geojson' ) . first . text
76
+ assert json = xml . xpath ( '/projects/project[id=1]/geojson' ) . text
77
+ assert json . present?
78
+ assert_match ( /123\. 269691/ , json )
79
+ assert_equal geo [ 'geometry' ] , JSON . parse ( json ) [ 'geometry' ] , json
80
+ # xml format - show api
81
+ get '/projects/1.xml'
82
+ assert_response :success
83
+ xml = xml_data
84
+ assert json = xml . xpath ( '/project/geojson' ) . text
78
85
assert json . present?
79
86
assert_match ( /123\. 269691/ , json )
80
87
assert_equal geo [ 'geometry' ] , JSON . parse ( json ) [ 'geometry' ] , json
81
88
89
+ # json format - index api
82
90
get '/projects.json?include=geometry'
83
91
assert_response :success
84
92
assert json = JSON . parse ( @response . body )
85
93
hsh = json [ 'projects' ] . detect { |p |p [ 'id' ] == @project . id } [ 'geojson' ]
86
94
assert_equal geo [ 'geometry' ] , hsh [ 'geometry' ]
95
+ # json format - show api
96
+ get '/projects/1.json'
97
+ assert_response :success
98
+ assert json = JSON . parse ( @response . body )
99
+ hsh = json [ 'project' ] [ 'geojson' ]
100
+ assert_equal geo [ 'geometry' ] , hsh [ 'geometry' ]
101
+ end
102
+
103
+ test 'should include empty geojson (on demand)' do
104
+ @project . update_attribute :geojson , nil
105
+ # xml format - index api
106
+ get '/projects.xml?include=geometry'
107
+ assert_response :success
108
+ xml = xml_data
109
+ assert json = xml . xpath ( '/projects/project[id=1]/geojson' ) . text
110
+ assert_equal "" , json
111
+ # xml format - show api
112
+ get '/projects/1.xml'
113
+ assert_response :success
114
+ xml = xml_data
115
+ assert json = xml . xpath ( '/project/geojson' ) . text
116
+ assert_equal "" , json
117
+
118
+ # json format - index api
119
+ get '/projects.json?include=geometry'
120
+ assert_response :success
121
+ assert json = JSON . parse ( @response . body )
122
+ hsh = json [ 'projects' ] . detect { |p |p [ 'id' ] == @project . id } [ 'geojson' ]
123
+ assert_nil hsh
124
+ # json format - show api
125
+ get '/projects/1.json'
126
+ assert_response :success
127
+ assert json = JSON . parse ( @response . body )
128
+ hsh = json [ 'project' ] [ 'geojson' ]
129
+ assert_nil hsh
87
130
end
88
131
89
132
test 'should filter projects by query and geometry' do
0 commit comments