Skip to content

Commit dd31057

Browse files
sanakdkastl
authored andcommitted
Update integration projects api test
1 parent 84404ae commit dd31057

File tree

1 file changed

+47
-4
lines changed

1 file changed

+47
-4
lines changed

test/integration/projects_api_test.rb

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class ProjectsApiTest < Redmine::IntegrationTest
5656

5757
end
5858

59-
test 'should include geojson on demand' do
59+
test 'should include geojson (on demand)' do
6060
geo = {
6161
'type' => 'Feature',
6262
'geometry' => {
@@ -69,21 +69,64 @@ class ProjectsApiTest < Redmine::IntegrationTest
6969
geojson = geo.to_json
7070

7171
@project.update_attribute :geojson, geojson
72-
@subproject1.update_attribute :geojson, geojson
72+
# xml format - index api
7373
get '/projects.xml?include=geometry'
7474
assert_response :success
7575
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
7885
assert json.present?
7986
assert_match(/123\.269691/, json)
8087
assert_equal geo['geometry'], JSON.parse(json)['geometry'], json
8188

89+
# json format - index api
8290
get '/projects.json?include=geometry'
8391
assert_response :success
8492
assert json = JSON.parse(@response.body)
8593
hsh = json['projects'].detect{|p|p['id'] == @project.id}['geojson']
8694
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
87130
end
88131

89132
test 'should filter projects by query and geometry' do

0 commit comments

Comments
 (0)