spatial_adapter 1.2.0 → 1.3.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.
Files changed (45) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +3 -0
  3. data/README.rdoc +30 -17
  4. data/Rakefile +11 -0
  5. data/init.rb +1 -0
  6. data/lib/spatial_adapter/base/mysql/adapter.rb +54 -0
  7. data/lib/spatial_adapter/base/mysql/spatial_column.rb +12 -0
  8. data/lib/spatial_adapter/base/mysql.rb +9 -0
  9. data/lib/spatial_adapter/common/schema_dumper.rb +12 -12
  10. data/lib/spatial_adapter/common/spatial_column.rb +4 -4
  11. data/lib/spatial_adapter/common/table_definition.rb +8 -10
  12. data/lib/spatial_adapter/common.rb +10 -0
  13. data/lib/spatial_adapter/jdbcmysql.rb +50 -0
  14. data/lib/spatial_adapter/mysql.rb +43 -85
  15. data/lib/spatial_adapter/mysql2.rb +39 -86
  16. data/lib/spatial_adapter/postgresql.rb +315 -324
  17. data/lib/spatial_adapter/version.rb +3 -0
  18. data/lib/spatial_adapter.rb +3 -7
  19. data/spatial_adapter.gemspec +39 -0
  20. data/spec/db/jdbcmysql_raw.rb +70 -0
  21. data/spec/db/mysql2_raw.rb +9 -9
  22. data/spec/db/mysql_raw.rb +9 -9
  23. data/spec/jdbcmysql_spec.rb +25 -0
  24. data/spec/mysql2_spec.rb +31 -0
  25. data/spec/mysql_spec.rb +17 -0
  26. data/spec/postgresql/connection_adapter_spec.rb +34 -39
  27. data/spec/postgresql/migration_spec.rb +51 -51
  28. data/spec/postgresql/models_spec.rb +37 -37
  29. data/spec/postgresql/schema_dumper_spec.rb +12 -12
  30. data/spec/postgresql_spec.rb +5 -0
  31. data/spec/{shared_examples.rb → shared/common_model_actions_spec.rb} +2 -2
  32. data/spec/shared/mysql_connection_adapter_spec.rb +110 -0
  33. data/spec/{mysql/migration_spec.rb → shared/mysql_migration_spec.rb} +17 -17
  34. data/spec/shared/mysql_models_spec.rb +58 -0
  35. data/spec/{mysql/schema_dumper_spec.rb → shared/mysql_schema_dumper_spec.rb} +24 -27
  36. data/spec/spec_helper.rb +25 -21
  37. metadata +131 -84
  38. data/VERSION +0 -1
  39. data/spec/README.txt +0 -22
  40. data/spec/mysql/connection_adapter_spec.rb +0 -106
  41. data/spec/mysql/models_spec.rb +0 -65
  42. data/spec/mysql2/connection_adapter_spec.rb +0 -106
  43. data/spec/mysql2/migration_spec.rb +0 -64
  44. data/spec/mysql2/models_spec.rb +0 -65
  45. data/spec/mysql2/schema_dumper_spec.rb +0 -56
@@ -9,12 +9,12 @@ describe "Spatially-enabled Migrations" do
9
9
  postgis_connection
10
10
  @connection = ActiveRecord::Base.connection
11
11
  end
12
-
12
+
13
13
  describe "creating tables" do
14
14
  after :each do
15
15
  @connection.drop_table "migrated_geometry_models"
16
16
  end
17
-
17
+
18
18
  SpatialAdapter.geometry_data_types.keys.each do |type|
19
19
  it "should create #{type.to_s} columns" do
20
20
  ActiveRecord::Schema.define do
@@ -23,7 +23,7 @@ describe "Spatially-enabled Migrations" do
23
23
  t.send(type, :geom)
24
24
  end
25
25
  end
26
-
26
+
27
27
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
28
28
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
29
29
  geom_column.type.should == :string
@@ -33,7 +33,7 @@ describe "Spatially-enabled Migrations" do
33
33
  geom_column.with_m.should == false
34
34
  geom_column.srid.should == -1
35
35
  end
36
-
36
+
37
37
  it "should create #{type.to_s} geographic columns" do
38
38
  ActiveRecord::Schema.define do
