worlddb-models 2.2.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/Manifest.txt +31 -13
  3. data/README.md +7 -7
  4. data/Rakefile +1 -1
  5. data/lib/worlddb/deleter.rb +6 -1
  6. data/lib/worlddb/helpers/value_helper.rb +117 -0
  7. data/lib/worlddb/matcher.rb +99 -135
  8. data/lib/worlddb/matcher_adm.rb +82 -0
  9. data/lib/worlddb/models/city.rb +30 -208
  10. data/lib/worlddb/models/city_base.rb +220 -0
  11. data/lib/worlddb/models/continent.rb +9 -0
  12. data/lib/worlddb/models/country.rb +21 -4
  13. data/lib/worlddb/models/forward.rb +25 -9
  14. data/lib/worlddb/models/lang.rb +6 -0
  15. data/lib/worlddb/models/place.rb +1 -1
  16. data/lib/worlddb/models/state.rb +83 -0
  17. data/lib/worlddb/models/{region.rb → state_base.rb} +52 -36
  18. data/lib/worlddb/models/tagdb/tag.rb +1 -1
  19. data/lib/worlddb/models.rb +11 -8
  20. data/lib/worlddb/patterns.rb +4 -4
  21. data/lib/worlddb/reader.rb +68 -39
  22. data/lib/worlddb/reader_file.rb +36 -3
  23. data/lib/worlddb/reader_zip.rb +33 -3
  24. data/lib/worlddb/readers/base.rb +149 -0
  25. data/lib/worlddb/readers/city.rb +2 -65
  26. data/lib/worlddb/readers/country.rb +2 -63
  27. data/lib/worlddb/readers/lang.rb +3 -68
  28. data/lib/worlddb/readers/state.rb +61 -0
  29. data/lib/worlddb/readers/state_tree.rb +118 -0
  30. data/lib/worlddb/readers/usage.rb +2 -65
  31. data/lib/worlddb/schema.rb +142 -43
  32. data/lib/worlddb/stats.rb +7 -4
  33. data/lib/worlddb/tree_reader.rb +97 -0
  34. data/lib/worlddb/version.rb +2 -2
  35. data/test/adm/test_fixture_matcher_adm2.rb +73 -0
  36. data/test/{test_fixture_matcher_adm3.rb → adm/test_fixture_matcher_adm3.rb} +6 -6
  37. data/test/adm/test_fixture_matcher_tree.rb +52 -0
  38. data/test/{test_read_adm.rb → adm/test_read_adm.rb} +13 -20
  39. data/test/adm/test_read_tree.rb +63 -0
  40. data/test/data/at-austria/2--n-niederoesterreich/counties.txt +6 -4
  41. data/test/data/at-austria/orte.txt +23 -0
  42. data/test/data/at-austria/setups/tree.txt +9 -0
  43. data/test/data/de-deutschland/3--by-bayern/4--oberfranken/counties.txt +14 -13
  44. data/test/data/de-deutschland/3--by-bayern/4--oberfranken/orte.txt +104 -0
  45. data/test/data/de-deutschland/3--by-bayern/4--oberfranken/orte_ii.txt +17 -0
  46. data/test/data/de-deutschland/3--by-bayern/{districts.txt → parts.txt} +1 -1
  47. data/test/data/de-deutschland/orte.txt +12 -0
  48. data/test/data/de-deutschland/setups/adm.txt +1 -1
  49. data/test/data/de-deutschland/setups/tree.txt +9 -0
  50. data/test/helper.rb +8 -1
  51. data/test/test_fixture_matchers.rb +9 -10
  52. data/test/test_fixture_matchers_ii.rb +20 -19
  53. data/test/test_model_city.rb +26 -9
  54. data/test/{test_model_comp.rb → test_model_compat.rb} +15 -13
  55. data/test/test_model_country.rb +1 -1
  56. data/test/test_model_state.rb +54 -0
  57. data/test/test_model_states_at.rb +111 -0
  58. data/test/test_model_states_de.rb +147 -0
  59. data/test/test_models.rb +10 -3
  60. data/test/test_parse_city.rb +70 -0
  61. data/test/test_parse_country.rb +56 -0
  62. data/test/test_parse_state.rb +46 -0
  63. data/test/test_state_tree_reader_at.rb +54 -0
  64. data/test/test_state_tree_reader_de.rb +71 -0
  65. data/test/test_tree_reader.rb +39 -0
  66. metadata +50 -22
  67. data/lib/worlddb/models/city_compat.rb +0 -27
  68. data/lib/worlddb/models/continent_compat.rb +0 -24
  69. data/lib/worlddb/models/country_compat.rb +0 -35
  70. data/lib/worlddb/models/lang_compat.rb +0 -23
  71. data/lib/worlddb/models/region_compat.rb +0 -26
  72. data/lib/worlddb/readers/region.rb +0 -79
  73. data/test/test_fixture_matcher_adm2.rb +0 -62
  74. data/test/test_model_region.rb +0 -50
