activerecord-postgis-adapter 1.0.0 → 1.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/Documentation.rdoc +6 -8
- data/History.rdoc +5 -0
- data/README.rdoc +22 -22
- data/lib/active_record/connection_adapters/postgis_adapter.rb +9 -14
- data/lib/active_record/connection_adapters/postgis_adapter/rails4/create_connection.rb +11 -13
- data/lib/active_record/connection_adapters/postgis_adapter/rails4/main_adapter.rb +122 -102
- data/lib/active_record/connection_adapters/postgis_adapter/rails4/postgis_database_tasks.rb +20 -44
- data/lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_column.rb +48 -69
- data/lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_table_definition.rb +52 -55
- data/lib/active_record/connection_adapters/postgis_adapter/shared/arel_tosql.rb +2 -2
- data/lib/active_record/connection_adapters/postgis_adapter/shared/common_adapter_methods.rb +9 -9
- data/lib/active_record/connection_adapters/postgis_adapter/shared/setup.rb +1 -11
- data/lib/active_record/connection_adapters/postgis_adapter/version.rb +1 -1
- data/test/basic_test.rb +190 -0
- data/test/ddl_test.rb +279 -0
- data/test/{tc_nested_class.rb → nested_class_test.rb} +7 -15
- data/test/setup_test.rb +17 -0
- data/test/spatial_queries_test.rb +105 -0
- data/test/test_helper.rb +8 -0
- data/test/test_tasks.rb +111 -0
- metadata +24 -34
- data/test/tc_basic.rb +0 -212
- data/test/tc_ddl.rb +0 -279
- data/test/tc_spatial_queries.rb +0 -126
- data/test/tc_tasks.rb +0 -112
data/test/tc_ddl.rb
DELETED
@@ -1,279 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'rgeo/active_record/adapter_test_helper'
|
3
|
-
|
4
|
-
module RGeo
|
5
|
-
module ActiveRecord # :nodoc:
|
6
|
-
module PostGISAdapter # :nodoc:
|
7
|
-
module Tests # :nodoc:
|
8
|
-
class TestDDL < ::MiniTest::Test # :nodoc:
|
9
|
-
DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database.yml'
|
10
|
-
OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database_local.yml'
|
11
|
-
include AdapterTestHelper
|
12
|
-
|
13
|
-
define_test_methods do
|
14
|
-
def test_create_simple_geometry
|
15
|
-
klass_ = create_ar_class
|
16
|
-
klass_.connection.create_table(:spatial_test) do |t_|
|
17
|
-
t_.column 'latlon', :geometry
|
18
|
-
end
|
19
|
-
assert_equal(1, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
20
|
-
col_ = klass_.columns.last
|
21
|
-
assert_equal(::RGeo::Feature::Geometry, col_.geometric_type)
|
22
|
-
assert_equal(true, col_.has_spatial_constraints?)
|
23
|
-
assert_equal(false, col_.geographic?)
|
24
|
-
assert_equal(0, col_.srid)
|
25
|
-
assert(klass_.cached_attributes.include?('latlon'))
|
26
|
-
klass_.connection.drop_table(:spatial_test)
|
27
|
-
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
28
|
-
end
|
29
|
-
|
30
|
-
# no_constraints no longer supported in PostGIS 2.0
|
31
|
-
def _test_create_no_constraints_geometry
|
32
|
-
klass_ = create_ar_class
|
33
|
-
klass_.connection.create_table(:spatial_test) do |t_|
|
34
|
-
t_.column 'geom', :geometry, :limit => {:no_constraints => true}
|
35
|
-
end
|
36
|
-
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
37
|
-
col_ = klass_.columns.last
|
38
|
-
assert_equal(::RGeo::Feature::Geometry, col_.geometric_type)
|
39
|
-
assert_equal(false, col_.geographic?)
|
40
|
-
assert_equal(false, col_.has_spatial_constraints?)
|
41
|
-
assert_nil(col_.srid)
|
42
|
-
assert(klass_.cached_attributes.include?('geom'))
|
43
|
-
klass_.connection.drop_table(:spatial_test)
|
44
|
-
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_create_simple_geography
|
48
|
-
klass_ = create_ar_class
|
49
|
-
klass_.connection.create_table(:spatial_test) do |t_|
|
50
|
-
t_.column 'latlon', :geometry, :geographic => true
|
51
|
-
end
|
52
|
-
col_ = klass_.columns.last
|
53
|
-
assert_equal(::RGeo::Feature::Geometry, col_.geometric_type)
|
54
|
-
assert_equal(true, col_.has_spatial_constraints?)
|
55
|
-
assert_equal(true, col_.geographic?)
|
56
|
-
assert_equal(4326, col_.srid)
|
57
|
-
assert(klass_.cached_attributes.include?('latlon'))
|
58
|
-
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_create_point_geometry
|
62
|
-
klass_ = create_ar_class
|
63
|
-
klass_.connection.create_table(:spatial_test) do |t_|
|
64
|
-
t_.column 'latlon', :point
|
65
|
-
end
|
66
|
-
assert_equal(::RGeo::Feature::Point, klass_.columns.last.geometric_type)
|
67
|
-
assert(klass_.cached_attributes.include?('latlon'))
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_create_geometry_with_index
|
71
|
-
klass_ = create_ar_class
|
72
|
-
klass_.connection.create_table(:spatial_test) do |t_|
|
73
|
-
t_.column 'latlon', :geometry
|
74
|
-
end
|
75
|
-
klass_.connection.change_table(:spatial_test) do |t_|
|
76
|
-
t_.index([:latlon], :spatial => true)
|
77
|
-
end
|
78
|
-
assert(klass_.connection.indexes(:spatial_test).last.spatial)
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_add_geometry_column
|
82
|
-
klass_ = create_ar_class
|
83
|
-
klass_.connection.create_table(:spatial_test) do |t_|
|
84
|
-
t_.column('latlon', :geometry)
|
85
|
-
end
|
86
|
-
klass_.connection.change_table(:spatial_test) do |t_|
|
87
|
-
t_.column('geom2', :point, :srid => 4326)
|
88
|
-
t_.column('name', :string)
|
89
|
-
end
|
90
|
-
assert_equal(2, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
91
|
-
cols_ = klass_.columns
|
92
|
-
assert_equal(::RGeo::Feature::Geometry, cols_[-3].geometric_type)
|
93
|
-
assert_equal(0, cols_[-3].srid)
|
94
|
-
assert_equal(true, cols_[-3].has_spatial_constraints?)
|
95
|
-
assert_equal(::RGeo::Feature::Point, cols_[-2].geometric_type)
|
96
|
-
assert_equal(4326, cols_[-2].srid)
|
97
|
-
assert_equal(false, cols_[-2].geographic?)
|
98
|
-
assert_equal(true, cols_[-2].has_spatial_constraints?)
|
99
|
-
assert_nil(cols_[-1].geometric_type)
|
100
|
-
assert_equal(false, cols_[-1].has_spatial_constraints?)
|
101
|
-
end
|
102
|
-
|
103
|
-
# no_constraints no longer supported in PostGIS 2.0
|
104
|
-
def _test_add_no_constraints_geometry_column
|
105
|
-
klass_ = create_ar_class
|
106
|
-
klass_.connection.create_table(:spatial_test) do |t_|
|
107
|
-
t_.column('latlon', :geometry)
|
108
|
-
end
|
109
|
-
klass_.connection.change_table(:spatial_test) do |t_|
|
110
|
-
t_.column('geom2', :geometry, :no_constraints => true)
|
111
|
-
t_.column('name', :string)
|
112
|
-
end
|
113
|
-
assert_equal(1, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
114
|
-
cols_ = klass_.columns
|
115
|
-
assert_equal(::RGeo::Feature::Geometry, cols_[-3].geometric_type)
|
116
|
-
assert_equal(0, cols_[-3].srid)
|
117
|
-
assert_equal(true, cols_[-3].has_spatial_constraints?)
|
118
|
-
assert_equal(::RGeo::Feature::Geometry, cols_[-2].geometric_type)
|
119
|
-
assert_nil(cols_[-2].srid)
|
120
|
-
assert_equal(false, cols_[-2].geographic?)
|
121
|
-
assert_equal(false, cols_[-2].has_spatial_constraints?)
|
122
|
-
assert_nil(cols_[-1].geometric_type)
|
123
|
-
assert_equal(false, cols_[-1].has_spatial_constraints?)
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_add_geography_column
|
127
|
-
klass_ = create_ar_class
|
128
|
-
klass_.connection.create_table(:spatial_test) do |t_|
|
129
|
-
t_.column('latlon', :geometry)
|
130
|
-
end
|
131
|
-
klass_.connection.change_table(:spatial_test) do |t_|
|
132
|
-
t_.column('geom2', :point, :srid => 4326, :geographic => true)
|
133
|
-
t_.column('name', :string)
|
134
|
-
end
|
135
|
-
assert_equal(1, 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::Geometry, cols_[-3].geometric_type)
|
138
|
-
assert_equal(0, cols_[-3].srid)
|
139
|
-
assert_equal(true, cols_[-3].has_spatial_constraints?)
|
140
|
-
assert_equal(::RGeo::Feature::Point, cols_[-2].geometric_type)
|
141
|
-
assert_equal(4326, cols_[-2].srid)
|
142
|
-
assert_equal(true, cols_[-2].geographic?)
|
143
|
-
assert_equal(true, cols_[-2].has_spatial_constraints?)
|
144
|
-
assert_nil(cols_[-1].geometric_type)
|
145
|
-
assert_equal(false, cols_[-1].has_spatial_constraints?)
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_drop_geometry_column
|
149
|
-
klass_ = create_ar_class
|
150
|
-
klass_.connection.create_table(:spatial_test) do |t_|
|
151
|
-
t_.column('latlon', :geometry)
|
152
|
-
t_.column('geom2', :point, :srid => 4326)
|
153
|
-
end
|
154
|
-
klass_.connection.change_table(:spatial_test) do |t_|
|
155
|
-
t_.remove('geom2')
|
156
|
-
end
|
157
|
-
assert_equal(1, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
158
|
-
cols_ = klass_.columns
|
159
|
-
assert_equal(::RGeo::Feature::Geometry, cols_[-1].geometric_type)
|
160
|
-
assert_equal('latlon', cols_[-1].name)
|
161
|
-
assert_equal(0, cols_[-1].srid)
|
162
|
-
assert_equal(false, cols_[-1].geographic?)
|
163
|
-
end
|
164
|
-
|
165
|
-
def test_drop_geography_column
|
166
|
-
klass_ = create_ar_class
|
167
|
-
klass_.connection.create_table(:spatial_test) do |t_|
|
168
|
-
t_.column('latlon', :geometry)
|
169
|
-
t_.column('geom2', :point, :srid => 4326, :geographic => true)
|
170
|
-
t_.column('geom3', :point, :srid => 4326)
|
171
|
-
end
|
172
|
-
klass_.connection.change_table(:spatial_test) do |t_|
|
173
|
-
t_.remove('geom2')
|
174
|
-
end
|
175
|
-
assert_equal(2, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
176
|
-
cols_ = klass_.columns
|
177
|
-
assert_equal(::RGeo::Feature::Point, cols_[-1].geometric_type)
|
178
|
-
assert_equal('geom3', cols_[-1].name)
|
179
|
-
assert_equal(false, cols_[-1].geographic?)
|
180
|
-
assert_equal(::RGeo::Feature::Geometry, cols_[-2].geometric_type)
|
181
|
-
assert_equal('latlon', cols_[-2].name)
|
182
|
-
assert_equal(false, cols_[-2].geographic?)
|
183
|
-
end
|
184
|
-
|
185
|
-
def test_create_simple_geometry_using_shortcut
|
186
|
-
klass_ = create_ar_class
|
187
|
-
klass_.connection.create_table(:spatial_test) do |t_|
|
188
|
-
t_.geometry 'latlon'
|
189
|
-
end
|
190
|
-
assert_equal(1, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
191
|
-
col_ = klass_.columns.last
|
192
|
-
assert_equal(::RGeo::Feature::Geometry, col_.geometric_type)
|
193
|
-
assert_equal(false, col_.geographic?)
|
194
|
-
assert_equal(0, col_.srid)
|
195
|
-
assert(klass_.cached_attributes.include?('latlon'))
|
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
|
-
# no_constraints no longer supported in PostGIS 2.0
|
201
|
-
def _test_create_no_constraints_geometry_using_shortcut
|
202
|
-
klass_ = create_ar_class
|
203
|
-
klass_.connection.create_table(:spatial_test) do |t_|
|
204
|
-
t_.spatial 'geom', :no_constraints => true
|
205
|
-
end
|
206
|
-
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
207
|
-
col_ = klass_.columns.last
|
208
|
-
assert_equal(::RGeo::Feature::Geometry, col_.geometric_type)
|
209
|
-
assert_equal(false, col_.geographic?)
|
210
|
-
assert_nil(col_.srid)
|
211
|
-
assert(klass_.cached_attributes.include?('geom'))
|
212
|
-
klass_.connection.drop_table(:spatial_test)
|
213
|
-
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
214
|
-
end
|
215
|
-
|
216
|
-
def test_create_simple_geography_using_shortcut
|
217
|
-
klass_ = create_ar_class
|
218
|
-
klass_.connection.create_table(:spatial_test) do |t_|
|
219
|
-
t_.geometry 'latlon', :geographic => true
|
220
|
-
end
|
221
|
-
col_ = klass_.columns.last
|
222
|
-
assert_equal(::RGeo::Feature::Geometry, col_.geometric_type)
|
223
|
-
assert_equal(true, col_.geographic?)
|
224
|
-
assert_equal(4326, col_.srid)
|
225
|
-
assert(klass_.cached_attributes.include?('latlon'))
|
226
|
-
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
227
|
-
end
|
228
|
-
|
229
|
-
def test_create_point_geometry_using_shortcut
|
230
|
-
klass_ = create_ar_class
|
231
|
-
klass_.connection.create_table(:spatial_test) do |t_|
|
232
|
-
t_.point 'latlon'
|
233
|
-
end
|
234
|
-
assert_equal(::RGeo::Feature::Point, klass_.columns.last.geometric_type)
|
235
|
-
assert(klass_.cached_attributes.include?('latlon'))
|
236
|
-
end
|
237
|
-
|
238
|
-
def test_create_geometry_with_options
|
239
|
-
klass_ = create_ar_class
|
240
|
-
klass_.connection.create_table(:spatial_test) do |t_|
|
241
|
-
t_.column 'region', :polygon, :has_m => true, :srid => 3785
|
242
|
-
end
|
243
|
-
assert_equal(1, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
244
|
-
col_ = klass_.columns.last
|
245
|
-
assert_equal(::RGeo::Feature::Polygon, col_.geometric_type)
|
246
|
-
assert_equal(false, col_.geographic?)
|
247
|
-
assert_equal(false, col_.has_z?)
|
248
|
-
assert_equal(true, col_.has_m?)
|
249
|
-
assert_equal(3785, col_.srid)
|
250
|
-
assert_equal({:has_m => true, :type => 'polygon', :srid => 3785}, col_.limit)
|
251
|
-
assert(klass_.cached_attributes.include?('region'))
|
252
|
-
klass_.connection.drop_table(:spatial_test)
|
253
|
-
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
254
|
-
end
|
255
|
-
|
256
|
-
def test_create_geometry_using_limit
|
257
|
-
klass_ = create_ar_class
|
258
|
-
klass_.connection.create_table(:spatial_test) do |t_|
|
259
|
-
t_.spatial 'region', :limit => {:has_m => true, :srid => 3785, :type => :polygon}
|
260
|
-
end
|
261
|
-
assert_equal(1, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
262
|
-
col_ = klass_.columns.last
|
263
|
-
assert_equal(::RGeo::Feature::Polygon, col_.geometric_type)
|
264
|
-
assert_equal(false, col_.geographic?)
|
265
|
-
assert_equal(false, col_.has_z)
|
266
|
-
assert_equal(true, col_.has_m)
|
267
|
-
assert_equal(3785, col_.srid)
|
268
|
-
assert_equal({:has_m => true, :type => 'polygon', :srid => 3785}, col_.limit)
|
269
|
-
assert(klass_.cached_attributes.include?('region'))
|
270
|
-
klass_.connection.drop_table(:spatial_test)
|
271
|
-
assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
272
|
-
end
|
273
|
-
|
274
|
-
end
|
275
|
-
end
|
276
|
-
end
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|
data/test/tc_spatial_queries.rb
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'rgeo/active_record/adapter_test_helper'
|
3
|
-
|
4
|
-
|
5
|
-
module RGeo
|
6
|
-
module ActiveRecord # :nodoc:
|
7
|
-
module PostGISAdapter # :nodoc:
|
8
|
-
module Tests # :nodoc:
|
9
|
-
|
10
|
-
class TestSpatialQueries < ::MiniTest::Test # :nodoc:
|
11
|
-
|
12
|
-
DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database.yml'
|
13
|
-
OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database_local.yml'
|
14
|
-
include AdapterTestHelper
|
15
|
-
|
16
|
-
define_test_methods do
|
17
|
-
|
18
|
-
|
19
|
-
def populate_ar_class(content_)
|
20
|
-
klass_ = create_ar_class
|
21
|
-
case content_
|
22
|
-
when :mercator_point
|
23
|
-
klass_.connection.create_table(:spatial_test) do |t_|
|
24
|
-
t_.column 'latlon', :point, :srid => 3785
|
25
|
-
end
|
26
|
-
when :latlon_point_geographic
|
27
|
-
klass_.connection.create_table(:spatial_test) do |t_|
|
28
|
-
t_.column 'latlon', :point, :srid => 4326, :geographic => true
|
29
|
-
end
|
30
|
-
when :path_linestring
|
31
|
-
klass_.connection.create_table(:spatial_test) do |t_|
|
32
|
-
t_.column 'path', :line_string, :srid => 3785
|
33
|
-
end
|
34
|
-
end
|
35
|
-
klass_
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
def test_query_point
|
40
|
-
klass_ = populate_ar_class(:mercator_point)
|
41
|
-
obj_ = klass_.new
|
42
|
-
obj_.latlon = @factory.point(1.0, 2.0)
|
43
|
-
obj_.save!
|
44
|
-
id_ = obj_.id
|
45
|
-
obj2_ = klass_.where(:latlon => @factory.multi_point([@factory.point(1.0, 2.0)])).first
|
46
|
-
refute_nil(obj2_)
|
47
|
-
assert_equal(id_, obj2_.id)
|
48
|
-
obj3_ = klass_.where(:latlon => @factory.point(2.0, 2.0)).first
|
49
|
-
assert_nil(obj3_)
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
def test_query_point_wkt
|
54
|
-
klass_ = populate_ar_class(:mercator_point)
|
55
|
-
obj_ = klass_.new
|
56
|
-
obj_.latlon = @factory.point(1.0, 2.0)
|
57
|
-
obj_.save!
|
58
|
-
id_ = obj_.id
|
59
|
-
obj2_ = klass_.where(:latlon => 'SRID=3785;POINT(1 2)').first
|
60
|
-
refute_nil(obj2_)
|
61
|
-
assert_equal(id_, obj2_.id)
|
62
|
-
obj3_ = klass_.where(:latlon => 'SRID=3785;POINT(2 2)').first
|
63
|
-
assert_nil(obj3_)
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
if ::RGeo::ActiveRecord.spatial_expressions_supported?
|
68
|
-
|
69
|
-
|
70
|
-
def test_query_st_distance
|
71
|
-
klass_ = populate_ar_class(:mercator_point)
|
72
|
-
obj_ = klass_.new
|
73
|
-
obj_.latlon = @factory.point(1.0, 2.0)
|
74
|
-
obj_.save!
|
75
|
-
id_ = obj_.id
|
76
|
-
obj2_ = klass_.where(klass_.arel_table[:latlon].st_distance('SRID=3785;POINT(2 3)').lt(2)).first
|
77
|
-
refute_nil(obj2_)
|
78
|
-
assert_equal(id_, obj2_.id)
|
79
|
-
obj3_ = klass_.where(klass_.arel_table[:latlon].st_distance('SRID=3785;POINT(2 3)').gt(2)).first
|
80
|
-
assert_nil(obj3_)
|
81
|
-
end
|
82
|
-
|
83
|
-
|
84
|
-
def test_query_st_distance_from_constant
|
85
|
-
klass_ = populate_ar_class(:mercator_point)
|
86
|
-
obj_ = klass_.new
|
87
|
-
obj_.latlon = @factory.point(1.0, 2.0)
|
88
|
-
obj_.save!
|
89
|
-
id_ = obj_.id
|
90
|
-
obj2_ = klass_.where(::Arel.spatial('SRID=3785;POINT(2 3)').st_distance(klass_.arel_table[:latlon]).lt(2)).first
|
91
|
-
refute_nil(obj2_)
|
92
|
-
assert_equal(id_, obj2_.id)
|
93
|
-
obj3_ = klass_.where(::Arel.spatial('SRID=3785;POINT(2 3)').st_distance(klass_.arel_table[:latlon]).gt(2)).first
|
94
|
-
assert_nil(obj3_)
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
def test_query_st_length
|
99
|
-
klass_ = populate_ar_class(:path_linestring)
|
100
|
-
obj_ = klass_.new
|
101
|
-
obj_.path = @factory.line(@factory.point(1.0, 2.0), @factory.point(3.0, 2.0))
|
102
|
-
obj_.save!
|
103
|
-
id_ = obj_.id
|
104
|
-
obj2_ = klass_.where(klass_.arel_table[:path].st_length.eq(2)).first
|
105
|
-
refute_nil(obj2_)
|
106
|
-
assert_equal(id_, obj2_.id)
|
107
|
-
obj3_ = klass_.where(klass_.arel_table[:path].st_length.gt(3)).first
|
108
|
-
assert_nil(obj3_)
|
109
|
-
end
|
110
|
-
|
111
|
-
|
112
|
-
else
|
113
|
-
|
114
|
-
puts "WARNING: The current Arel does not support named functions. Spatial expression tests skipped."
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
data/test/tc_tasks.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'rgeo/active_record/adapter_test_helper'
|
3
|
-
|
4
|
-
module RGeo
|
5
|
-
module ActiveRecord # :nodoc:
|
6
|
-
module PostGISAdapter # :nodoc:
|
7
|
-
module Tests # :nodoc:
|
8
|
-
class TestTasks < ::MiniTest::Test # :nodoc:
|
9
|
-
DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database.yml'
|
10
|
-
OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database_local.yml'
|
11
|
-
|
12
|
-
class << self
|
13
|
-
def before_open_database(args_)
|
14
|
-
@new_database_config = args_[:config].merge('database' => 'postgis_adapter_test2')
|
15
|
-
@new_database_config.stringify_keys!
|
16
|
-
end
|
17
|
-
attr_reader :new_database_config
|
18
|
-
end
|
19
|
-
|
20
|
-
include AdapterTestHelper
|
21
|
-
|
22
|
-
def cleanup_tables
|
23
|
-
::ActiveRecord::Base.remove_connection
|
24
|
-
::ActiveRecord::Base.clear_active_connections!
|
25
|
-
TestTasks::DEFAULT_AR_CLASS.connection.execute("DROP DATABASE IF EXISTS \"postgis_adapter_test2\"")
|
26
|
-
end
|
27
|
-
|
28
|
-
define_test_methods do
|
29
|
-
def test_create_database_from_extension_in_public_schema
|
30
|
-
::ActiveRecord::Tasks::DatabaseTasks.create(TestTasks.new_database_config)
|
31
|
-
::ActiveRecord::Base.connection.select_values("SELECT * from public.spatial_ref_sys")
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_empty_sql_dump
|
35
|
-
filename_ = ::File.expand_path('../tmp/tmp.sql', ::File.dirname(__FILE__))
|
36
|
-
::FileUtils.rm_f(filename_)
|
37
|
-
::FileUtils.mkdir_p(::File.dirname(filename_))
|
38
|
-
::ActiveRecord::Tasks::DatabaseTasks.create(TestTasks.new_database_config.merge('schema_search_path' => 'public,postgis'))
|
39
|
-
::ActiveRecord::Tasks::DatabaseTasks.structure_dump(TestTasks.new_database_config, filename_)
|
40
|
-
sql_ = ::File.read(filename_)
|
41
|
-
assert(sql_ !~ /CREATE/)
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_basic_geography_sql_dump
|
45
|
-
filename_ = ::File.expand_path('../tmp/tmp.sql', ::File.dirname(__FILE__))
|
46
|
-
::FileUtils.rm_f(filename_)
|
47
|
-
::FileUtils.mkdir_p(::File.dirname(filename_))
|
48
|
-
::ActiveRecord::Tasks::DatabaseTasks.create(TestTasks.new_database_config.merge('schema_search_path' => 'public,postgis'))
|
49
|
-
::ActiveRecord::Base.connection.create_table(:spatial_test) do |t_|
|
50
|
-
t_.point "latlon", :geographic => true
|
51
|
-
end
|
52
|
-
::ActiveRecord::Tasks::DatabaseTasks.structure_dump(TestTasks.new_database_config, filename_)
|
53
|
-
data_ = ::File.read(filename_)
|
54
|
-
assert(data_.index('latlon geography(Point,4326)'))
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_empty_schema_dump
|
58
|
-
filename_ = ::File.expand_path('../tmp/tmp.rb', ::File.dirname(__FILE__))
|
59
|
-
::FileUtils.rm_f(filename_)
|
60
|
-
::FileUtils.mkdir_p(::File.dirname(filename_))
|
61
|
-
::ActiveRecord::Tasks::DatabaseTasks.create(TestTasks.new_database_config.merge('schema_search_path' => 'public,postgis'))
|
62
|
-
require 'active_record/schema_dumper'
|
63
|
-
::File.open(filename_, "w:utf-8") do |file_|
|
64
|
-
::ActiveRecord::SchemaDumper.dump(::ActiveRecord::Base.connection, file_)
|
65
|
-
end
|
66
|
-
data_ = ::File.read(filename_)
|
67
|
-
assert(data_.index('ActiveRecord::Schema'))
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_basic_geometry_schema_dump
|
71
|
-
filename_ = ::File.expand_path('../tmp/tmp.rb', ::File.dirname(__FILE__))
|
72
|
-
::FileUtils.rm_f(filename_)
|
73
|
-
::FileUtils.mkdir_p(::File.dirname(filename_))
|
74
|
-
::ActiveRecord::Tasks::DatabaseTasks.create(TestTasks.new_database_config.merge('schema_search_path' => 'public,postgis'))
|
75
|
-
conn_ = ::ActiveRecord::Base.connection
|
76
|
-
conn_.create_table(:spatial_test) do |t_|
|
77
|
-
t_.geometry 'object1'
|
78
|
-
t_.spatial "object2", :limit => {:srid=>conn_.default_srid, :type=>"geometry"}
|
79
|
-
end
|
80
|
-
require 'active_record/schema_dumper'
|
81
|
-
::File.open(filename_, "w:utf-8") do |file_|
|
82
|
-
::ActiveRecord::SchemaDumper.dump(conn_, file_)
|
83
|
-
end
|
84
|
-
data_ = ::File.read(filename_)
|
85
|
-
assert(data_.index("t.spatial \"object1\", limit: {:srid=>#{conn_.default_srid}, :type=>\"geometry\"}"))
|
86
|
-
assert(data_.index("t.spatial \"object2\", limit: {:srid=>#{conn_.default_srid}, :type=>\"geometry\"}"))
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_basic_geography_schema_dump
|
90
|
-
filename_ = ::File.expand_path('../tmp/tmp.rb', ::File.dirname(__FILE__))
|
91
|
-
::FileUtils.rm_f(filename_)
|
92
|
-
::FileUtils.mkdir_p(::File.dirname(filename_))
|
93
|
-
::ActiveRecord::Tasks::DatabaseTasks.create(TestTasks.new_database_config.merge('schema_search_path' => 'public,postgis'))
|
94
|
-
conn_ = ::ActiveRecord::Base.connection
|
95
|
-
conn_.create_table(:spatial_test) do |t_|
|
96
|
-
t_.point "latlon1", :geographic => true
|
97
|
-
t_.spatial "latlon2", :limit => {:srid=>4326, :type=>"point", :geographic=>true}
|
98
|
-
end
|
99
|
-
require 'active_record/schema_dumper'
|
100
|
-
::File.open(filename_, "w:utf-8") do |file_|
|
101
|
-
::ActiveRecord::SchemaDumper.dump(conn_, file_)
|
102
|
-
end
|
103
|
-
data_ = ::File.read(filename_)
|
104
|
-
assert(data_.index('t.spatial "latlon1", limit: {:srid=>4326, :type=>"point", :geographic=>true}'))
|
105
|
-
assert(data_.index('t.spatial "latlon2", limit: {:srid=>4326, :type=>"point", :geographic=>true}'))
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|