39
39
  create_table :migrated_geometry_models, :force => true do |t|
@@ -41,9 +41,9 @@ describe "Spatially-enabled Migrations" do
41
41
  t.column :geom, type, :geographic => true
42
42
  end
43
43
  end
44
-
44
+
45
45
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
46
-
46
+
47
47
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
48
48
  geom_column.type.should == :string
49
49
  geom_column.geometry_type.should == type
@@ -53,8 +53,8 @@ describe "Spatially-enabled Migrations" do
53
53
  #geom_column.srid.should == 4326 # SRID is currently irrelevant for geography columns
54
54
  end
55
55
  end
56
-
57
-
56
+
57
+
58
58
  it "should create 3d (xyz) geometry columns" do
59
59
  ActiveRecord::Schema.define do
60
60
  create_table :migrated_geometry_models, :force => true do |t|
@@ -62,15 +62,15 @@ describe "Spatially-enabled Migrations" do
62
62
  t.point :geom, :with_z => true
63
63
  end
64
64
  end
65
-
65
+
66
66
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
67
67
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
68
68
  geom_column.with_z.should == true
69
69
  geom_column.with_m.should == false
70
70
  geom_column.srid.should == -1
71
71
  end
72
-
73
-
72
+
73
+
74
74
  it "should create 3d (xym) geometry columns" do
75
75
  ActiveRecord::Schema.define do
76
76
  create_table :migrated_geometry_models, :force => true do |t|
@@ -78,7 +78,7 @@ describe "Spatially-enabled Migrations" do
78
78
  t.point :geom, :with_m => true
79
79
  end
80
80
  end
81
-
81
+
82
82
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
83
83
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
84
84
  geom_column.geometry_type.should == :point
@@ -87,8 +87,8 @@ describe "Spatially-enabled Migrations" do
87
87
  geom_column.with_m.should == true
88
88
  geom_column.srid.should == -1
89
89
  end
90
-
91
-
90
+
91
+
92
92
  it "should create 4d (xyzm) geometry columns" do
93
93
  ActiveRecord::Schema.define do
94
94
  create_table :migrated_geometry_models, :force => true do |t|
@@ -96,7 +96,7 @@ describe "Spatially-enabled Migrations" do
96
96
  t.point :geom, :with_z => true, :with_m => true
97
97
  end
98
98
  end
99
-
99
+
100
100
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
101
101
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
102
102
  geom_column.geometry_type.should == :point
@@ -105,7 +105,7 @@ describe "Spatially-enabled Migrations" do
105
105
  geom_column.with_m.should == true
106
106
  geom_column.srid.should == -1
107
107
  end
108
-
108
+
109
109
  it "should create 3d (xyz) geographic columns" do
110
110
  ActiveRecord::Schema.define do
111
111
  create_table :migrated_geometry_models, :force => true do |t|
@@ -113,15 +113,15 @@ describe "Spatially-enabled Migrations" do
113
113
  t.point :geom, :with_z => true, :geographic => true
114
114
  end
115
115
  end
116
-
116
+
117
117
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
118
118
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
119
119
  geom_column.should be_geographic
120
120
  geom_column.with_z.should == true
121
121
  geom_column.with_m.should == false
122
122
  end
123
-
124
-
123
+
124
+
125
125
  it "should create 3d (xym) geographic columns" do
126
126
  ActiveRecord::Schema.define do
127
127
  create_table :migrated_geometry_models, :force => true do |t|
@@ -129,7 +129,7 @@ describe "Spatially-enabled Migrations" do
129
129
  t.point :geom, :with_m => true, :geographic => true
130
130
  end
131
131
  end
132
-
132
+
133
133
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
134
134
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
135
135
  geom_column.geometry_type.should == :point
@@ -138,8 +138,8 @@ describe "Spatially-enabled Migrations" do
138
138
  geom_column.with_z.should == false
139
139
  geom_column.with_m.should == true
140
140
  end
141
-
142
-
141
+
142
+
143
143
  it "should create 4d (xyzm) geographic columns" do
144
144
  ActiveRecord::Schema.define do
145
145
  create_table :migrated_geometry_models, :force => true do |t|