@@ -0,0 +1,111 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_model_states_at.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+ class TestModelStatesAt < MiniTest::Test
11
+
12
+ def setup
13
+ # delete all countries, states, cities in in-memory only db
14
+ WorldDb.delete!
15
+ end
16
+
17
+
18
+ def test_n # country > state > county > muni
19
+
20
+ at = Country.create!( key: 'at',
21
+ name: 'Austria',
22
+ code: 'AUT',
23
+ pop: 1,
24
+ area: 1 )
25
+
26
+ n = State.create!( key: 'n',
27
+ name: 'Niederösterreich',
28
+ country_id: at.id,
29
+ pop: 1,
30
+ area: 1 )
31
+
32
+ n2 = State.find_by_key!( 'n' )
33
+ assert_equal n.id, n2.id
34
+
35
+ assert_equal 'Niederösterreich', n.name
36
+ assert_equal 1, n.area
37
+ assert_equal at.id, n.country_id
38
+ assert_equal 1, n.level
39
+ assert_equal 'ADM1', n.place_kind
40
+
41
+ ### test place
42
+ assert_equal 'Niederösterreich', n.place.name
43
+
44
+ ## test assocs
45
+ assert_equal 'Austria', n.country.name
46
+ assert_equal 0, n.parts.count
47
+ assert_equal 0, n.counties.count
48
+ assert_equal 0, n.munis.count
49
+ assert_equal 0, n.cities.count
50
+
51
+ #############################
52
+ # County (Landkreis, Bezirk, etc.)
53
+
54
+ tu = County.create!( key: 'tu',
55
+ name: 'Tulln',
56
+ state_id: n.id,
57
+ pop: 1,
58
+ area: 1 )
59
+
60
+ tu2 = County.find_by_key!( 'tu' )
61
+ assert_equal tu.id, tu2.id
62
+
63
+ assert_equal 'Tulln', tu.name
64
+ assert_equal 1, tu.area
65
+ assert_equal n.id, tu.state_id
66
+ assert_equal 2, tu.level
67
+ assert_equal 'ADM2', tu.place_kind
68
+
69
+ ### test place
70
+ assert_equal 'Tulln', tu.place.name
71
+
72
+ ## test assocs
73
+ assert_equal 'Niederösterreich', tu.state.name
74
+ assert_equal 0, tu.munis.count
75
+ assert_equal 0, tu.cities.count
76
+ assert_equal 1, n.counties.count
77
+ assert_equal 'Tulln', n.counties.first.name
78
+
79
+ #############################
80
+ # Muni (Gemeinde - Markt, Stadt, etc.)
81
+
82
+ gr = Muni.create!( key: 'grafenwoerth',
83
+ name: 'Grafenwörth',
84
+ state_id: n.id,
85
+ county_id: tu.id,
86
+ pop: 1,
87
+ area: 1 )
88
+
89
+ gr2 = Muni.find_by_key!( 'grafenwoerth' )
90
+ assert_equal gr.id, gr2.id
91
+
92
+ assert_equal 'Grafenwörth', gr.name
93
+ assert_equal 1, gr.area
94
+ assert_equal n.id, gr.state_id
95
+ assert_equal tu.id, gr.county_id
96
+ assert_equal 3, gr.level
97
+ assert_equal 'ADM3', gr.place_kind
98
+
99
+ ### test place
100
+ assert_equal 'Grafenwörth', gr.place.name
101
+
102
+ ## test assocs
103
+ assert_equal 'Niederösterreich', gr.county.state.name
104
+ assert_equal 0, gr.cities.count
105
+ assert_equal 1, n.munis.count
106
+ assert_equal 1, tu.munis.count
107
+ assert_equal 'Grafenwörth', n.munis.first.name
108
+ assert_equal 'Grafenwörth', tu.munis.first.name
109
+ end
110
+
111
+ end # class TestModelStatesAt
@@ -0,0 +1,147 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_model_states_de.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+ class TestModelStatesDe < MiniTest::Test
11
+
12
+ def setup
13
+ # delete all countries, states, cities in in-memory only db
14
+ WorldDb.delete!
15
+ end
16
+
17
+
18
+ def test_bayern # country > state > part > county > muni
19
+
20
+ de = Country.create!( key: 'de',
21
+ name: 'Deutschland',
22
+ code: 'DEU',
23
+ pop: 1,
24
+ area: 1 )
25
+
26
+ by = State.create!( key: 'by',
27
+ name: 'Bayern',
28
+ country_id: de.id,
29
+ pop: 1,
30
+ area: 1 )
31
+
32
+ by2 = State.find_by_key!( 'by' )
33
+ assert_equal by.id, by2.id
34
+
35
+ assert_equal 'Bayern', by.name
36
+ assert_equal 1, by.area
37
+ assert_equal de.id, by.country_id
38
+ assert_equal 1, by.level
39
+ assert_equal 'ADM1', by.place_kind
40
+
41
+ ### test place
42
+ assert_equal 'Bayern', by.place.name
43
+
44
+ ## test assocs
45
+ assert_equal 'Deutschland', by.country.name
46
+ assert_equal 0, by.parts.count
47
+ assert_equal 0, by.counties.count
48
+ assert_equal 0, by.munis.count
49
+ assert_equal 0, by.cities.count
50
+
51
+ ############
52
+ # Part
53
+
54
+ ob = Part.create!( key: 'ob',
55
+ name: 'Oberbayern',
56
+ state_id: by.id,
57
+ pop: 1,
58
+ area: 1 )
59
+
60
+ ob2 = Part.find_by_key!( 'ob' )
61
+ assert_equal ob.id, ob2.id
62
+
63
+ assert_equal 'Oberbayern', ob.name
64
+ assert_equal 1, ob.area
65
+ assert_equal by.id, ob.state_id
66
+ assert_equal 2, ob.level
67
+ assert_equal 'ADM2', ob.place_kind
68
+
69
+ ### test place
70
+ assert_equal 'Oberbayern', ob.place.name
71
+
72
+ ## test assocs
73
+ assert_equal 'Bayern', ob.state.name
74
+ assert_equal 0, ob.counties.count
75
+ assert_equal 0, ob.cities.count
76
+ assert_equal 1, by.parts.count
77
+ assert_equal 'Oberbayern', by.parts.first.name
78
+
79
+ #############################
80
+ # County (Landkreis, Bezirk, etc.)
81
+
82
+ fs = County.create!( key: 'fs',
83
+ name: 'Freising',
84
+ state_id: by.id,
85
+ part_id: ob.id,
86
+ pop: 1,
87
+ area: 1,
88
+ level: 3 )
89
+
90
+ fs2 = County.find_by_key!( 'fs' )
91
+ assert_equal fs.id, fs2.id
92
+
93
+ assert_equal 'Freising', fs.name
94
+ assert_equal 1, fs.area
95
+ assert_equal by.id, fs.state_id
96
+ assert_equal ob.id, fs.part_id
97
+ assert_equal 3, fs.level
98
+ assert_equal 'ADM3', fs.place_kind
99
+
100
+ ### test place
101
+ assert_equal 'Freising', fs.place.name
102
+
103
+ ## test assocs
104
+ assert_equal 'Bayern', fs.state.name
105
+ assert_equal 'Oberbayern', fs.part.name
106
+ assert_equal 0, fs.munis.count
107
+ assert_equal 0, fs.cities.count
108
+ assert_equal 1, by.counties.count
109
+ assert_equal 1, ob.counties.count
110
+ assert_equal 'Freising', by.counties.first.name
111
+ assert_equal 'Freising', ob.counties.first.name
112
+
113
+ #############################
114
+ # Muni (Gemeinde - Markt, Stadt, etc.)
115
+
116
+ au = Muni.create!( key: 'auidhallertau',
117
+ name: 'Au i.d. Hallertau',
118
+ state_id: by.id,
119
+ county_id: fs.id,
120
+ pop: 1,
121
+ area: 1,
122
+ level: 4 )
123
+
124
+ au2 = Muni.find_by_key!( 'auidhallertau' )
125
+ assert_equal au.id, au2.id
126
+
127
+ assert_equal 'Au i.d. Hallertau', au.name
128
+ assert_equal 1, au.area
129
+ assert_equal by.id, au.state_id
130
+ assert_equal fs.id, au.county_id
131
+ assert_equal 4, au.level
132
+ assert_equal 'ADM4', au.place_kind
133
+
134
+ ### test place
135
+ assert_equal 'Au i.d. Hallertau', au.place.name
136
+
137
+ ## test assocs
138
+ assert_equal 'Bayern', au.county.state.name
139
+ assert_equal 'Oberbayern', au.county.part.name
140
+ assert_equal 0, au.cities.count
141
+ assert_equal 1, by.munis.count
142
+ assert_equal 1, fs.munis.count
143
+ assert_equal 'Au i.d. Hallertau', by.munis.first.name
144
+ assert_equal 'Au i.d. Hallertau', fs.munis.first.name
145
+ end
146
+
147
+ end # class TestModelStatesDe
data/test/test_models.rb CHANGED
@@ -6,7 +6,7 @@ require 'helper'
6
6
  class TestModels < MiniTest::Test
