Skip to content

Commit b25cc78

Browse files
sanakdkastl
authored andcommitted
Add integration issues api test
1 parent dd31057 commit b25cc78

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
require_relative '../test_helper'
2+
3+
class IssuesApiTest < Redmine::IntegrationTest
4+
fixtures :projects,
5+
:users,
6+
:roles,
7+
:members,
8+
:member_roles,
9+
:issues
10+
11+
setup do
12+
# User.current = nil
13+
@project = Project.find 'ecookbook'
14+
@project.enabled_modules.create name: 'gtt'
15+
end
16+
17+
test 'should include geojson' do
18+
geo = {
19+
'type' => 'Feature',
20+
'geometry' => {
21+
'type' => 'Point',
22+
'coordinates' => [123.269691,9.305099]
23+
}
24+
}
25+
geojson = geo.to_json
26+
27+
issue = @project.issues.find 1
28+
issue.update_attribute :geojson, geojson
29+
# xml format - index api
30+
get '/issues.xml'
31+
assert_response :success
32+
xml = xml_data
33+
assert json = xml.xpath('/issues/issue[id=1]/geojson').text
34+
assert json.present?
35+
assert_match(/123\.269691/, json)
36+
assert_equal geo['geometry'], JSON.parse(json)['geometry'], json
37+
# xml format - show api
38+
get '/issues/1.xml'
39+
assert_response :success
40+
xml = xml_data
41+
assert json = xml.xpath('/issue/geojson').text
42+
assert json.present?
43+
assert_match(/123\.269691/, json)
44+
assert_equal geo['geometry'], JSON.parse(json)['geometry'], json
45+
46+
# json format - index api
47+
get '/issues.json'
48+
assert_response :success
49+
assert json = JSON.parse(@response.body)
50+
hsh = json['issues'].detect{|i|i['id'] == issue.id}['geojson']
51+
assert_equal geo['geometry'], hsh['geometry']
52+
# json format - show api
53+
get '/issues/1.json'
54+
assert_response :success
55+
assert json = JSON.parse(@response.body)
56+
hsh = json['issue']['geojson']
57+
assert_equal geo['geometry'], hsh['geometry']
58+
end
59+
60+
test 'should include empty geojson' do
61+
issue = @project.issues.find 1
62+
issue.update_attribute :geojson, nil
63+
64+
# xml format - index api
65+
get '/issues.xml'
66+
assert_response :success
67+
xml = xml_data
68+
assert json = xml.xpath('/issues/issue[id=1]/geojson').text
69+
assert_equal "", json
70+
# xml format - show api
71+
get '/issues/1.xml'
72+
assert_response :success
73+
xml = xml_data
74+
assert json = xml.xpath('/issue/geojson').text
75+
assert_equal "", json
76+
77+
# json format - index api
78+
get '/issues.json'
79+
assert_response :success
80+
assert json = JSON.parse(@response.body)
81+
hsh = json['issues'].detect{|p|p['id'] == issue.id}['geojson']
82+
assert_nil hsh
83+
# json format - show api
84+
get '/issues/1.json'
85+
assert_response :success
86+
assert json = JSON.parse(@response.body)
87+
hsh = json['issue']['geojson']
88+
assert_nil hsh
89+
end
90+
91+
def xml_data
92+
Nokogiri::XML(@response.body)
93+
end
94+
end

0 commit comments

Comments
 (0)