@@ -147,7 +147,7 @@ describe "Spatially-enabled Migrations" do
147
147
  t.point :geom, :with_z => true, :with_m => true, :geographic => true
148
148
  end
149
149
  end
150
-
150
+
151
151
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
152
152
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
153
153
  geom_column.geometry_type.should == :point
@@ -156,8 +156,8 @@ describe "Spatially-enabled Migrations" do
156
156
  geom_column.with_z.should == true
157
157
  geom_column.with_m.should == true
158
158
  end
159
-
160
-
159
+
160
+
161
161
  it "should create geometry columns with specified SRID" do
162
162
  ActiveRecord::Schema.define do
163
163
  create_table :migrated_geometry_models, :force => true do |t|
@@ -165,7 +165,7 @@ describe "Spatially-enabled Migrations" do
165
165
  t.geometry :geom, :srid => 4326
166
166
  end
167
167
  end
168
-
168
+
169
169
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
170
170
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
171
171
  geom_column.type.should == :string
@@ -184,17 +184,17 @@ describe "Spatially-enabled Migrations" do
184
184
  end
185
185
  end
186
186
  end
187
-
187
+
188
188
  after :each do
189
189
  @connection.drop_table "migrated_geometry_models"
190
190
  end
191
-
191
+
192
192
  SpatialAdapter.geometry_data_types.keys.each do |type|
193
193
  it "should add #{type.to_s} columns" do
194
194
  ActiveRecord::Schema.define do
195
195
  add_column :migrated_geometry_models, :geom, type
196
196
  end
197
-
197
+
198
198
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
199
199
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
200
200
  geom_column.type.should == :string
@@ -204,12 +204,12 @@ describe "Spatially-enabled Migrations" do
204
204
  geom_column.srid.should == -1
205
205
  end
206
206
  end
207
-
207
+
208
208
  it "should add 3d (xyz) geometry columns" do
209
209
  ActiveRecord::Schema.define do
210
210
  add_column :migrated_geometry_models, :geom, :point, :with_z => true
211
211
  end
212
-
212
+
213
213
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
214
214
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
215
215
  geom_column.type.should == :string
@@ -218,13 +218,13 @@ describe "Spatially-enabled Migrations" do
218
218
  geom_column.with_m.should == false
219
219
  geom_column.srid.should == -1
220
220
  end
221
-
222
-
221
+
222
+
223
223
  it "should add 3d (xym) geometry columns" do
224
224
  ActiveRecord::Schema.define do
225
225
  add_column :migrated_geometry_models, :geom, :point, :with_m => true
226
226
  end
227
-
227
+
228
228
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
229
229
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
230
230
  geom_column.type.should == :string
@@ -233,13 +233,13 @@ describe "Spatially-enabled Migrations" do
233
233
  geom_column.with_m.should == true
234
234
  geom_column.srid.should == -1
235
235
  end
236
-
237
-
236
+
237
+
238
238
  it "should add 4d (xyzm) geometry columns" do
239
239
  ActiveRecord::Schema.define do
240
240
  add_column :migrated_geometry_models, :geom, :point, :with_z => true, :with_m => true
241
241
  end
242
-
242
+
243
243
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
244
244
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
245
245
  geom_column.type.should == :string
@@ -248,12 +248,12 @@ describe "Spatially-enabled Migrations" do
248
248
  geom_column.with_m.should == true
249
249
  geom_column.srid.should == -1
250
250
  end
251
-
251
+
252
252
  it "should add 3d (xyz) geography columns" do
253
253
  ActiveRecord::Schema.define do
254
254
  add_column :migrated_geometry_models, :geom, :point, :with_z => true, :geographic => true
255
255
  end
256
-
256
+
257
257
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
258
258
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
259
259
  geom_column.type.should == :string
@@ -262,13 +262,13 @@ describe "Spatially-enabled Migrations" do
262
262
  geom_column.with_z.should == true
263
263
  geom_column.with_m.should == false
264
264
  end
265
-
266
-
265
+
266
+
267
267
  it "should add 3d (xym) geography columns" do
268
268
  ActiveRecord::Schema.define do
269
269
  add_column :migrated_geometry_models, :geom, :point, :with_m => true, :geographic => true
270
270
  end
271
-
271
+
272
272
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
273
273
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
274
274
  geom_column.type.should == :string
