activerecord-postgis-adapter 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/active_record/connection_adapters/postgis_adapter.rb +9 -8
- data/lib/active_record/connection_adapters/postgis_adapter/common_adapter_methods.rb +6 -6
- data/lib/active_record/connection_adapters/postgis_adapter/main_adapter.rb +18 -33
- data/lib/active_record/connection_adapters/postgis_adapter/spatial_column.rb +12 -8
- data/lib/active_record/connection_adapters/postgis_adapter/spatial_column_info.rb +42 -0
- data/lib/active_record/connection_adapters/postgis_adapter/version.rb +1 -1
- data/test/basic_test.rb +175 -183
- data/test/ddl_test.rb +248 -217
- data/test/nested_class_test.rb +22 -30
- data/test/setup_test.rb +4 -12
- data/test/spatial_queries_test.rb +83 -91
- data/test/tasks_test.rb +145 -153
- metadata +18 -3
data/test/ddl_test.rb
CHANGED
@@ -1,223 +1,254 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
def test_create_point_geometry
|
45
|
-
klass = create_ar_class
|
46
|
-
klass.connection.create_table(:spatial_test) do |t|
|
47
|
-
t.column 'latlon', :point
|
48
|
-
end
|
49
|
-
assert_equal(::RGeo::Feature::Point, klass.columns.last.geometric_type)
|
50
|
-
assert(klass.cached_attributes.include?('latlon'))
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_create_geometry_with_index
|
54
|
-
klass = create_ar_class
|
55
|
-
klass.connection.create_table(:spatial_test) do |t|
|
56
|
-
t.column 'latlon', :geometry
|
57
|
-
end
|
58
|
-
klass.connection.change_table(:spatial_test) do |t|
|
59
|
-
t.index([:latlon], :spatial => true)
|
60
|
-
end
|
61
|
-
assert(klass.connection.indexes(:spatial_test).last.spatial)
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_add_geometry_column
|
65
|
-
klass = create_ar_class
|
66
|
-
klass.connection.create_table(:spatial_test) do |t|
|
67
|
-
t.column('latlon', :geometry)
|
68
|
-
end
|
69
|
-
klass.connection.change_table(:spatial_test) do |t|
|
70
|
-
t.column('geom2', :point, :srid => 4326)
|
71
|
-
t.column('name', :string)
|
72
|
-
end
|
73
|
-
assert_equal(2, klass.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
74
|
-
cols_ = klass.columns
|
75
|
-
assert_equal(::RGeo::Feature::Geometry, cols_[-3].geometric_type)
|
76
|
-
assert_equal(0, cols_[-3].srid)
|
77
|
-
assert_equal(true, cols_[-3].has_spatial_constraints?)
|
78
|
-
assert_equal(::RGeo::Feature::Point, cols_[-2].geometric_type)
|
79
|
-
assert_equal(4326, cols_[-2].srid)
|
80
|
-
assert_equal(false, cols_[-2].geographic?)
|
81
|
-
assert_equal(true, cols_[-2].has_spatial_constraints?)
|
82
|
-
assert_nil(cols_[-1].geometric_type)
|
83
|
-
assert_equal(false, cols_[-1].has_spatial_constraints?)
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_add_geography_column
|
87
|
-
klass = create_ar_class
|
88
|
-
klass.connection.create_table(:spatial_test) do |t|
|
89
|
-
t.column('latlon', :geometry)
|
90
|
-
end
|
91
|
-
klass.connection.change_table(:spatial_test) do |t|
|
92
|
-
t.column('geom2', :point, :srid => 4326, :geographic => true)
|
93
|
-
t.column('name', :string)
|
94
|
-
end
|
95
|
-
assert_equal(1, klass.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
96
|
-
cols_ = klass.columns
|
97
|
-
assert_equal(::RGeo::Feature::Geometry, cols_[-3].geometric_type)
|
98
|
-
assert_equal(0, cols_[-3].srid)
|
99
|
-
assert_equal(true, cols_[-3].has_spatial_constraints?)
|
100
|
-
assert_equal(::RGeo::Feature::Point, cols_[-2].geometric_type)
|
101
|
-
assert_equal(4326, cols_[-2].srid)
|
102
|
-
assert_equal(true, cols_[-2].geographic?)
|
103
|
-
assert_equal(true, cols_[-2].has_spatial_constraints?)
|
104
|
-
assert_nil(cols_[-1].geometric_type)
|
105
|
-
assert_equal(false, cols_[-1].has_spatial_constraints?)
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_drop_geometry_column
|
109
|
-
klass = create_ar_class
|
110
|
-
klass.connection.create_table(:spatial_test) do |t|
|
111
|
-
t.column('latlon', :geometry)
|
112
|
-
t.column('geom2', :point, :srid => 4326)
|
113
|
-
end
|
114
|
-
klass.connection.change_table(:spatial_test) do |t|
|
115
|
-
t.remove('geom2')
|
116
|
-
end
|
117
|
-
assert_equal(1, klass.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
118
|
-
cols_ = klass.columns
|
119
|
-
assert_equal(::RGeo::Feature::Geometry, cols_[-1].geometric_type)
|
120
|
-
assert_equal('latlon', cols_[-1].name)
|
121
|
-
assert_equal(0, cols_[-1].srid)
|
122
|
-
assert_equal(false, cols_[-1].geographic?)
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_drop_geography_column
|
126
|
-
klass = create_ar_class
|
127
|
-
klass.connection.create_table(:spatial_test) do |t|
|
128
|
-
t.column('latlon', :geometry)
|
129
|
-
t.column('geom2', :point, :srid => 4326, :geographic => true)
|
130
|
-
t.column('geom3', :point, :srid => 4326)
|
131
|
-
end
|
132
|
-
klass.connection.change_table(:spatial_test) do |t|
|
133
|
-
t.remove('geom2')
|
134
|
-
end
|
135
|
-
assert_equal(2, klass.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
136
|
-
cols_ = klass.columns
|
137
|
-
assert_equal(::RGeo::Feature::Point, cols_[-1].geometric_type)
|
138
|
-
assert_equal('geom3', cols_[-1].name)
|
139
|
-
assert_equal(false, cols_[-1].geographic?)
|
140
|
-
assert_equal(::RGeo::Feature::Geometry, cols_[-2].geometric_type)
|
141
|
-
assert_equal('latlon', cols_[-2].name)
|
142
|
-
assert_equal(false, cols_[-2].geographic?)
|
143
|
-
end
|
144
|
-
|
145
|
-
def test_create_simple_geometry_using_shortcut
|
146
|
-
klass = create_ar_class
|
147
|
-
klass.connection.create_table(:spatial_test) do |t|
|
148
|
-
t.geometry 'latlon'
|
149
|
-
end
|
150
|
-
assert_equal(1, klass.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
151
|
-
col = klass.columns.last
|
152
|
-
assert_equal(::RGeo::Feature::Geometry, col.geometric_type)
|
153
|
-
assert_equal(false, col.geographic?)
|
154
|
-
assert_equal(0, col.srid)
|
155
|
-
assert(klass.cached_attributes.include?('latlon'))
|
156
|
-
klass.connection.drop_table(:spatial_test)
|
157
|
-
assert_equal(0, klass.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
158
|
-
end
|
159
|
-
|
160
|
-
def test_create_simple_geography_using_shortcut
|
161
|
-
klass = create_ar_class
|
162
|
-
klass.connection.create_table(:spatial_test) do |t|
|
163
|
-
t.geometry 'latlon', :geographic => true
|
164
|
-
end
|
165
|
-
col = klass.columns.last
|
166
|
-
assert_equal(::RGeo::Feature::Geometry, col.geometric_type)
|
167
|
-
assert_equal(true, col.geographic?)
|
168
|
-
assert_equal(4326, col.srid)
|
169
|
-
assert(klass.cached_attributes.include?('latlon'))
|
170
|
-
assert_equal(0, klass.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
171
|
-
end
|
172
|
-
|
173
|
-
def test_create_point_geometry_using_shortcut
|
174
|
-
klass = create_ar_class
|
175
|
-
klass.connection.create_table(:spatial_test) do |t|
|
176
|
-
t.point 'latlon'
|
177
|
-
end
|
178
|
-
assert_equal(::RGeo::Feature::Point, klass.columns.last.geometric_type)
|
179
|
-
assert(klass.cached_attributes.include?('latlon'))
|
180
|
-
end
|
181
|
-
|
182
|
-
def test_create_geometry_with_options
|
183
|
-
klass = create_ar_class
|
184
|
-
klass.connection.create_table(:spatial_test) do |t|
|
185
|
-
t.column 'region', :polygon, :has_m => true, :srid => 3785
|
186
|
-
end
|
187
|
-
assert_equal(1, klass.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
188
|
-
col = klass.columns.last
|
189
|
-
assert_equal(::RGeo::Feature::Polygon, col.geometric_type)
|
190
|
-
assert_equal(false, col.geographic?)
|
191
|
-
assert_equal(false, col.has_z?)
|
192
|
-
assert_equal(true, col.has_m?)
|
193
|
-
assert_equal(3785, col.srid)
|
194
|
-
assert_equal({:has_m => true, :type => 'polygon', :srid => 3785}, col.limit)
|
195
|
-
assert(klass.cached_attributes.include?('region'))
|
196
|
-
klass.connection.drop_table(:spatial_test)
|
197
|
-
assert_equal(0, klass.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
198
|
-
end
|
199
|
-
|
200
|
-
def test_create_geometry_using_limit
|
201
|
-
klass = create_ar_class
|
202
|
-
klass.connection.create_table(:spatial_test) do |t|
|
203
|
-
t.spatial 'region', :limit => {:has_m => true, :srid => 3785, :type => :polygon}
|
204
|
-
end
|
205
|
-
assert_equal(1, klass.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
206
|
-
col = klass.columns.last
|
207
|
-
assert_equal(::RGeo::Feature::Polygon, col.geometric_type)
|
208
|
-
assert_equal(false, col.geographic?)
|
209
|
-
assert_equal(false, col.has_z)
|
210
|
-
assert_equal(true, col.has_m)
|
211
|
-
assert_equal(3785, col.srid)
|
212
|
-
assert_equal({:has_m => true, :type => 'polygon', :srid => 3785}, col.limit)
|
213
|
-
assert(klass.cached_attributes.include?('region'))
|
214
|
-
klass.connection.drop_table(:spatial_test)
|
215
|
-
assert_equal(0, klass.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
216
|
-
end
|
217
|
-
|
218
|
-
end
|
219
|
-
end
|
3
|
+
class DDLTest < ActiveSupport::TestCase # :nodoc:
|
4
|
+
DATABASE_CONFIG_PATH = ::File.dirname(__FILE__) + '/database.yml'
|
5
|
+
OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__) + '/database_local.yml'
|
6
|
+
|
7
|
+
include RGeo::ActiveRecord::AdapterTestHelper
|
8
|
+
|
9
|
+
define_test_methods do
|
10
|
+
def test_create_simple_geometry
|
11
|
+
klass = create_ar_class
|
12
|
+
klass.connection.create_table(:spatial_test) do |t|
|
13
|
+
t.column 'latlon', :geometry
|
14
|
+
end
|
15
|
+
assert_equal(1, klass.connection.select_value(geometry_column_count_query).to_i)
|
16
|
+
col = klass.columns.last
|
17
|
+
assert_equal(::RGeo::Feature::Geometry, col.geometric_type)
|
18
|
+
assert_equal(true, col.has_spatial_constraints?)
|
19
|
+
assert_equal(false, col.geographic?)
|
20
|
+
assert_equal(0, col.srid)
|
21
|
+
assert(klass.cached_attributes.include?('latlon'))
|
22
|
+
klass.connection.drop_table(:spatial_test)
|
23
|
+
assert_equal(0, klass.connection.select_value(geometry_column_count_query).to_i)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_create_simple_geography
|
27
|
+
klass = create_ar_class
|
28
|
+
klass.connection.create_table(:spatial_test) do |t|
|
29
|
+
t.column 'latlon', :geometry, :geographic => true
|
30
|
+
end
|
31
|
+
col = klass.columns.last
|
32
|
+
assert_equal(::RGeo::Feature::Geometry, col.geometric_type)
|
33
|
+
assert_equal(true, col.has_spatial_constraints?)
|
34
|
+
assert_equal(true, col.geographic?)
|
35
|
+
assert_equal(4326, col.srid)
|
36
|
+
assert(klass.cached_attributes.include?('latlon'))
|
37
|
+
assert_equal(0, klass.connection.select_value(geometry_column_count_query).to_i)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_create_point_geometry
|
41
|
+
klass = create_ar_class
|
42
|
+
klass.connection.create_table(:spatial_test) do |t|
|
43
|
+
t.column 'latlon', :point
|
220
44
|
end
|
45
|
+
assert_equal(::RGeo::Feature::Point, klass.columns.last.geometric_type)
|
46
|
+
assert(klass.cached_attributes.include?('latlon'))
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_create_geometry_with_index
|
50
|
+
klass = create_ar_class
|
51
|
+
klass.connection.create_table(:spatial_test) do |t|
|
52
|
+
t.column 'latlon', :geometry
|
53
|
+
end
|
54
|
+
klass.connection.change_table(:spatial_test) do |t|
|
55
|
+
t.index([:latlon], :spatial => true)
|
56
|
+
end
|
57
|
+
assert(klass.connection.indexes(:spatial_test).last.spatial)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_add_geometry_column
|
61
|
+
klass = create_ar_class
|
62
|
+
klass.connection.create_table(:spatial_test) do |t|
|
63
|
+
t.column('latlon', :geometry)
|
64
|
+
end
|
65
|
+
klass.connection.change_table(:spatial_test) do |t|
|
66
|
+
t.column('geom2', :point, :srid => 4326)
|
67
|
+
t.column('name', :string)
|
68
|
+
end
|
69
|
+
assert_equal(2, klass.connection.select_value(geometry_column_count_query).to_i)
|
70
|
+
cols_ = klass.columns
|
71
|
+
assert_equal(::RGeo::Feature::Geometry, cols_[-3].geometric_type)
|
72
|
+
assert_equal(0, cols_[-3].srid)
|
73
|
+
assert_equal(true, cols_[-3].has_spatial_constraints?)
|
74
|
+
assert_equal(::RGeo::Feature::Point, cols_[-2].geometric_type)
|
75
|
+
assert_equal(4326, cols_[-2].srid)
|
76
|
+
assert_equal(false, cols_[-2].geographic?)
|
77
|
+
assert_equal(true, cols_[-2].has_spatial_constraints?)
|
78
|
+
assert_nil(cols_[-1].geometric_type)
|
79
|
+
assert_equal(false, cols_[-1].has_spatial_constraints?)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_add_geometry_column_null_false
|
83
|
+
klass = create_ar_class
|
84
|
+
klass.connection.create_table(:spatial_test) do |t|
|
85
|
+
t.column('latlon', :geometry, null: false)
|
86
|
+
end
|
87
|
+
geometry_column = klass.columns.first
|
88
|
+
|
89
|
+
refute(geometry_column.null, 'Column should be null: false')
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_add_geography_column
|
93
|
+
klass = create_ar_class
|
94
|
+
klass.connection.create_table(:spatial_test) do |t|
|
95
|
+
t.column('latlon', :geometry)
|
96
|
+
end
|
97
|
+
klass.connection.change_table(:spatial_test) do |t|
|
98
|
+
t.column('geom2', :point, :srid => 4326, :geographic => true)
|
99
|
+
t.column('name', :string)
|
100
|
+
end
|
101
|
+
assert_equal(1, klass.connection.select_value(geometry_column_count_query).to_i)
|
102
|
+
cols_ = klass.columns
|
103
|
+
assert_equal(::RGeo::Feature::Geometry, cols_[-3].geometric_type)
|
104
|
+
assert_equal(0, cols_[-3].srid)
|
105
|
+
assert_equal(true, cols_[-3].has_spatial_constraints?)
|
106
|
+
assert_equal(::RGeo::Feature::Point, cols_[-2].geometric_type)
|
107
|
+
assert_equal(4326, cols_[-2].srid)
|
108
|
+
assert_equal(true, cols_[-2].geographic?)
|
109
|
+
assert_equal(true, cols_[-2].has_spatial_constraints?)
|
110
|
+
assert_nil(cols_[-1].geometric_type)
|
111
|
+
assert_equal(false, cols_[-1].has_spatial_constraints?)
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_drop_geometry_column
|
115
|
+
klass = create_ar_class
|
116
|
+
klass.connection.create_table(:spatial_test) do |t|
|
117
|
+
t.column('latlon', :geometry)
|
118
|
+
t.column('geom2', :point, :srid => 4326)
|
119
|
+
end
|
120
|
+
klass.connection.change_table(:spatial_test) do |t|
|
121
|
+
t.remove('geom2')
|
122
|
+
end
|
123
|
+
assert_equal(1, klass.connection.select_value(geometry_column_count_query).to_i)
|
124
|
+
cols_ = klass.columns
|
125
|
+
assert_equal(::RGeo::Feature::Geometry, cols_[-1].geometric_type)
|
126
|
+
assert_equal('latlon', cols_[-1].name)
|
127
|
+
assert_equal(0, cols_[-1].srid)
|
128
|
+
assert_equal(false, cols_[-1].geographic?)
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_drop_geography_column
|
132
|
+
klass = create_ar_class
|
133
|
+
klass.connection.create_table(:spatial_test) do |t|
|
134
|
+
t.column('latlon', :geometry)
|
135
|
+
t.column('geom2', :point, :srid => 4326, :geographic => true)
|
136
|
+
t.column('geom3', :point, :srid => 4326)
|
137
|
+
end
|
138
|
+
klass.connection.change_table(:spatial_test) do |t|
|
139
|
+
t.remove('geom2')
|
140
|
+
end
|
141
|
+
assert_equal(2, klass.connection.select_value(geometry_column_count_query).to_i)
|
142
|
+
cols_ = klass.columns
|
143
|
+
assert_equal(::RGeo::Feature::Point, cols_[-1].geometric_type)
|
144
|
+
assert_equal('geom3', cols_[-1].name)
|
145
|
+
assert_equal(false, cols_[-1].geographic?)
|
146
|
+
assert_equal(::RGeo::Feature::Geometry, cols_[-2].geometric_type)
|
147
|
+
assert_equal('latlon', cols_[-2].name)
|
148
|
+
assert_equal(false, cols_[-2].geographic?)
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_create_simple_geometry_using_shortcut
|
152
|
+
klass = create_ar_class
|
153
|
+
klass.connection.create_table(:spatial_test) do |t|
|
154
|
+
t.geometry 'latlon'
|
155
|
+
end
|
156
|
+
assert_equal(1, klass.connection.select_value(geometry_column_count_query).to_i)
|
157
|
+
col = klass.columns.last
|
158
|
+
assert_equal(::RGeo::Feature::Geometry, col.geometric_type)
|
159
|
+
assert_equal(false, col.geographic?)
|
160
|
+
assert_equal(0, col.srid)
|
161
|
+
assert(klass.cached_attributes.include?('latlon'))
|
162
|
+
klass.connection.drop_table(:spatial_test)
|
163
|
+
assert_equal(0, klass.connection.select_value(geometry_column_count_query).to_i)
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_create_simple_geography_using_shortcut
|
167
|
+
klass = create_ar_class
|
168
|
+
klass.connection.create_table(:spatial_test) do |t|
|
169
|
+
t.geometry 'latlon', :geographic => true
|
170
|
+
end
|
171
|
+
col = klass.columns.last
|
172
|
+
assert_equal(::RGeo::Feature::Geometry, col.geometric_type)
|
173
|
+
assert_equal(true, col.geographic?)
|
174
|
+
assert_equal(4326, col.srid)
|
175
|
+
assert(klass.cached_attributes.include?('latlon'))
|
176
|
+
assert_equal(0, klass.connection.select_value(geometry_column_count_query).to_i)
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_create_point_geometry_using_shortcut
|
180
|
+
klass = create_ar_class
|
181
|
+
klass.connection.create_table(:spatial_test) do |t|
|
182
|
+
t.point 'latlon'
|
183
|
+
end
|
184
|
+
assert_equal(::RGeo::Feature::Point, klass.columns.last.geometric_type)
|
185
|
+
assert(klass.cached_attributes.include?('latlon'))
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_create_geometry_with_options
|
189
|
+
klass = create_ar_class
|
190
|
+
klass.connection.create_table(:spatial_test) do |t|
|
191
|
+
t.column 'region', :polygon, :has_m => true, :srid => 3785
|
192
|
+
end
|
193
|
+
assert_equal(1, klass.connection.select_value(geometry_column_count_query).to_i)
|
194
|
+
col = klass.columns.last
|
195
|
+
assert_equal(::RGeo::Feature::Polygon, col.geometric_type)
|
196
|
+
assert_equal(false, col.geographic?)
|
197
|
+
assert_equal(false, col.has_z?)
|
198
|
+
assert_equal(true, col.has_m?)
|
199
|
+
assert_equal(3785, col.srid)
|
200
|
+
assert_equal({:has_m => true, :type => 'polygon', :srid => 3785}, col.limit)
|
201
|
+
assert(klass.cached_attributes.include?('region'))
|
202
|
+
klass.connection.drop_table(:spatial_test)
|
203
|
+
assert_equal(0, klass.connection.select_value(geometry_column_count_query).to_i)
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_create_geometry_using_limit
|
207
|
+
klass = create_ar_class
|
208
|
+
klass.connection.create_table(:spatial_test) do |t|
|
209
|
+
t.spatial 'region', :limit => {:has_m => true, :srid => 3785, :type => :polygon}
|
210
|
+
end
|
211
|
+
assert_equal(1, klass.connection.select_value(geometry_column_count_query).to_i)
|
212
|
+
col = klass.columns.last
|
213
|
+
assert_equal(::RGeo::Feature::Polygon, col.geometric_type)
|
214
|
+
assert_equal(false, col.geographic?)
|
215
|
+
assert_equal(false, col.has_z)
|
216
|
+
assert_equal(true, col.has_m)
|
217
|
+
assert_equal(3785, col.srid)
|
218
|
+
assert_equal({:has_m => true, :type => 'polygon', :srid => 3785}, col.limit)
|
219
|
+
assert(klass.cached_attributes.include?('region'))
|
220
|
+
klass.connection.drop_table(:spatial_test)
|
221
|
+
assert_equal(0, klass.connection.select_value(geometry_column_count_query).to_i)
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_caches_spatial_column_info
|
225
|
+
klass = create_ar_class
|
226
|
+
klass.connection.create_table(:spatial_test, force: true) do |t|
|
227
|
+
t.point 'latlon'
|
228
|
+
t.point 'other'
|
229
|
+
end
|
230
|
+
::ActiveRecord::ConnectionAdapters::PostGISAdapter::SpatialColumnInfo.any_instance.expects(:all).once.returns({})
|
231
|
+
klass.columns
|
232
|
+
klass.columns
|
233
|
+
end
|
234
|
+
|
235
|
+
def test_no_query_spatial_column_info
|
236
|
+
klass = create_ar_class
|
237
|
+
klass.connection.create_table(:spatial_test, force: true) do |t|
|
238
|
+
t.string 'name'
|
239
|
+
end
|
240
|
+
# `all` queries column info from the database - it should not be called when klass.columns is called
|
241
|
+
::ActiveRecord::ConnectionAdapters::PostGISAdapter::SpatialColumnInfo.any_instance.expects(:all).never
|
242
|
+
# first column is id, second is name
|
243
|
+
refute klass.columns[1].spatial?
|
244
|
+
assert_nil klass.columns[1].has_z
|
245
|
+
end
|
246
|
+
|
247
|
+
private
|
248
|
+
|
249
|
+
def geometry_column_count_query
|
250
|
+
"SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'"
|
221
251
|
end
|
222
252
|
end
|
253
|
+
|
223
254
|
end
|