7
7
 
8
8
  def setup
9
- # delete all countries, regions, cities in in-memory only db
9
+ # delete all countries, states, cities in in-memory only db
10
10
  WorldDb.delete!
11
11
  end
12
12
 
@@ -15,8 +15,15 @@ class TestModels < MiniTest::Test
15
15
  assert_equal 0, Place.count
16
16
  assert_equal 0, Continent.count
17
17
  assert_equal 0, Country.count
18
- assert_equal 0, Region.count
18
+
19
+ assert_equal 0, State.count
20
+ assert_equal 0, Part.count
21
+ assert_equal 0, County.count
22
+ assert_equal 0, Muni.count
23
+
24
+ assert_equal 0, Metro.count
19
25
  assert_equal 0, City.count
26
+ assert_equal 0, District.count
20
27
 
21
28
  assert_equal 0, Lang.count
22
29
  assert_equal 0, Usage.count
@@ -27,7 +34,7 @@ class TestModels < MiniTest::Test
27
34
  def test_place_assoc_counts
28
35
  # assert_equal 0, Continent.new.place.count
29
36
  # assert_equal 0, Country.new.place.count
30
- # assert_equal 0, Region.new.place.count
37
+ # assert_equal 0, State.new.place.count
31
38
  # assert_equal 0, City.new.place.count