@@ -277,13 +277,13 @@ describe "Spatially-enabled Migrations" do
277
277
  geom_column.with_z.should == false
278
278
  geom_column.with_m.should == true
279
279
  end
280
-
281
-
280
+
281
+
282
282
  it "should add 4d (xyzm) geography columns" do
283
283
  ActiveRecord::Schema.define do
284
284
  add_column :migrated_geometry_models, :geom, :point, :with_z => true, :with_m => true, :geographic => true
285
285
  end
286
-
286
+
287
287
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
288
288
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
289
289
  geom_column.type.should == :string
@@ -297,7 +297,7 @@ describe "Spatially-enabled Migrations" do
297
297
  ActiveRecord::Schema.define do
298
298
  add_column :migrated_geometry_models, :geom, :geometry, :srid => 4326
299
299
  end
300
-
300
+
301
301
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
302
302
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
303
303
  geom_column.geometry_type.should == :geometry
@@ -307,12 +307,12 @@ describe "Spatially-enabled Migrations" do
307
307
  geom_column.srid.should == 4326
308
308
  end
309
309
  end
310
-
310
+
311
311
  describe "removing columns" do
312
312
  after :each do
313
313
  @connection.drop_table "migrated_geometry_models"
314
314
  end
315
-
315
+
316
316
  SpatialAdapter.geometry_data_types.keys.each do |type|
317
317
  it "should remove #{type.to_s} columns using DropGeometryColumn" do
318
318
  ActiveRecord::Schema.define do
@@ -321,7 +321,7 @@ describe "Spatially-enabled Migrations" do
321
321
  t.send(type, :geom)
322
322
  end
323
323
  end
324
-
324
+
325
325
  @connection.should_receive(:execute).with(/DropGeometryColumn(.*migrated_geometry_models.*geom)/)
326
326
  ActiveRecord::Schema.define do
327
327
  remove_column :migrated_geometry_models, :geom
@@ -346,7 +346,7 @@ describe "Spatially-enabled Migrations" do
346
346
  @connection.should_receive(:execute).with(anything())
347
347
  end
348
348
  end
349
-
349
+
350
350
  it "should still remove non-spatial columns using ALTER TABLE DROP COLUMN" do
351
351
  ActiveRecord::Schema.define do
352
352
  create_table :migrated_geometry_models, :force => true do |t|
@@ -362,4 +362,4 @@ describe "Spatially-enabled Migrations" do
362
362
  @connection.should_receive(:execute).with(anything())
363
363
  end
364
364
  end
365
- end
365
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'shared_examples'
2
+ require 'shared/common_model_actions_spec'
3
3
  require 'spatial_adapter/postgresql'
4
4
  require 'db/postgis_raw'
5
5
  require 'models/common'
@@ -9,68 +9,70 @@ describe "Spatially-enabled Models" do
9
9
  postgis_connection
10
10
  @connection = ActiveRecord::Base.connection
11
11
  end
12
-
12
+
13
+ it_should_behave_like 'common model actions'
14
+
13
15
  describe "inserting records" do
14
16
  it 'should save Point objects' do
15
17
  model = PointModel.new(:extra => 'test', :geom => GeometryFactory.point)
16
18
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point.as_hex_ewkb))
17
19
  model.save.should == true
18
20
  end
19
-
21
+
20
22
  it 'should save LineString objects' do
21
23
  model = LineStringModel.new(:extra => 'test', :geom => GeometryFactory.line_string)
22
24
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.line_string.as_hex_ewkb))
23
25
  model.save.should == true
24
26
  end
25
-
27
+
26
28
  it 'should save Polygon objects' do
27
29
  model = PolygonModel.new(:extra => 'test', :geom => GeometryFactory.polygon)
28
30
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.polygon.as_hex_ewkb))
29
31
  model.save.should == true
30
32
  end
31
-
33
+
32
34
  it 'should save MultiPoint objects' do
33
35
  model = MultiPointModel.new(:extra => 'test', :geom => GeometryFactory.multi_point)
34
36
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_point.as_hex_ewkb))
35
37
  model.save.should == true
36
38
  end
37
-
39
+
38
40
  it 'should save MultiLineString objects' do
