-
Notifications
You must be signed in to change notification settings - Fork 0
/
'
325 lines (257 loc) · 15.2 KB
/
'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
require 'test_helper'
class SplitRouteTest < ActionDispatch::IntegrationTest
def setup
init()
end
#split route with selected place
test "split route with selected place" do
#create route
#create place at half-way point
#navigate to my route
login_as(@testuser2.name,"password")
assert is_logged_in?
tr=Route.create(name: "splitroute", createdBy_id: @testuser.id, updatedBy_id: @testuser.id,experienced_at: "01-01-1900", published: true, startplace_id: @testplace.id, endplace_id: @testplace2.id, routetype_id: 2, gradient_id: 2, river_id: 2, alpinesummer_id: 2,alpinewinter_id: 2,terrain_id: 2, via: "splittrack", importance_id: 2, time: 3, location: 'LINESTRING(175.61823472 -41.07151361 300,175.61823472 -41.06251490 200)', distance: 1, description: "A"*1000, reverse_description: "Z"*1000, winterdescription: 'X'*1000)
tp=Place.create(name: "splitplace", createdBy_id: @testuser.id, updatedBy_id: @testuser.id,experienced_at: "01-01-1900", x: 1820000, y: 5450000, projection_id: 2193, location: 'POINT(175.61823472 -41.06701426)',place_type: "Hut", place_owner: "DOC", altitude: "123", description:"test place1 description")
get '/routes/'+tr.id.to_s
assert :success
assert_template 'routes/show'
assert_select 'a[href=?]', '/routes/xrc'+tr.id.to_s+"xps"
get '/routes/xrc'+tr.id.to_s+"xps"
assert :success
assert_template 'routes/show_many'
# route is shown
assert_select 'div#route_title1', 'testplace to testplacei2 via splittrack'
assert_select 'div#actiontitle2', 'Select place at which to split this route:'
#split at selected place
rtcnt=Route.count
post '/places/select', url: 'xrc'+tr.id.to_s+'xps', route_startplace_id: tp.id.to_s, commit: 'select'
assert :success
assert_template 'routes/show_many'
#new route created
assert_equal Route.count, rtcnt+1
tr2=Route.last
tr.reload
assert_select 'div.alert', 'Success: route split. Now please edit the details of the first half of the split route'
#correct url sequence (modify original, view new)
assert_select 'input#urlfield[value=?]', 'xrm'+tr.id.to_s+'xrv'+tr2.id.to_s
############################################
#first route is shown in edit mdoe
#values correct
assert_select 'input#route_startplace_name[value=?]', 'testplace'
assert_select 'input#route_endplace_name[value=?]', 'splitplace'
assert_select 'input#route_distance[value=?]', 0.500865350899489 #TODO expected 500
############################################
#second route is shown in view mdoe
assert_select 'div#route_title1', 'splitplace to testplacei2 via splittrack'
assert_select 'span#route_dist1', 'Distance: 0.5 km' #TODO expected 500m
assert_select 'div#fw_t1', "From splitplace to testplacei2"
#updated_by
assert_equal tr.updatedBy_id, @testuser2.id
assert_equal tr2.updatedBy_id, @testuser2.id
#location
assert_equal tr.location.as_text, "LINESTRING (175.61823472 -41.07151361 300.0, 175.61823472 -41.06701426 300.0)"
assert_equal tr2.location.as_text, "LINESTRING (175.61823472 -41.06701426 200.0, 175.61823472 -41.0625149 200.0)"
#altitude
assert_equal tr.altloss, 0
assert_equal tr.altgain, 0
assert_equal tr.minalt, 300
assert_equal tr.maxalt, 300
assert_equal tr2.altloss, 0
assert_equal tr2.altgain, 0
assert_equal tr2.minalt, 200
assert_equal tr2.maxalt, 200
#intances
#original route now has 2 instances
assert_equal tr.routeInstances.count, 2
assert_equal tr2.routeInstances.count, 1
#all other values equal
assert_equal tr.description, tr2.description
assert_equal tr.routetype_id, tr2.routetype_id
assert_equal tr.terrain_id, tr2.terrain_id
assert_equal tr.alpinesummer_id, tr2.alpinesummer_id
assert_equal tr.river_id, tr2.river_id
assert_equal tr.alpinewinter_id, tr2.alpinewinter_id
assert_equal tr.winterdescription, tr2.winterdescription
assert_equal tr.createdBy_id, tr2.createdBy_id
# assert_equal tr.created_at, tr2.created_at
assert_equal tr.via, tr2.via
assert_equal tr.reverse_description, tr2.reverse_description
assert_equal tr.time, tr2.time
assert_equal tr.datasource, tr2.datasource
assert_equal tr.published, tr2.published
assert_equal tr.experienced_at, tr2.experienced_at
############################################
#save pt1, part 2 placed in edit mode
patch '/routes/'+tr.id.to_s, route: { startplace_id: @testplace.id.to_s, endplace_id: tp.id.to_s, via: "changedvia", experienced_at: "2015-01-01", location: "LINESTRING (175.61823472 -41.07151361 300.0, 175.61823472 -41.06701426 300.0)", description: "M"*3000, reverse_description: "N"*3000, time: "1.1", distance: "0.5", importance_id: "3", routetype_id: "3", gradient_id: "3", terrain_id: "3", alpinesummer_id: "3", river_id: "3", alpinewinter_id: "3", winterdescription: "O"*3000, published: "1" }, datasource: "Uploaded from GPS", save: "Save", url: 'xrm'+tr.id.to_s+'xrv'+tr2.id.to_s
assert :success
assert_template 'routes/show_many'
tr.reload
assert_select 'div.alert', 'First segment updated. Now please update the details of the second part of the split route'
#correct url sequence (modify original, view new)
assert_select 'input#urlfield[value=?]', 'xrv'+tr.id.to_s+'xre'+tr2.id.to_s
############################################
#first route is shown in view mdoe
assert_select 'div#route_title1', 'testplace to splitplace via changedvia'
assert_select 'div#fw_t1', "From testplace to splitplace"
############################################
#second route is shown in edit mdoe
#values correct
assert_select 'input#route_startplace_name[value=?]', 'splitplace'
assert_select 'input#route_endplace_name[value=?]', 'testplacei2'
assert_select 'input#route_distance[value=?]', 0.5008664640973013 #TODO expected 0.500
############################################
#save pt2, part 2 placed in edit moderts 1 and 2 shown as view
patch '/routes/'+tr2.id.to_s, route: { startplace_id: tp.id.to_s, endplace_id: @testplace2.id.to_s, via: "changedvia", experienced_at: "2015-01-01", location: "LINESTRING (175.61823472 -41.06701426 200.0, 175.61823472 -41.0625149 200.0)", description: "M"*3000, reverse_description: "N"*3000, time: "1.1", distance: "0.5", importance_id: "3", routetype_id: "3", gradient_id: "3", terrain_id: "3", alpinesummer_id: "3", river_id: "3", alpinewinter_id: "3", winterdescription: "O"*3000, published: "1" }, datasource: "Uploaded from GPS", save: "Save", url: 'xrv'+tr.id.to_s+'xre'+tr2.id.to_s
assert :success
assert_template 'routes/show_many'
tr.reload
assert_select 'div.alert', 'Route updated, id:'+tr2.id.to_s
#correct url sequence (modify original, view new)
# assert_select 'input#urlfield[value=?]', 'xrv'+tr.id.to_s+'xrv'+tr2.id.to_s
############################################
#first route is shown in view mdoe
assert_select 'div#route_title1', 'testplace to splitplace via changedvia'
assert_select 'div#fw_t1', "From testplace to splitplace"
############################################
#second route is shown in view mdoe
assert_select 'div#route_title2', 'splitplace to testplacei2 via changedvia'
assert_select 'div#fw_t2', "From splitplace to testplacei2"
end
#split route with added place
test "split route with added place" do
#create route
#create place at half-way point
#navigate to my route
login_as(@testuser2.name,"password")
assert is_logged_in?
tr=Route.create(name: "splitroute", createdBy_id: @testuser.id, updatedBy_id: @testuser.id,experienced_at: "01-01-1900", published: true, startplace_id: @testplace.id, endplace_id: @testplace2.id, routetype_id: 2, gradient_id: 2, river_id: 2, alpinesummer_id: 2,alpinewinter_id: 2,terrain_id: 2, via: "splittrack", importance_id: 2, time: 3, location: 'LINESTRING(175.61823472 -41.07151361 300,175.61823472 -41.06251490 200)', distance: 1, description: "A"*1000, reverse_description: "Z"*1000, winterdescription: 'X'*1000)
# tp=Place.create(name: "splitplace", createdBy_id: @testuser.id, updatedBy_id: @testuser.id,experienced_at: "01-01-1900", x: 1820000, y: 5450000, projection_id: 2193, location: 'POINT(175.61823472 -41.06701426)',place_type: "Hut", place_owner: "DOC", altitude: "123", description:"test place1 description")
get '/routes/'+tr.id.to_s
assert :success
assert_template 'routes/show'
assert_select 'a[href=?]', '/routes/xrc'+tr.id.to_s+"xps"
get '/routes/xrc'+tr.id.to_s+"xps"
assert :success
assert_template 'routes/show_many'
# route is shown
assert_select 'div#route_title1', 'testplace to testplacei2 via splittrack'
assert_select 'div#actiontitle2', 'Select place at which to split this route:'
#split at selected place
rtcnt=Route.count
get '/routes/xrc'+tr.id.to_s+"xpn"
assert :success
assert_template 'routes/show_many'
# route is shown
assert_select 'div#route_title1', 'testplace to testplacei2 via splittrack'
assert_select 'div#actiontitle2', 'Enter details of place at which to split this route:'
#post '/places/select', url: 'xrc'+tr.id.to_s+'xps', route_startplace_id: tp.id.to_s, commit: 'select'
assert :success
assert_template 'routes/show_many'
#new route created
assert_equal Route.count, rtcnt+1
tr2=Route.last
tr.reload
assert_select 'div.alert', 'Success: route split. Now please edit the details of the first half of the split route'
#correct url sequence (modify original, view new)
assert_select 'input#urlfield[value=?]', 'xrm'+tr.id.to_s+'xrv'+tr2.id.to_s
############################################
#first route is shown in edit mdoe
#values correct
assert_select 'input#route_startplace_name[value=?]', 'testplace'
assert_select 'input#route_endplace_name[value=?]', 'splitplace'
assert_select 'input#route_distance[value=?]', 0.500865350899489 #TODO expected 500
############################################
#second route is shown in view mdoe
assert_select 'div#route_title1', 'splitplace to testplacei2 via splittrack'
assert_select 'span#route_dist1', 'Distance: 0.5 km' #TODO expected 500m
assert_select 'div#fw_t1', "From splitplace to testplacei2"
#updated_by
assert_equal tr.updatedBy_id, @testuser2.id
assert_equal tr2.updatedBy_id, @testuser2.id
#location
assert_equal tr.location.as_text, "LINESTRING (175.61823472 -41.07151361 300.0, 175.61823472 -41.06701426 300.0)"
assert_equal tr2.location.as_text, "LINESTRING (175.61823472 -41.06701426 200.0, 175.61823472 -41.0625149 200.0)"
#altitude
assert_equal tr.altloss, 0
assert_equal tr.altgain, 0
assert_equal tr.minalt, 300
assert_equal tr.maxalt, 300
assert_equal tr2.altloss, 0
assert_equal tr2.altgain, 0
assert_equal tr2.minalt, 200
assert_equal tr2.maxalt, 200
#intances
#original route now has 2 instances
assert_equal tr.routeInstances.count, 2
assert_equal tr2.routeInstances.count, 1
#all other values equal
assert_equal tr.description, tr2.description
assert_equal tr.routetype_id, tr2.routetype_id
assert_equal tr.terrain_id, tr2.terrain_id
assert_equal tr.alpinesummer_id, tr2.alpinesummer_id
assert_equal tr.river_id, tr2.river_id
assert_equal tr.alpinewinter_id, tr2.alpinewinter_id
assert_equal tr.winterdescription, tr2.winterdescription
assert_equal tr.createdBy_id, tr2.createdBy_id
# assert_equal tr.created_at, tr2.created_at
assert_equal tr.via, tr2.via
assert_equal tr.reverse_description, tr2.reverse_description
assert_equal tr.time, tr2.time
assert_equal tr.datasource, tr2.datasource
assert_equal tr.published, tr2.published
assert_equal tr.experienced_at, tr2.experienced_at
############################################
#save pt1, part 2 placed in edit mode
patch '/routes/'+tr.id.to_s, route: { startplace_id: @testplace.id.to_s, endplace_id: tp.id.to_s, via: "changedvia", experienced_at: "2015-01-01", location: "LINESTRING (175.61823472 -41.07151361 300.0, 175.61823472 -41.06701426 300.0)", description: "M"*3000, reverse_description: "N"*3000, time: "1.1", distance: "0.5", importance_id: "3", routetype_id: "3", gradient_id: "3", terrain_id: "3", alpinesummer_id: "3", river_id: "3", alpinewinter_id: "3", winterdescription: "O"*3000, published: "1" }, datasource: "Uploaded from GPS", save: "Save", url: 'xrm'+tr.id.to_s+'xrv'+tr2.id.to_s
assert :success
assert_template 'routes/show_many'
tr.reload
assert_select 'div.alert', 'First segment updated. Now please update the details of the second part of the split route'
#correct url sequence (modify original, view new)
assert_select 'input#urlfield[value=?]', 'xrv'+tr.id.to_s+'xre'+tr2.id.to_s
############################################
#first route is shown in view mdoe
assert_select 'div#route_title1', 'testplace to splitplace via changedvia'
assert_select 'div#fw_t1', "From testplace to splitplace"
############################################
#second route is shown in edit mdoe
#values correct
assert_select 'input#route_startplace_name[value=?]', 'splitplace'
assert_select 'input#route_endplace_name[value=?]', 'testplacei2'
assert_select 'input#route_distance[value=?]', 0.5008664640973013 #TODO expected 0.500
############################################
#save pt2, part 2 placed in edit moderts 1 and 2 shown as view
patch '/routes/'+tr2.id.to_s, route: { startplace_id: tp.id.to_s, endplace_id: @testplace2.id.to_s, via: "changedvia", experienced_at: "2015-01-01", location: "LINESTRING (175.61823472 -41.06701426 200.0, 175.61823472 -41.0625149 200.0)", description: "M"*3000, reverse_description: "N"*3000, time: "1.1", distance: "0.5", importance_id: "3", routetype_id: "3", gradient_id: "3", terrain_id: "3", alpinesummer_id: "3", river_id: "3", alpinewinter_id: "3", winterdescription: "O"*3000, published: "1" }, datasource: "Uploaded from GPS", save: "Save", url: 'xrv'+tr.id.to_s+'xre'+tr2.id.to_s
assert :success
assert_template 'routes/show_many'
tr.reload
assert_select 'div.alert', 'Route updated, id:'+tr2.id.to_s
#correct url sequence (modify original, view new)
# assert_select 'input#urlfield[value=?]', 'xrv'+tr.id.to_s+'xrv'+tr2.id.to_s
############################################
#first route is shown in view mdoe
assert_select 'div#route_title1', 'testplace to splitplace via changedvia'
assert_select 'div#fw_t1', "From testplace to splitplace"
############################################
#second route is shown in view mdoe
assert_select 'div#route_title2', 'splitplace to testplacei2 via changedvia'
assert_select 'div#fw_t2', "From splitplace to testplacei2"
end
#split route with edited place
#no trips
#forward trip has new route segments .... pt1, pt2, ...
#reverse trip has new route segments .... -pt2, -pt1, ...
#no links ok
#linked items inherit both segments
#errors:
##Distance > 200m
##Split returned 1 segment
##Start segment lenght=0
##End segment length=0
##Save of new route failed (validation errors) (duplicate name a good one)
##Save of old route fails (dupicate name a good one)
##Copy link fails (how???)
##Create tripdetail (forwards) fails
##Create tripdetail (backwards) fails
##Update existing tripdetail fails
end