1
1
require_relative '../test_helper'
2
2
3
- class UpdateProjectSettingsTest < ActiveSupport :: TestCase
3
+ class UpdateProjectSettingsTest < GttTest
4
4
fixtures :projects
5
5
6
6
test 'should save tile sources' do
@@ -15,6 +15,49 @@ class UpdateProjectSettingsTest < ActiveSupport::TestCase
15
15
p . reload
16
16
assert_equal [ ts ] , p . gtt_tile_sources . to_a
17
17
end
18
+
19
+ test 'should validate invalid multipolygon geometry' do
20
+ p = Project . find 'ecookbook'
21
+ coordinates = [
22
+ [
23
+ [ [ 135.0 , 35.0 ] , [ 136.0 , 35.0 ] , [ 136.0 , 36.0 ] , [ 135.0 , 36.0 ] , [ 135.0 , 35.0 ] ]
24
+ ] ,
25
+ [
26
+ [ [ 136.0 , 35.0 ] , [ 137.0 , 35.0 ] , [ 137.0 , 36.0 ] , [ 136.0 , 36.0 ] , [ 136.0 , 35.0 ] ]
27
+ ]
28
+ ]
29
+
30
+ form = GttConfiguration . from_params geojson : multipolygon_geojson ( coordinates )
31
+ form . project = p
32
+ r = RedmineGtt ::Actions ::UpdateProjectSettings . ( form )
33
+
34
+ assert_not r . settings_saved?
35
+
36
+ p . reload
37
+ assert_include 'Geometry is invalid' , p . errors . full_messages
38
+ end
39
+
40
+ test 'should save valid multipolygon geometry' do
41
+ p = Project . find 'ecookbook'
42
+ coordinates = [
43
+ [
44
+ [ [ 135.0 , 35.0 ] , [ 136.0 , 35.0 ] , [ 136.0 , 36.0 ] , [ 135.0 , 36.0 ] , [ 135.0 , 35.0 ] ]
45
+ ] ,
46
+ [
47
+ [ [ 137.0 , 35.0 ] , [ 138.0 , 35.0 ] , [ 138.0 , 36.0 ] , [ 137.0 , 36.0 ] , [ 137.0 , 35.0 ] ]
48
+ ]
49
+ ]
50
+
51
+ form = GttConfiguration . from_params geojson : multipolygon_geojson ( coordinates )
52
+ form . project = p
53
+ r = RedmineGtt ::Actions ::UpdateProjectSettings . ( form )
54
+
55
+ assert r . settings_saved?
56
+
57
+ p . reload
58
+ assert_equal coordinates , JSON . parse ( p . geojson ) [ 'geometry' ] [ 'coordinates' ]
59
+ end
60
+
18
61
end
19
62
20
63
0 commit comments