39
41
  model = MultiLineStringModel.new(:extra => 'test', :geom => GeometryFactory.multi_line_string)
40
42
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_line_string.as_hex_ewkb))
41
43
  model.save.should == true
42
44
  end
43
-
45
+
44
46
  it 'should save MultiPolygon objects' do
45
47
  model = MultiPolygonModel.new(:extra => 'test', :geom => GeometryFactory.multi_polygon)
46
48
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_polygon.as_hex_ewkb))
47
49
  model.save.should == true
48
50
  end
49
-
51
+
50
52
  it 'should save GeometryCollection objects' do
51
53
  model = GeometryCollectionModel.new(:extra => 'test', :geom => GeometryFactory.geometry_collection)
52
54
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.geometry_collection.as_hex_ewkb))
53
55
  model.save.should == true
54
56
  end
55
-
57
+
56
58
  it 'should save Geometry objects' do
57
59
  model = GeometryModel.new(:extra => 'test', :geom => GeometryFactory.point)
58
60
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point.as_hex_ewkb))
59
61
  model.save.should == true
60
62
  end
61
-
63
+
62
64
  it 'should save 3D Point (with Z coord) objects' do
63
65
  model = PointzModel.new(:extra => 'test', :geom => GeometryFactory.pointz)
64
66
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.pointz.as_hex_ewkb))
65
67
  model.save.should == true
66
68
  end
67
-
69
+
68
70
  it 'should save 3D Point (with M coord) objects' do
69
71
  model = PointmModel.new(:extra => 'test', :geom => GeometryFactory.pointm)
70
72
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.pointm.as_hex_ewkb))
71
73
  model.save.should == true
72
74
  end
73
-
75
+
74
76
  it 'should save 4D Point objects' do
75
77
  model = Point4Model.new(:extra => 'test', :geom => GeometryFactory.point4)
76
78
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point4.as_hex_ewkb))
@@ -82,61 +84,61 @@ describe "Spatially-enabled Models" do
82
84
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point.as_hex_ewkb))
83
85
  model.save.should == true
84
86
  end
85
-
87
+
86
88
  it 'should save LineString geography objects' do
87
89
  model = GeographyLineStringModel.new(:extra => 'test', :geom => GeometryFactory.line_string)
88
90
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.line_string.as_hex_ewkb))
89
91
  model.save.should == true
90
92
  end
91
-
93
+
92
94
  it 'should save Polygon geography objects' do
93
95
  model = GeographyPolygonModel.new(:extra => 'test', :geom => GeometryFactory.polygon)
94
96
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.polygon.as_hex_ewkb))
95
97
  model.save.should == true
96
98
  end
97
-
99
+
98
100
  it 'should save MultiPoint geography objects' do
99
101
  model = GeographyMultiPointModel.new(:extra => 'test', :geom => GeometryFactory.multi_point)
100
102
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_point.as_hex_ewkb))
101
103
  model.save.should == true
102
104
  end
103
-
105
+
104
106
  it 'should save MultiLineString geography objects' do
105
107
  model = GeographyMultiLineStringModel.new(:extra => 'test', :geom => GeometryFactory.multi_line_string)
106
108
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_line_string.as_hex_ewkb))
107
109
  model.save.should == true
108
110
  end
109
-
111
+
110
112
  it 'should save MultiPolygon geography objects' do
111
113
  model = GeographyMultiPolygonModel.new(:extra => 'test', :geom => GeometryFactory.multi_polygon)
112
114
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_polygon.as_hex_ewkb))
113
115
  model.save.should == true
114
116
  end
115
-
117
+
116
118
  it 'should save GeometryCollection geography objects' do
117
119
  model = GeographyGeometryCollectionModel.new(:extra => 'test', :geom => GeometryFactory.geometry_collection)
118
120
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.geometry_collection.as_hex_ewkb))
119
121
  model.save.should == true
120
122
  end
121
-
123
+
122
124
  it 'should save Geography objects' do
123
125
  model = GeographyModel.new(:extra => 'test', :geom => GeometryFactory.point)
124
126
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point.as_hex_ewkb))
125
127
  model.save.should == true
126
128
  end
127
-
129
+
128
130
  it 'should save 3D Point (with Z coord) geography objects' do