32
39
  end
33
40
 
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_parse_city.rb
6
+
7
+ require 'helper'
8
+
9
+ class TestParseCity < MiniTest::Test
10
+
11
+ def setup
12
+ # delete all countries, states, cities in in-memory only db
13
+ WorldDb.delete!
14
+ end
15
+
16
+
17
+ def test_at
18
+
19
+ at = Country.parse( 'at',
20
+ 'Austria',
21
+ 'AUT',
22
+ '83_871 km²',
23
+ '8_414_638' )
24
+
25
+ w = State.parse( 'w',
26
+ 'Wien',
27
+ country_id: at.id )
28
+
29
+ c = City.parse( 'wien',
30
+ 'Wien',
31
+ 'W',
32
+ '1_731_236',
33
+ 'm:1_724_000',
34
+ country_id: at.id )
35
+
36
+ c2 = City.find_by!( key: 'wien' )
37
+ assert_equal c2.id, c.id
38
+
39
+ assert_equal 'Wien', c.name
40
+ assert_equal 1_731_236, c.pop
41
+ assert_equal w.id, c.state_id
42
+ assert_equal at.id, c.country_id
43
+
44
+ ### test place
45
+ assert_equal 'Wien', c.place.name
46
+
47
+ ## test assocs
48
+ assert_equal 'Wien', c.state.name
49
+ assert_equal 'Austria', c.state.country.name
50
+ assert_equal 'Austria', c.country.name
51
+
52
+
53
+ #####
54
+ # check (auto-)added metro record
55
+
56
+ m = Metro.find_by!( key: 'wien' )
57
+ assert_equal 'Wien', m.name
58
+ assert_equal 1_724_000, m.pop
59
+ assert_equal at.id, m.country_id
60
+
61
+ ## test assocs
62
+ assert_equal 1, m.cities.count
63
+ assert_equal 'Wien', m.cities.first.name
64
+ assert_equal 'Austria', m.country.name
65
+
66
+ assert_equal 'Wien', c.metro.name
67
+ assert_equal m.id, c.metro.id
68
+ end
69
+
70
+ end # class TestParseCity
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_parse_country.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+ class TestParseCountry < MiniTest::Test
11
+
12
+ def setup
13
+ # delete all countries, states, cities in in-memory only db
14
+ WorldDb.delete!
15
+ end
16
+
17
+ def test_to_path
18
+ eu = Continent.create!( key: 'eu', name: 'Europe' )
19
+
20
+ assert_equal 'europe', eu.slug
21
+
22
+ at = Country.parse( 'at',
23
+ 'Austria',
24
+ 'AUT',
25
+ '83_871 km²',
26
+ '8_414_638',
27
+ continent: eu )
28
+
29
+ assert_equal 'austria', at.slug
30
+ assert_equal 'europe/at-austria', at.to_path
31
+ end
32
+
33
+ def test_at
34
+
35
+ c = Country.parse( 'at',
36
+ 'Austria',
37
+ 'AUT',
38
+ '83_871 km²',
39
+ '8_414_638',
40
+ 'un|fifa|uefa|eu|euro|schengen|central_europe|western_europe' )
41
+
42
+ c2 = Country.find_by!( key: 'at' )
43
+ assert_equal c.id, c2.id
44
+
45
+ assert_equal 'Austria', c.name
46
+ assert_equal 8_414_638, c.pop
47
+ assert_equal 83_871, c.area
48
+ ## todo: assert tag count; add supra:eu etc.
49
+
50
+ ### test place
51
+ assert_equal 'Austria', c.place.name
52
+ end
53
+
54
+
55
+ end # class TestParseCountry
56
+
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_parse_state.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+ class TestParseState < MiniTest::Test
11
+
12
+ def setup
13
+ # delete all countries, states, cities in in-memory only db
14
+ WorldDb.delete!
15
+ end
16
+
17
+ def test_at
18
+
19
+ at = Country.parse( 'at',
20
+ 'Austria',
21
+ 'AUT',
22
+ '8_414_638 km²',
23
+ '83_871' )
24
+
25
+ w = State.parse( 'w',
26
+ 'Wien',
27
+ '415 km²',
28
+ 'eastern austria',
29
+ country_id: at.id )
30
+
31
+ w2 = State.find_by!( key: 'w' )
32
+ assert_equal w.id, w2.id
33
+
34
+ assert_equal 'Wien', w.name
35
+ assert_equal 415, w.area
36
+ assert_equal at.id, w.country_id
37
+
38
+ ### test place
39
+ assert_equal 'Wien', w.place.name
40
+
41
+ ## test assocs
42
+ assert_equal 'Austria', w.country.name
43
+ end
44
+
45
+ end # class TestParseState
46
+
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_state_tree_reader_at.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+ class TestStateTreeReaderAt < MiniTest::Test
11
+
12
+ def setup
13
+ # delete all countries, states, cities in in-memory only db
14
+ WorldDb.delete!
15
+
16
+ Country.create!( key: 'at',
17
+ name: 'Austria',
18
+ code: 'AUT',
19
+ pop: 0,
20
+ area: 0 )
21
+
22
+ reader = WorldDb::Reader.new( "#{WorldDb.root}/test/data/at-austria" )
23
+ reader.load_setup( 'setups/adm' )
24
+ end
25
+
26
+ def test_orte
27
+ at = Country.find_by!( key: 'at' )
28
+ more_attribs = { country_id: at.id }
29
+ reader = WorldDb::StateTreeReader.from_file( "#{WorldDb.root}/test/data/at-austria/orte.txt",
30
+ more_attribs )
31
+ reader.read
32
+
33
+ n = State.find_by!( key: 'n' )
34
+ assert_equal 'Niederösterreich [Lower Austria]', n.name
35
+ assert_equal 25, n.counties.count
36
+
37
+ ks = County.find_by!( key: 'ks' )
38
+ assert_equal 'Krems an der Donau (Stadt)', ks.name
39
+ assert_equal 1, ks.munis.count
40
+
41
+ k = Muni.find_by!( key: 'kremsanderdonau' ) ## Statutarstadt (Gemeinde)
42
+ assert_equal 'Krems an der Donau', k.name
43
+ assert_equal 12, k.cities.count
44
+ assert_equal 'Krems an der Donau (Stadt)', k.county.name
45
+
46
+ gneixendorf = City.find_by!( key: 'gneixendorf' )
47
+ assert_equal 'Gneixendorf', gneixendorf.name
48
+ assert_equal 'Krems an der Donau', gneixendorf.muni.name
49
+ assert_equal 'Krems an der Donau (Stadt)', gneixendorf.muni.county.name
50
+ assert_equal 'Niederösterreich [Lower Austria]', gneixendorf.muni.county.state.name
51
+ end
52
+
53
+ end # class TestStateTreeReaderAt
54
+
@@ -0,0 +1,71 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_state_tree_reader_de.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+ class TestStateTreeReaderDe < MiniTest::Test
11
+
12
+ def setup
13
+ # delete all countries, states, cities in in-memory only db
14
+ WorldDb.delete!
15
+
16
+ Country.create!( key: 'de',
17
+ name: 'Germany',
18
+ code: 'GER',
19
+ pop: 0,
20
+ area: 0 )
21
+
22
+ reader = WorldDb::Reader.new( "#{WorldDb.root}/test/data/de-deutschland" )
23
+ reader.load_setup( 'setups/adm' )
24
+ end
25
+
26
+ def test_oberfranken_ii ## small (short) version
27
+ de = Country.find_by!( key: 'de' )
28
+ more_attribs = { country_id: de.id }
29
+ reader = WorldDb::StateTreeReader.from_file( "#{WorldDb.root}/test/data/de-deutschland/3--by-bayern/4--oberfranken/orte_ii.txt",
30
+ more_attribs )
31
+ reader.read
32
+
33
+ ofr = Part.find_by!( key: 'ofr' )
34
+ assert_equal 'Oberfranken', ofr.name
35
+ assert_equal 13, ofr.counties.count
36
+
37
+ ba = County.find_by!( key: 'ba' )
38
+ assert_equal 'Bamberg (Stadt)', ba.name
39
+ assert_equal 1, ba.munis.count
40
+
41
+ baland = County.find_by!( key: 'baland' )
42
+ assert_equal 'Bamberg (Land)', baland.name
43
+ assert_equal 2, baland.munis.count
44
+
45
+ hallstadt = Muni.find_by!( key: 'hallstadt' )
46
+ assert_equal 'Hallstadt', hallstadt.name
47
+ assert_equal 2, hallstadt.cities.count
48
+ assert_equal 'Bamberg (Land)', hallstadt.county.name
49
+
50
+ doerfleins = City.find_by!( key: 'doerfleins' )
51
+ assert_equal 'Dörfleins', doerfleins.name
52
+ assert_equal 'Hallstadt', doerfleins.muni.name
53
+ assert_equal 'Bamberg (Land)', doerfleins.muni.county.name
54
+ assert_equal 'Oberfranken', doerfleins.muni.county.part.name
55
+ end
56
+
57
+
58
+ def test_oberfranken
59
+ de = Country.find_by!( key: 'de' )
60
+ more_attribs = { country_id: de.id }
61
+ reader = WorldDb::StateTreeReader.from_file( "#{WorldDb.root}/test/data/de-deutschland/3--by-bayern/4--oberfranken/orte.txt",
62
+ more_attribs )
63
+ reader.read
64
+
65
+ ba = County.find_by!( key: 'ba' )
66
+ assert_equal 'Bamberg (Stadt)', ba.name
67
+ assert_equal 1, ba.munis.count
68
+ end
69
+
70
+ end # class TestStateTreeReaderDe
71
+
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_tree_reader.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+ class TestTreeReader < MiniTest::Test
11
+
12
+ def setup
13
+ # delete all countries, states, cities in in-memory only db
14
+ WorldDb.delete!
15
+ end
16
+
17
+
18
+ def test_oberfranken
19
+ reader = TreeReader.from_file( "#{WorldDb.root}/test/data/de-deutschland/3--by-bayern/4--oberfranken/orte.txt" )
20
+
21
+ reader.each_line do |_|
22
+ ## do nothing for now
23
+ end
24
+
25
+ assert true ## assume everything ok if we get here
26
+ end
27
+
28
+ def test_de
29
+ reader = TreeReader.from_file( "#{WorldDb.root}/test/data/de-deutschland/orte.txt" )
30
+
31
+ reader.each_line do |_|
32
+ ## do nothing for now
33
+ end
34
+
35
+ assert true ## assume everything ok if we get here
36
+ end
37
+
38
+ end # class TestTreeReader
39
+