Skip to content

Commit e93334f

Browse files
committed
Added unit tests for valid/invalid multipolygon geometry
Signed-off-by: Ko Nagase <[email protected]>
1 parent 50b24ac commit e93334f

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

test/test_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ def point_geojson(coordinates)
1414
{'type'=>'Feature','geometry'=>{ 'type'=>'Point','coordinates'=> coordinates}}.to_json
1515
end
1616

17+
def multipolygon_geojson(coordinates)
18+
{'type'=>'Feature','geometry'=>{ 'type'=>'MultiPolygon','coordinates'=> coordinates}}.to_json
19+
end
20+
1721
def test_geom
1822
RedmineGtt::Conversions::WkbToGeom.("01030000000100000006000000C84B374110E76040381DD011545A4140C84B3739ACE96040F07E6DCC7A594140C84B37F199E960403CBC2D58E2554140C84B373917E8604098CBC3E188564140C84B37FD36E66040F24C2E959D564140C84B374110E76040381DD011545A4140")
1923
end

test/unit/update_project_settings_test.rb

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require_relative '../test_helper'
22

3-
class UpdateProjectSettingsTest < ActiveSupport::TestCase
3+
class UpdateProjectSettingsTest < GttTest
44
fixtures :projects
55

66
test 'should save tile sources' do
@@ -15,6 +15,49 @@ class UpdateProjectSettingsTest < ActiveSupport::TestCase
1515
p.reload
1616
assert_equal [ts], p.gtt_tile_sources.to_a
1717
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+
1861
end
1962

2063

0 commit comments

Comments
 (0)