129
131
  model = GeographyPointzModel.new(:extra => 'test', :geom => GeometryFactory.pointz)
130
132
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.pointz.as_hex_ewkb))
131
133
  model.save.should == true
132
134
  end
133
-
135
+
134
136
  it 'should save 3D Point (with M coord) geography objects' do
135
137
  model = GeographyPointmModel.new(:extra => 'test', :geom => GeometryFactory.pointm)
136
138
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.pointm.as_hex_ewkb))
137
139
  model.save.should == true
138
140
  end
139
-
141
+
140
142
  it 'should save 4D Point geography objects' do
141
143
  model = GeographyPoint4Model.new(:extra => 'test', :geom => GeometryFactory.point4)
142
144
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point4.as_hex_ewkb))
@@ -144,19 +146,17 @@ describe "Spatially-enabled Models" do
144
146
  end
145
147
  end
146
148
 
147
- include CommonModelActions
148
-
149
- describe "finding records" do
149
+ describe "finding records" do
150
150
  it 'should retrieve 3D Point (with Z coord) objects' do
151
151
  model = PointzModel.create(:extra => 'test', :geom => GeometryFactory.pointz)
152
152
  PointzModel.find(model.id).geom.should == GeometryFactory.pointz
153
153
  end
154
-
154
+
155
155
  it 'should retrieve 3D Point (with M coord) objects' do
156
156
  model = GeographyPointmModel.create(:extra => 'test', :geom => GeometryFactory.pointm)
157
157
  GeographyPointmModel.find(model.id).geom.should == GeometryFactory.pointm
158
158
  end
159
-
159
+
160
160
  it 'should retrieve 4D Point objects' do
161
161
  model = GeographyPoint4Model.create(:extra => 'test', :geom => GeometryFactory.point4)
162
162
  GeographyPoint4Model.find(model.id).geom.should == GeometryFactory.point4
@@ -166,52 +166,52 @@ describe "Spatially-enabled Models" do
166
166
  model = GeographyPointModel.create(:extra => 'test', :geom => GeometryFactory.point)
167
167
  GeographyPointModel.find(model.id).geom.should == GeometryFactory.point
168
168
  end
169
-
169
+
170
170
  it 'should retrieve LineString geography objects' do
171
171
  model = GeographyLineStringModel.create(:extra => 'test', :geom => GeometryFactory.line_string)
172
172
  GeographyLineStringModel.find(model.id).geom.should == GeometryFactory.line_string
173
173
  end
174
-
174
+
175
175
  it 'should retrieve Polygon geography objects' do
176
176
  model = GeographyPolygonModel.create(:extra => 'test', :geom => GeometryFactory.polygon)
177
177
  GeographyPolygonModel.find(model.id).geom.should == GeometryFactory.polygon
178
178
  end
179
-
179
+
180
180
  it 'should retrieve MultiPoint geography objects' do
181
181
  model = GeographyMultiPointModel.create(:extra => 'test', :geom => GeometryFactory.multi_point)
182
182
  GeographyMultiPointModel.find(model.id).geom.should == GeometryFactory.multi_point
183
183
  end
184
-
184
+
185
185
  it 'should retrieve MultiLineString geography objects' do
186
186
  model = GeographyMultiLineStringModel.create(:extra => 'test', :geom => GeometryFactory.multi_line_string)
187
187
  GeographyMultiLineStringModel.find(model.id).geom.should == GeometryFactory.multi_line_string
188
188
  end
189
-
189
+
190
190
  it 'should retrieve MultiPolygon geography objects' do
191
191
  model = GeographyMultiPolygonModel.create(:extra => 'test', :geom => GeometryFactory.multi_polygon)
192
192
  GeographyMultiPolygonModel.find(model.id).geom.should == GeometryFactory.multi_polygon
193
193
  end
194
-
194
+
195
195
  it 'should retrieve GeometryCollection geography objects' do
196
196
  model = GeographyGeometryCollectionModel.create(:extra => 'test', :geom => GeometryFactory.geometry_collection)
197
197
  GeographyGeometryCollectionModel.find(model.id).geom.should == GeometryFactory.geometry_collection
198
198
  end
199
-
199
+
200
200
  it 'should retrieve Geometry geography objects' do
