Skip to content

Commit 74e6226

Browse files
committed
adds tests for patched models #50
1 parent b553077 commit 74e6226

File tree

5 files changed

+140
-9
lines changed

5 files changed

+140
-9
lines changed

test/test_helper.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
11
# Load the Redmine helper
22
require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper')
3+
4+
class GttTest < ActiveSupport::TestCase
5+
6+
def test_wkb
7+
"01030000000100000006000000C84B374110E76040381DD011545A4140C84B3739ACE96040F07E6DCC7A594140C84B37F199E960403CBC2D58E2554140C84B373917E8604098CBC3E188564140C84B37FD36E66040F24C2E959D564140C84B374110E76040381DD011545A4140"
8+
end
9+
10+
def assert_geojson(json)
11+
assert_equal 'Feature', json['type']
12+
assert geom = json['geometry']
13+
assert_equal 'Polygon', geom['type']
14+
assert_equal [[[135.22073422241215,34.70569060003112],[135.30227337646488,34.6990600142143],[135.3000417785645,34.670969984370885],[135.25283489990238,34.676052303889435],[135.1942125396729,34.67668404351015],[135.22073422241215,34.70569060003112]]], geom['coordinates']
15+
end
16+
17+
def assert_geojson_collection(json)
18+
assert_equal 'FeatureCollection', json['type']
19+
assert_equal 1, json['features'].size
20+
assert_geojson json['features'][0]
21+
end
22+
end

test/unit/gtt_map_test.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
require_relative '../test_helper'
22

3-
class GttMapTest < ActiveSupport::TestCase
3+
class GttMapTest < GttTest
44

55
setup do
66
@ts = GttTileSource.create! name: 'test', type: 'ol.source.OSM'
77
end
88

99
test 'should compute json from wkb' do
10-
wkb = "01030000000100000006000000C84B374110E76040381DD011545A4140C84B3739ACE96040F07E6DCC7A594140C84B37F199E960403CBC2D58E2554140C84B373917E8604098CBC3E188564140C84B37FD36E66040F24C2E959D564140C84B374110E76040381DD011545A4140"
11-
m = GttMap.new layers: [@ts], wkb: wkb
12-
13-
assert (json = m.json).present?
14-
assert_equal 'Feature', json['type']
15-
assert geom = json['geometry']
16-
assert_equal 'Polygon', geom['type']
17-
assert_equal [[[135.22073422241215,34.70569060003112],[135.30227337646488,34.6990600142143],[135.3000417785645,34.670969984370885],[135.25283489990238,34.676052303889435],[135.1942125396729,34.67668404351015],[135.22073422241215,34.70569060003112]]], geom['coordinates']
10+
m = GttMap.new layers: [@ts], wkb: test_wkb
11+
assert_geojson m.json
1812
end
1913
end
2014

test/unit/issue_test.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require_relative '../test_helper'
2+
3+
class IssueTest < GttTest
4+
fixtures :projects, :issues, :users
5+
6+
setup do
7+
@project = Project.find 'ecookbook'
8+
@issue = @project.issues.last
9+
@issue.update_column :geom, test_wkb
10+
end
11+
12+
test 'should have geojson attribute' do
13+
assert_geojson @issue.geojson
14+
end
15+
16+
test 'should render properties in as_geojson' do
17+
j = @issue.as_geojson include_properties: true
18+
assert_geojson j
19+
assert_equal @issue.id, j['properties']['id']
20+
assert_equal @issue.subject, j['properties']['subject']
21+
assert_equal @issue.author_id, j['properties']['author_id']
22+
assert_nil j['properties']['geom']
23+
24+
j = @issue.as_geojson include_properties: { only: [:id, :subject] }
25+
assert_geojson j
26+
assert_equal @issue.id, j['properties']['id']
27+
assert_equal @issue.subject, j['properties']['subject']
28+
assert_nil j['properties']['author_id']
29+
assert_nil j['properties']['geom']
30+
end
31+
32+
test 'should render array as geojson' do
33+
j = Issue.array_to_geojson [@issue]
34+
assert_geojson_collection j
35+
end
36+
37+
38+
test 'should have geojson scope' do
39+
assert_geojson_collection Issue.geojson
40+
end
41+
42+
end
43+
44+
45+
46+

test/unit/project_test.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require_relative '../test_helper'
2+
3+
class ProjectTest < GttTest
4+
fixtures :projects
5+
6+
test 'should have geojson attribute' do
7+
p = Project.find 'ecookbook'
8+
p.update_column :geom, test_wkb
9+
10+
assert_geojson p.geojson
11+
end
12+
13+
test 'should render properties in as_geojson' do
14+
p = Project.find 'ecookbook'
15+
p.update_column :geom, test_wkb
16+
17+
j = p.as_geojson include_properties: true
18+
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']
22+
23+
j = p.as_geojson include_properties: { only: [:id, :identifier] }
24+
assert_geojson j
25+
assert_equal p.id, j['properties']['id']
26+
assert_equal p.identifier, j['properties']['identifier']
27+
assert_nil j['properties']['name']
28+
end
29+
30+
end
31+
32+
33+

test/unit/user_test.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
require_relative '../test_helper'
2+
3+
class UserTest < GttTest
4+
fixtures :users
5+
6+
setup do
7+
@user = User.find_by_login 'dlopper'
8+
@user.update_column :geom, test_wkb
9+
end
10+
11+
test 'should have geojson attribute' do
12+
assert_geojson @user.geojson
13+
end
14+
15+
test 'should render properties in as_geojson' do
16+
j = @user.as_geojson include_properties: true
17+
assert_geojson j
18+
assert_equal @user.id, j['properties']['id']
19+
assert_equal @user.lastname, j['properties']['lastname']
20+
assert_equal @user.login, j['properties']['login']
21+
assert_nil j['properties']['geom']
22+
assert_nil j['properties']['auth_source_id']
23+
24+
j = @user.as_geojson include_properties: { only: [:id, :lastname] }
25+
assert_geojson j
26+
assert_equal @user.id, j['properties']['id']
27+
assert_equal @user.lastname, j['properties']['lastname']
28+
assert_nil j['properties']['login']
29+
assert_nil j['properties']['geom']
30+
assert_nil j['properties']['auth_source_id']
31+
end
32+
33+
end
34+
35+
36+
37+
38+

0 commit comments

Comments
 (0)