achirkunov-spatial_adapter 1.0.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.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +193 -0
- data/VERSION +1 -0
- data/lib/spatial_adapter.rb +37 -0
- data/lib/spatial_adapter/common/raw_geom_info.rb +23 -0
- data/lib/spatial_adapter/common/schema_definitions.rb +11 -0
- data/lib/spatial_adapter/common/schema_dumper.rb +136 -0
- data/lib/spatial_adapter/common/spatial_column.rb +75 -0
- data/lib/spatial_adapter/common/table_definition.rb +14 -0
- data/lib/spatial_adapter/mysql.rb +98 -0
- data/lib/spatial_adapter/postgresql.rb +388 -0
- data/rails/init.rb +16 -0
- data/spec/README.txt +16 -0
- data/spec/db/mysql_raw.rb +70 -0
- data/spec/db/postgis_raw.rb +190 -0
- data/spec/models/common.rb +65 -0
- data/spec/mysql/connection_adapter_spec.rb +106 -0
- data/spec/mysql/migration_spec.rb +64 -0
- data/spec/mysql/models_spec.rb +104 -0
- data/spec/mysql/schema_dumper_spec.rb +56 -0
- data/spec/postgresql/connection_adapter_spec.rb +230 -0
- data/spec/postgresql/migration_spec.rb +351 -0
- data/spec/postgresql/models_spec.rb +258 -0
- data/spec/postgresql/schema_dumper_spec.rb +79 -0
- data/spec/spec_helper.rb +74 -0
- metadata +113 -0
@@ -0,0 +1,351 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'spatial_adapter/postgresql'
|
3
|
+
|
4
|
+
class MigratedGeometryModel < ActiveRecord::Base
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "Spatially-enabled Migrations" do
|
8
|
+
before :each do
|
9
|
+
postgis_connection
|
10
|
+
@connection = ActiveRecord::Base.connection
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "creating tables" do
|
14
|
+
after :each do
|
15
|
+
@connection.drop_table "migrated_geometry_models"
|
16
|
+
end
|
17
|
+
|
18
|
+
SpatialAdapter.geometry_data_types.keys.each do |type|
|
19
|
+
it "should create #{type.to_s} columns" do
|
20
|
+
ActiveRecord::Schema.define do
|
21
|
+
create_table :migrated_geometry_models, :force => true do |t|
|
22
|
+
t.integer :extra
|
23
|
+
t.send(type, :geom)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
28
|
+
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
29
|
+
geom_column.type.should == :string
|
30
|
+
geom_column.geometry_type.should == type
|
31
|
+
geom_column.should_not be_geographic
|
32
|
+
geom_column.with_z.should == false
|
33
|
+
geom_column.with_m.should == false
|
34
|
+
geom_column.srid.should == -1
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should create #{type.to_s} geographic columns" do
|
38
|
+
ActiveRecord::Schema.define do
|
39
|
+
create_table :migrated_geometry_models, :force => true do |t|
|
40
|
+
t.integer :extra
|
41
|
+
t.column :geom, type, :geographic => true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
46
|
+
|
47
|
+
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
48
|
+
geom_column.type.should == :string
|
49
|
+
geom_column.geometry_type.should == type
|
50
|
+
geom_column.should be_geographic
|
51
|
+
geom_column.with_z.should == false
|
52
|
+
geom_column.with_m.should == false
|
53
|
+
#geom_column.srid.should == 4326 # SRID is currently irrelevant for geography columns
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
it "should create 3d (xyz) geometry columns" do
|
59
|
+
ActiveRecord::Schema.define do
|
60
|
+
create_table :migrated_geometry_models, :force => true do |t|
|
61
|
+
t.integer :extra
|
62
|
+
t.point :geom, :with_z => true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
67
|
+
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
68
|
+
geom_column.with_z.should == true
|
69
|
+
geom_column.with_m.should == false
|
70
|
+
geom_column.srid.should == -1
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
it "should create 3d (xym) geometry columns" do
|
75
|
+
ActiveRecord::Schema.define do
|
76
|
+
create_table :migrated_geometry_models, :force => true do |t|
|
77
|
+
t.integer :extra
|
78
|
+
t.point :geom, :with_m => true
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
83
|
+
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
84
|
+
geom_column.geometry_type.should == :point
|
85
|
+
geom_column.type.should == :string
|
86
|
+
geom_column.with_z.should == false
|
87
|
+
geom_column.with_m.should == true
|
88
|
+
geom_column.srid.should == -1
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
it "should create 4d (xyzm) geometry columns" do
|
93
|
+
ActiveRecord::Schema.define do
|
94
|
+
create_table :migrated_geometry_models, :force => true do |t|
|
95
|
+
t.integer :extra
|
96
|
+
t.point :geom, :with_z => true, :with_m => true
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
101
|
+
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
102
|
+
geom_column.geometry_type.should == :point
|
103
|
+
geom_column.type.should == :string
|
104
|
+
geom_column.with_z.should == true
|
105
|
+
geom_column.with_m.should == true
|
106
|
+
geom_column.srid.should == -1
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should create 3d (xyz) geographic columns" do
|
110
|
+
ActiveRecord::Schema.define do
|
111
|
+
create_table :migrated_geometry_models, :force => true do |t|
|
112
|
+
t.integer :extra
|
113
|
+
t.point :geom, :with_z => true, :geographic => true
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
118
|
+
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
119
|
+
geom_column.should be_geographic
|
120
|
+
geom_column.with_z.should == true
|
121
|
+
geom_column.with_m.should == false
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
it "should create 3d (xym) geographic columns" do
|
126
|
+
ActiveRecord::Schema.define do
|
127
|
+
create_table :migrated_geometry_models, :force => true do |t|
|
128
|
+
t.integer :extra
|
129
|
+
t.point :geom, :with_m => true, :geographic => true
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
134
|
+
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
135
|
+
geom_column.geometry_type.should == :point
|
136
|
+
geom_column.type.should == :string
|
137
|
+
geom_column.should be_geographic
|
138
|
+
geom_column.with_z.should == false
|
139
|
+
geom_column.with_m.should == true
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
it "should create 4d (xyzm) geographic columns" do
|
144
|
+
ActiveRecord::Schema.define do
|
145
|
+
create_table :migrated_geometry_models, :force => true do |t|
|
146
|
+
t.integer :extra
|
147
|
+
t.point :geom, :with_z => true, :with_m => true, :geographic => true
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
152
|
+
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
153
|
+
geom_column.geometry_type.should == :point
|
154
|
+
geom_column.should be_geographic
|
155
|
+
geom_column.type.should == :string
|
156
|
+
geom_column.with_z.should == true
|
157
|
+
geom_column.with_m.should == true
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
it "should create geometry columns with specified SRID" do
|
162
|
+
ActiveRecord::Schema.define do
|
163
|
+
create_table :migrated_geometry_models, :force => true do |t|
|
164
|
+
t.integer :extra
|
165
|
+
t.geometry :geom, :srid => 4326
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
170
|
+
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
171
|
+
geom_column.type.should == :string
|
172
|
+
geom_column.geometry_type.should == :geometry
|
173
|
+
geom_column.with_z.should == false
|
174
|
+
geom_column.with_m.should == false
|
175
|
+
geom_column.srid.should == 4326
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "adding columns" do
|
180
|
+
before :each do
|
181
|
+
ActiveRecord::Schema.define do
|
182
|
+
create_table :migrated_geometry_models, :force => true do |t|
|
183
|
+
t.integer :extra
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
after :each do
|
189
|
+
@connection.drop_table "migrated_geometry_models"
|
190
|
+
end
|
191
|
+
|
192
|
+
SpatialAdapter.geometry_data_types.keys.each do |type|
|
193
|
+
it "should add #{type.to_s} columns" do
|
194
|
+
ActiveRecord::Schema.define do
|
195
|
+
add_column :migrated_geometry_models, :geom, type
|
196
|
+
end
|
197
|
+
|
198
|
+
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
199
|
+
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
200
|
+
geom_column.type.should == :string
|
201
|
+
geom_column.geometry_type.should == type
|
202
|
+
geom_column.with_z.should == false
|
203
|
+
geom_column.with_m.should == false
|
204
|
+
geom_column.srid.should == -1
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should add 3d (xyz) geometry columns" do
|
209
|
+
ActiveRecord::Schema.define do
|
210
|
+
add_column :migrated_geometry_models, :geom, :point, :with_z => true
|
211
|
+
end
|
212
|
+
|
213
|
+
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
214
|
+
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
215
|
+
geom_column.type.should == :string
|
216
|
+
geom_column.geometry_type.should == :point
|
217
|
+
geom_column.with_z.should == true
|
218
|
+
geom_column.with_m.should == false
|
219
|
+
geom_column.srid.should == -1
|
220
|
+
end
|
221
|
+
|
222
|
+
|
223
|
+
it "should add 3d (xym) geometry columns" do
|
224
|
+
ActiveRecord::Schema.define do
|
225
|
+
add_column :migrated_geometry_models, :geom, :point, :with_m => true
|
226
|
+
end
|
227
|
+
|
228
|
+
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
229
|
+
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
230
|
+
geom_column.type.should == :string
|
231
|
+
geom_column.geometry_type.should == :point
|
232
|
+
geom_column.with_z.should == false
|
233
|
+
geom_column.with_m.should == true
|
234
|
+
geom_column.srid.should == -1
|
235
|
+
end
|
236
|
+
|
237
|
+
|
238
|
+
it "should add 4d (xyzm) geometry columns" do
|
239
|
+
ActiveRecord::Schema.define do
|
240
|
+
add_column :migrated_geometry_models, :geom, :point, :with_z => true, :with_m => true
|
241
|
+
end
|
242
|
+
|
243
|
+
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
244
|
+
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
245
|
+
geom_column.type.should == :string
|
246
|
+
geom_column.geometry_type.should == :point
|
247
|
+
geom_column.with_z.should == true
|
248
|
+
geom_column.with_m.should == true
|
249
|
+
geom_column.srid.should == -1
|
250
|
+
end
|
251
|
+
|
252
|
+
it "should add 3d (xyz) geography columns" do
|
253
|
+
ActiveRecord::Schema.define do
|
254
|
+
add_column :migrated_geometry_models, :geom, :point, :with_z => true, :geographic => true
|
255
|
+
end
|
256
|
+
|
257
|
+
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
258
|
+
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
259
|
+
geom_column.type.should == :string
|
260
|
+
geom_column.should be_geographic
|
261
|
+
geom_column.geometry_type.should == :point
|
262
|
+
geom_column.with_z.should == true
|
263
|
+
geom_column.with_m.should == false
|
264
|
+
end
|
265
|
+
|
266
|
+
|
267
|
+
it "should add 3d (xym) geography columns" do
|
268
|
+
ActiveRecord::Schema.define do
|
269
|
+
add_column :migrated_geometry_models, :geom, :point, :with_m => true, :geographic => true
|
270
|
+
end
|
271
|
+
|
272
|
+
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
273
|
+
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
274
|
+
geom_column.type.should == :string
|
275
|
+
geom_column.should be_geographic
|
276
|
+
geom_column.geometry_type.should == :point
|
277
|
+
geom_column.with_z.should == false
|
278
|
+
geom_column.with_m.should == true
|
279
|
+
end
|
280
|
+
|
281
|
+
|
282
|
+
it "should add 4d (xyzm) geography columns" do
|
283
|
+
ActiveRecord::Schema.define do
|
284
|
+
add_column :migrated_geometry_models, :geom, :point, :with_z => true, :with_m => true, :geographic => true
|
285
|
+
end
|
286
|
+
|
287
|
+
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
288
|
+
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
289
|
+
geom_column.type.should == :string
|
290
|
+
geom_column.should be_geographic
|
291
|
+
geom_column.geometry_type.should == :point
|
292
|
+
geom_column.with_z.should == true
|
293
|
+
geom_column.with_m.should == true
|
294
|
+
end
|
295
|
+
|
296
|
+
it "should add GEOMETRY columns with specified SRID" do
|
297
|
+
ActiveRecord::Schema.define do
|
298
|
+
add_column :migrated_geometry_models, :geom, :geometry, :srid => 4326
|
299
|
+
end
|
300
|
+
|
301
|
+
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
302
|
+
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
303
|
+
geom_column.geometry_type.should == :geometry
|
304
|
+
geom_column.type.should == :string
|
305
|
+
geom_column.with_z.should == false
|
306
|
+
geom_column.with_m.should == false
|
307
|
+
geom_column.srid.should == 4326
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
describe "removing columns" do
|
312
|
+
after :each do
|
313
|
+
@connection.drop_table "migrated_geometry_models"
|
314
|
+
end
|
315
|
+
|
316
|
+
SpatialAdapter.geometry_data_types.keys.each do |type|
|
317
|
+
it "should remove #{type.to_s} columns using DropGeometryColumn" do
|
318
|
+
ActiveRecord::Schema.define do
|
319
|
+
create_table :migrated_geometry_models, :force => true do |t|
|
320
|
+
t.integer :extra
|
321
|
+
t.send(type, :geom)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
@connection.should_receive(:execute).with(/DropGeometryColumn(.*migrated_geometry_models.*geom)/)
|
326
|
+
ActiveRecord::Schema.define do
|
327
|
+
remove_column :migrated_geometry_models, :geom
|
328
|
+
end
|
329
|
+
@connection.should_receive(:execute).with(anything())
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
|
334
|
+
SpatialAdapter.geometry_data_types.keys.each do |type|
|
335
|
+
it "should remove #{type.to_s} geography columns using ALTER TABLE DROP COLUMN" do
|
336
|
+
ActiveRecord::Schema.define do
|
337
|
+
create_table :migrated_geometry_models, :force => true do |t|
|
338
|
+
t.integer :extra
|
339
|
+
t.send(type, :geom, :geographic => true)
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
@connection.should_receive(:execute).with(/alter table.*migrated_geometry_models.*drop.*geom/i)
|
344
|
+
ActiveRecord::Schema.define do
|
345
|
+
remove_column :migrated_geometry_models, :geom
|
346
|
+
end
|
347
|
+
@connection.should_receive(:execute).with(anything())
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|
@@ -0,0 +1,258 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'spatial_adapter/postgresql'
|
3
|
+
require 'db/postgis_raw'
|
4
|
+
require 'models/common'
|
5
|
+
|
6
|
+
describe "Spatially-enabled Models" do
|
7
|
+
before :each do
|
8
|
+
postgis_connection
|
9
|
+
@connection = ActiveRecord::Base.connection
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "inserting records" do
|
13
|
+
it 'should save Point objects' do
|
14
|
+
model = PointModel.new(:extra => 'test', :geom => GeometryFactory.point)
|
15
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point.as_hex_ewkb))
|
16
|
+
model.save.should == true
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should save LineString objects' do
|
20
|
+
model = LineStringModel.new(:extra => 'test', :geom => GeometryFactory.line_string)
|
21
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.line_string.as_hex_ewkb))
|
22
|
+
model.save.should == true
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should save Polygon objects' do
|
26
|
+
model = PolygonModel.new(:extra => 'test', :geom => GeometryFactory.polygon)
|
27
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.polygon.as_hex_ewkb))
|
28
|
+
model.save.should == true
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should save MultiPoint objects' do
|
32
|
+
model = MultiPointModel.new(:extra => 'test', :geom => GeometryFactory.multi_point)
|
33
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_point.as_hex_ewkb))
|
34
|
+
model.save.should == true
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should save MultiLineString objects' do
|
38
|
+
model = MultiLineStringModel.new(:extra => 'test', :geom => GeometryFactory.multi_line_string)
|
39
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_line_string.as_hex_ewkb))
|
40
|
+
model.save.should == true
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should save MultiPolygon objects' do
|
44
|
+
model = MultiPolygonModel.new(:extra => 'test', :geom => GeometryFactory.multi_polygon)
|
45
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_polygon.as_hex_ewkb))
|
46
|
+
model.save.should == true
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should save GeometryCollection objects' do
|
50
|
+
model = GeometryCollectionModel.new(:extra => 'test', :geom => GeometryFactory.geometry_collection)
|
51
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.geometry_collection.as_hex_ewkb))
|
52
|
+
model.save.should == true
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should save Geometry objects' do
|
56
|
+
model = GeometryModel.new(:extra => 'test', :geom => GeometryFactory.point)
|
57
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point.as_hex_ewkb))
|
58
|
+
model.save.should == true
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should save 3D Point (with Z coord) objects' do
|
62
|
+
model = PointzModel.new(:extra => 'test', :geom => GeometryFactory.pointz)
|
63
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.pointz.as_hex_ewkb))
|
64
|
+
model.save.should == true
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should save 3D Point (with M coord) objects' do
|
68
|
+
model = PointmModel.new(:extra => 'test', :geom => GeometryFactory.pointm)
|
69
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.pointm.as_hex_ewkb))
|
70
|
+
model.save.should == true
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should save 4D Point objects' do
|
74
|
+
model = Point4Model.new(:extra => 'test', :geom => GeometryFactory.point4)
|
75
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point4.as_hex_ewkb))
|
76
|
+
model.save.should == true
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should save Point geography objects' do
|
80
|
+
model = GeographyPointModel.new(:extra => 'test', :geom => GeometryFactory.point)
|
81
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point.as_hex_ewkb))
|
82
|
+
model.save.should == true
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should save LineString geography objects' do
|
86
|
+
model = GeographyLineStringModel.new(:extra => 'test', :geom => GeometryFactory.line_string)
|
87
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.line_string.as_hex_ewkb))
|
88
|
+
model.save.should == true
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should save Polygon geography objects' do
|
92
|
+
model = GeographyPolygonModel.new(:extra => 'test', :geom => GeometryFactory.polygon)
|
93
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.polygon.as_hex_ewkb))
|
94
|
+
model.save.should == true
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should save MultiPoint geography objects' do
|
98
|
+
model = GeographyMultiPointModel.new(:extra => 'test', :geom => GeometryFactory.multi_point)
|
99
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_point.as_hex_ewkb))
|
100
|
+
model.save.should == true
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should save MultiLineString geography objects' do
|
104
|
+
model = GeographyMultiLineStringModel.new(:extra => 'test', :geom => GeometryFactory.multi_line_string)
|
105
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_line_string.as_hex_ewkb))
|
106
|
+
model.save.should == true
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should save MultiPolygon geography objects' do
|
110
|
+
model = GeographyMultiPolygonModel.new(:extra => 'test', :geom => GeometryFactory.multi_polygon)
|
111
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_polygon.as_hex_ewkb))
|
112
|
+
model.save.should == true
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should save GeometryCollection geography objects' do
|
116
|
+
model = GeographyGeometryCollectionModel.new(:extra => 'test', :geom => GeometryFactory.geometry_collection)
|
117
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.geometry_collection.as_hex_ewkb))
|
118
|
+
model.save.should == true
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should save Geography objects' do
|
122
|
+
model = GeographyModel.new(:extra => 'test', :geom => GeometryFactory.point)
|
123
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point.as_hex_ewkb))
|
124
|
+
model.save.should == true
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should save 3D Point (with Z coord) geography objects' do
|
128
|
+
model = GeographyPointzModel.new(:extra => 'test', :geom => GeometryFactory.pointz)
|
129
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.pointz.as_hex_ewkb))
|
130
|
+
model.save.should == true
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'should save 3D Point (with M coord) geography objects' do
|
134
|
+
model = GeographyPointmModel.new(:extra => 'test', :geom => GeometryFactory.pointm)
|
135
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.pointm.as_hex_ewkb))
|
136
|
+
model.save.should == true
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should save 4D Point geography objects' do
|
140
|
+
model = GeographyPoint4Model.new(:extra => 'test', :geom => GeometryFactory.point4)
|
141
|
+
@connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point4.as_hex_ewkb))
|
142
|
+
model.save.should == true
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "finding records" do
|
147
|
+
it 'should retrieve Point objects' do
|
148
|
+
model = PointModel.create(:extra => 'test', :geom => GeometryFactory.point)
|
149
|
+
PointModel.find(model.id).geom.should == GeometryFactory.point
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'should retrieve LineString objects' do
|
153
|
+
model = LineStringModel.create(:extra => 'test', :geom => GeometryFactory.line_string)
|
154
|
+
LineStringModel.find(model.id).geom.should == GeometryFactory.line_string
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should retrieve Polygon objects' do
|
158
|
+
model = PolygonModel.create(:extra => 'test', :geom => GeometryFactory.polygon)
|
159
|
+
PolygonModel.find(model.id).geom.should == GeometryFactory.polygon
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'should retrieve MultiPoint objects' do
|
163
|
+
model = MultiPointModel.create(:extra => 'test', :geom => GeometryFactory.multi_point)
|
164
|
+
MultiPointModel.find(model.id).geom.should == GeometryFactory.multi_point
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'should retrieve MultiLineString objects' do
|
168
|
+
model = MultiLineStringModel.create(:extra => 'test', :geom => GeometryFactory.multi_line_string)
|
169
|
+
MultiLineStringModel.find(model.id).geom.should == GeometryFactory.multi_line_string
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should retrieve MultiPolygon objects' do
|
173
|
+
model = MultiPolygonModel.create(:extra => 'test', :geom => GeometryFactory.multi_polygon)
|
174
|
+
MultiPolygonModel.find(model.id).geom.should == GeometryFactory.multi_polygon
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'should retrieve GeometryCollection objects' do
|
178
|
+
model = GeometryCollectionModel.create(:extra => 'test', :geom => GeometryFactory.geometry_collection)
|
179
|
+
GeometryCollectionModel.find(model.id).geom.should == GeometryFactory.geometry_collection
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'should retrieve Geometry objects' do
|
183
|
+
model = GeometryModel.create(:extra => 'test', :geom => GeometryFactory.point)
|
184
|
+
GeometryModel.find(model.id).geom.should == GeometryFactory.point
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'should retrieve 3D Point (with Z coord) objects' do
|
188
|
+
model = PointzModel.create(:extra => 'test', :geom => GeometryFactory.pointz)
|
189
|
+
PointzModel.find(model.id).geom.should == GeometryFactory.pointz
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'should retrieve 3D Point (with M coord) objects' do
|
193
|
+
model = GeographyPointmModel.create(:extra => 'test', :geom => GeometryFactory.pointm)
|
194
|
+
GeographyPointmModel.find(model.id).geom.should == GeometryFactory.pointm
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should retrieve 4D Point objects' do
|
198
|
+
model = GeographyPoint4Model.create(:extra => 'test', :geom => GeometryFactory.point4)
|
199
|
+
GeographyPoint4Model.find(model.id).geom.should == GeometryFactory.point4
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'should retrieve Point geography objects' do
|
203
|
+
model = GeographyPointModel.create(:extra => 'test', :geom => GeometryFactory.point)
|
204
|
+
GeographyPointModel.find(model.id).geom.should == GeometryFactory.point
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'should retrieve LineString geography objects' do
|
208
|
+
model = GeographyLineStringModel.create(:extra => 'test', :geom => GeometryFactory.line_string)
|
209
|
+
GeographyLineStringModel.find(model.id).geom.should == GeometryFactory.line_string
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'should retrieve Polygon geography objects' do
|
213
|
+
model = GeographyPolygonModel.create(:extra => 'test', :geom => GeometryFactory.polygon)
|
214
|
+
GeographyPolygonModel.find(model.id).geom.should == GeometryFactory.polygon
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'should retrieve MultiPoint geography objects' do
|
218
|
+
model = GeographyMultiPointModel.create(:extra => 'test', :geom => GeometryFactory.multi_point)
|
219
|
+
GeographyMultiPointModel.find(model.id).geom.should == GeometryFactory.multi_point
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'should retrieve MultiLineString geography objects' do
|
223
|
+
model = GeographyMultiLineStringModel.create(:extra => 'test', :geom => GeometryFactory.multi_line_string)
|
224
|
+
GeographyMultiLineStringModel.find(model.id).geom.should == GeometryFactory.multi_line_string
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'should retrieve MultiPolygon geography objects' do
|
228
|
+
model = GeographyMultiPolygonModel.create(:extra => 'test', :geom => GeometryFactory.multi_polygon)
|
229
|
+
GeographyMultiPolygonModel.find(model.id).geom.should == GeometryFactory.multi_polygon
|
230
|
+
end
|
231
|
+
|
232
|
+
it 'should retrieve GeometryCollection geography objects' do
|
233
|
+
model = GeographyGeometryCollectionModel.create(:extra => 'test', :geom => GeometryFactory.geometry_collection)
|
234
|
+
GeographyGeometryCollectionModel.find(model.id).geom.should == GeometryFactory.geometry_collection
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'should retrieve Geometry geography objects' do
|
238
|
+
model = GeographyModel.create(:extra => 'test', :geom => GeometryFactory.point)
|
239
|
+
GeographyModel.find(model.id).geom.should == GeometryFactory.point
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'should retrieve 3D Point (with Z coord) geography objects' do
|
243
|
+
model = GeographyPointzModel.create(:extra => 'test', :geom => GeometryFactory.pointz)
|
244
|
+
GeographyPointzModel.find(model.id).geom.should == GeometryFactory.pointz
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'should retrieve 3D Point (with M coord) geography objects' do
|
248
|
+
model = GeographyPointmModel.create(:extra => 'test', :geom => GeometryFactory.pointm)
|
249
|
+
GeographyPointmModel.find(model.id).geom.should == GeometryFactory.pointm
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'should retrieve 4D Point geography objects' do
|
253
|
+
model = GeographyPoint4Model.create(:extra => 'test', :geom => GeometryFactory.point4)
|
254
|
+
GeographyPoint4Model.find(model.id).geom.should == GeometryFactory.point4
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|