201
201
  model = GeographyModel.create(:extra => 'test', :geom => GeometryFactory.point)
202
202
  GeographyModel.find(model.id).geom.should == GeometryFactory.point
203
203
  end
204
-
204
+
205
205
  it 'should retrieve 3D Point (with Z coord) geography objects' do
206
206
  model = GeographyPointzModel.create(:extra => 'test', :geom => GeometryFactory.pointz)
207
207
  GeographyPointzModel.find(model.id).geom.should == GeometryFactory.pointz
208
208
  end
209
-
209
+
210
210
  it 'should retrieve 3D Point (with M coord) geography objects' do
211
211
  model = GeographyPointmModel.create(:extra => 'test', :geom => GeometryFactory.pointm)
212
212
  GeographyPointmModel.find(model.id).geom.should == GeometryFactory.pointm
213
213
  end
214
-
214
+
215
215
  it 'should retrieve 4D Point geography objects' do
216
216
  model = GeographyPoint4Model.create(:extra => 'test', :geom => GeometryFactory.point4)
217
217
  GeographyPoint4Model.find(model.id).geom.should == GeometryFactory.point4
@@ -20,18 +20,18 @@ describe "Spatially-enabled Schema Dumps" do
20
20
  end
21
21
  end
22
22
 
23
- File.open('schema.rb', "w") do |file|
23
+ File.open('schema.rb', "w:UTF-8") do |file|
24
24
  ActiveRecord::SchemaDumper.dump(@connection, file)
25
25
  end
26
-
26
+
27
27
  # Drop the original tables
28
28
  @connection.drop_table "migrated_geometry_models"
29
29
  @connection.drop_table "migrated_geography_models"
30
-
30
+
31
31
  # Load the dumped schema
32
32
  load('schema.rb')
33
33
  end
34
-
34
+
35
35
  after :all do
36
36
  # delete the schema file
37
37
  File.delete('schema.rb')
@@ -40,10 +40,10 @@ describe "Spatially-enabled Schema Dumps" do
40
40
  @connection.drop_table "migrated_geometry_models"
41
41
  @connection.drop_table "migrated_geography_models"
42
42
  end
43
-
43
+
44
44
  it "should preserve spatial attributes of geometry tables" do
45
45
  columns = @connection.columns("migrated_geometry_models")
46
-
46
+
47
47
  columns.should have(3).items
48
48
  geom_column = columns.select{|c| c.name == 'geom'}.first
49
49
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
@@ -53,10 +53,10 @@ describe "Spatially-enabled Schema Dumps" do
53
53
  geom_column.with_m.should == true
54
54
  geom_column.srid.should == 4326
55
55
  end
56
-
56
+
57
57
  it "should preserve spatial attributes of geography tables" do
58
58
  columns = @connection.columns("migrated_geography_models")
59
-
59
+
60
60
  columns.should have(3).items
61
61
  geom_column = columns.select{|c| c.name == 'geom'}.first
62
62
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
@@ -66,14 +66,14 @@ describe "Spatially-enabled Schema Dumps" do
66
66
  geom_column.with_m.should == true
67
67
  geom_column.should be_geographic
68
68
  end
69
-
69
+
70
70
  it "should preserve spatial indexes" do
71
71
  indexes = @connection.indexes("migrated_geometry_models")
72
-
72
+
73
73
  indexes.should have(1).item
74
-
74
+
75
75
  indexes.first.name.should == 'test_spatial_index'
76
76
  indexes.first.columns.should == ["geom"]
77
77
  indexes.first.spatial.should == true
78
78
  end
79
- end
79
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+ require 'postgresql/connection_adapter_spec'
3
+ require 'postgresql/migration_spec'
4
+ require 'postgresql/models_spec'
5
+ require 'postgresql/schema_dumper_spec'
@@ -1,5 +1,5 @@
1
- share_as :CommonModelActions do
2
- describe 'finding records' do
1
+ shared_examples_for 'common model actions' do
2
+ context 'finding records' do
3
3
  it 'should retrieve Point objects' do
4
4
  model = PointModel.create(:extra => 'test', :geom => GeometryFactory.point)
5
5
  PointModel.find(model.id).geom.should == GeometryFactory.point