Skip to content

Commit a73bb8d

Browse files
committed
unit test fixes
- my tests were barking about the wkb having the wrong srid. using json works.
1 parent 80f7887 commit a73bb8d

File tree

5 files changed

+31
-17
lines changed

5 files changed

+31
-17
lines changed

test/test_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33

44
class GttTest < ActiveSupport::TestCase
55

6+
def test_geojson
7+
{'type'=>'Feature','geometry'=>{ 'type'=>'Polygon','coordinates'=> [[[135.22073422241215,34.70569060003112],[135.30227337646488,34.6990600142143],[135.3000417785645,34.670969984370885],[135.25283489990238,34.676052303889435],[135.1942125396729,34.67668404351015],[135.22073422241215,34.70569060003112]]]}}.to_json
8+
end
9+
610
def test_geom
711
RedmineGtt::Conversions::WkbToGeom.("01030000000100000006000000C84B374110E76040381DD011545A4140C84B3739ACE96040F07E6DCC7A594140C84B37F199E960403CBC2D58E2554140C84B373917E8604098CBC3E188564140C84B37FD36E66040F24C2E959D564140C84B374110E76040381DD011545A4140")
812
end
913

1014
def assert_geojson(json)
15+
json = JSON.parse json if json.is_a?(String)
1116
assert_equal 'Feature', json['type']
1217
assert geom = json['geometry']
1318
assert_equal 'Polygon', geom['type']

test/unit/gtt_map_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class GttMapTest < GttTest
66
@ts = GttTileSource.create! name: 'test', type: 'ol.source.OSM'
77
end
88

9-
test 'should compute json from wkb' do
9+
test 'should compute json from geom' do
1010
m = GttMap.new layers: [@ts], geom: test_geom
1111
assert_geojson m.json
1212
end

test/unit/issue_test.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ class IssueTest < GttTest
66
setup do
77
@project = Project.find 'ecookbook'
88
@issue = @project.issues.last
9-
@issue.update_column :geom, test_geom
9+
@issue.update_attribute :geojson, test_geojson
10+
@issue = Issue.find @issue.id
11+
end
12+
13+
test 'should have geom attribute' do
14+
assert @issue.geom.present?
1015
end
1116

1217
test 'should have geojson attribute' do

test/unit/project_test.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@
33
class ProjectTest < GttTest
44
fixtures :projects
55

6-
test 'should have geojson attribute' do
7-
p = Project.find 'ecookbook'
8-
p.update_column :geom, test_geom
6+
setup do
7+
@p = Project.find 'ecookbook'
8+
@p.update_attribute :geojson, test_geojson
9+
end
910

10-
assert_geojson p.geojson
11+
test 'should have geojson and geom attribute' do
12+
assert @p.geom.present?
13+
assert_geojson @p.geojson
1114
end
1215

1316
test 'should render properties in as_geojson' do
14-
p = Project.find 'ecookbook'
15-
p.update_column :geom, test_geom
16-
17-
j = p.as_geojson include_properties: true
17+
j = @p.as_geojson include_properties: true
1818
assert_geojson j
19-
assert_equal p.id, j['properties']['id']
20-
assert_equal p.identifier, j['properties']['identifier']
21-
assert_equal p.name, j['properties']['name']
19+
assert_equal @p.id, j['properties']['id']
20+
assert_equal @p.identifier, j['properties']['identifier']
21+
assert_equal @p.name, j['properties']['name']
2222

23-
j = p.as_geojson include_properties: { only: [:id, :identifier] }
23+
j = @p.as_geojson include_properties: { only: [:id, :identifier] }
2424
assert_geojson j
25-
assert_equal p.id, j['properties']['id']
26-
assert_equal p.identifier, j['properties']['identifier']
25+
assert_equal @p.id, j['properties']['id']
26+
assert_equal @p.identifier, j['properties']['identifier']
2727
assert_nil j['properties']['name']
2828
end
2929

test/unit/user_test.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ class UserTest < GttTest
55

66
setup do
77
@user = User.find_by_login 'dlopper'
8-
@user.update_column :geom, test_geom
8+
@user.update_attribute :geojson, test_geojson
9+
end
10+
11+
test 'should set geom from json' do
12+
assert @user.geom.present?
913
end
1014

1115
test 'should have geojson attribute' do

0 commit comments

Comments
 (0)