spatial_adapter 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -3,7 +3,7 @@ require 'active_record/connection_adapters/mysql_adapter'
3
3
  ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
4
4
  include SpatialAdapter
5
5
 
6
- def supports_geography?
6
+ def supports_geographic?
7
7
  false
8
8
  end
9
9
 
@@ -28,12 +28,8 @@ ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
28
28
  columns = []
29
29
  result = execute(sql, name)
30
30
  result.each do |field|
31
- if field[1] =~ /geometry|point|linestring|polygon|multipoint|multilinestring|multipolygon|geometrycollection/i
32
- #to note that the column is spatial
33
- columns << ActiveRecord::ConnectionAdapters::SpatialMysqlColumn.new(field[0], field[4], field[1], field[2] == "YES")
34
- else
35
- columns << ActiveRecord::ConnectionAdapters::MysqlColumn.new(field[0], field[4], field[1], field[2] == "YES")
36
- end
31
+ klass = field[1] =~ /geometry|point|linestring|polygon|multipoint|multilinestring|multipolygon|geometrycollection/i ? ActiveRecord::ConnectionAdapters::SpatialMysqlColumn : ActiveRecord::ConnectionAdapters::MysqlColumn
32
+ columns << klass.new(field[0], field[4], field[1], field[2] == "YES")
37
33
  end
38
34
  result.free
39
35
  columns
@@ -25,7 +25,7 @@ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
25
25
  !postgis_version.nil?
26
26
  end
27
27
 
28
- def supports_geography?
28
+ def supports_geographic?
29
29
  postgis_major_version > 1 || (postgis_major_version == 1 && postgis_minor_version >= 5)
30
30
  end
31
31
 
@@ -49,9 +49,12 @@ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
49
49
 
50
50
  column_definitions(table_name).collect do |name, type, default, notnull|
51
51
  case type
52
+ when /geography/i
53
+ ActiveRecord::ConnectionAdapters::SpatialPostgreSQLColumn.create_from_geography(name, default, type, notnull == 'f')
52
54
  when /geometry/i
53
55
  raw_geom_info = raw_geom_infos[name]
54
56
  if raw_geom_info.nil?
57
+ # This column isn't in the geometry_columns table, so we don't know anything else about it
55
58
  ActiveRecord::ConnectionAdapters::SpatialPostgreSQLColumn.create_simplified(name, default, notnull == "f")
56
59
  else
57
60
  ActiveRecord::ConnectionAdapters::SpatialPostgreSQLColumn.new(name, default, raw_geom_info.type, notnull == "f", raw_geom_info.srid, raw_geom_info.with_z, raw_geom_info.with_m)
@@ -77,26 +80,28 @@ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
77
80
  create_sql << "#{quote_table_name(table_name)} ("
78
81
  create_sql << table_definition.to_sql
79
82
  create_sql << ") #{options[:options]}"
80
- execute create_sql
81
83
 
82
84
  # This is the additional portion for PostGIS
83
85
  unless table_definition.geom_columns.nil?
84
86
  table_definition.geom_columns.each do |geom_column|
85
- execute geom_column.to_sql(table_name)
87
+ geom_column.table_name = table_name
88
+ create_sql << "; " + geom_column.to_sql
86
89
  end
87
90
  end
91
+
92
+ execute create_sql
88
93
  end
89
94
 
90
95
  alias :original_remove_column :remove_column
91
- def remove_column(table_name, column_name, options = {})
96
+ def remove_column(table_name, *column_names)
97
+ column_names = column_names.flatten
92
98
  columns(table_name).each do |col|
93
- if col.name == column_name.to_s
94
- #check if the column is geometric
95
- unless geometry_data_types[col.type].nil? or
96
- (options[:remove_using_dropgeometrycolumn] == false)
97
- execute "SELECT DropGeometryColumn('#{table_name}','#{column_name}')"
99
+ if column_names.include?(col.name.to_sym)
100
+ # Geometry columns have to be removed using DropGeometryColumn
101
+ if col.type == :geometry && !col.geographic?
102
+ execute "SELECT DropGeometryColumn('#{table_name}','#{col.name}')"
98
103
  else
99
- original_remove_column(table_name, column_name)
104
+ original_remove_column(table_name, col.name)
100
105
  end
101
106
  end
102
107
  end
@@ -104,9 +109,20 @@ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
104
109
 
105
110
  alias :original_add_column :add_column
106
111
  def add_column(table_name, column_name, type, options = {})
107
- unless geometry_data_types[type].nil? or (options[:create_using_addgeometrycolumn] == false)
108
- geom_column = ActiveRecord::ConnectionAdapters::PostgreSQLColumnDefinition.new(self, column_name, type, nil, nil, options[:null], options[:srid] || -1 , options[:with_z] || false , options[:with_m] || false)
109
- execute geom_column.to_sql(table_name)
112
+ unless geometry_data_types[type].nil?
113
+ geom_column = ActiveRecord::ConnectionAdapters::PostgreSQLColumnDefinition.new(self, column_name, type, nil, nil, options[:null], options[:srid] || -1 , options[:with_z] || false , options[:with_m] || false, options[:geographic] || false)
114
+ if geom_column.geographic
115
+ default = options[:default]
116
+ notnull = options[:null] == false
117
+
118
+ execute("ALTER TABLE #{quote_table_name(table_name)} ADD COLUMN #{geom_column.to_sql}")
119
+
120
+ change_column_default(table_name, column_name, default) if options_include_default?(options)
121
+ change_column_null(table_name, column_name, false, default) if notnull
122
+ else
123
+ geom_column.table_name = table_name
124
+ execute geom_column.to_sql
125
+ end
110
126
  else
111
127
  original_add_column(table_name, column_name, type, options)
112
128
  end
@@ -228,14 +244,21 @@ module ActiveRecord
228
244
  unless (@base.geometry_data_types[type.to_sym].nil? or
229
245
  (options[:create_using_addgeometrycolumn] == false))
230
246
 
231
- geom_column = PostgreSQLColumnDefinition.new(@base, name, type)
232
- geom_column.null = options[:null]
233
- geom_column.srid = options[:srid] || -1
234
- geom_column.with_z = options[:with_z] || false
235
- geom_column.with_m = options[:with_m] || false
236
-
237
- @geom_columns ||= []
238
- @geom_columns << geom_column
247
+ column = self[name] || PostgreSQLColumnDefinition.new(@base, name, type)
248
+ column.null = options[:null]
249
+ column.srid = options[:srid] || -1
250
+ column.with_z = options[:with_z] || false
251
+ column.with_m = options[:with_m] || false
252
+ column.geographic = options[:geographic] || false
253
+
254
+ if column.geographic
255
+ @columns << column unless @columns.include? column
256
+ else
257
+ # Hold this column for later
258
+ @geom_columns ||= []
259
+ @geom_columns << column
260
+ end
261
+ self
239
262
  else
240
263
  super(name, type, options)
241
264
  end
@@ -243,20 +266,37 @@ module ActiveRecord
243
266
  end
244
267
 
245
268
  class PostgreSQLColumnDefinition < ColumnDefinition
246
- attr_accessor :srid, :with_z, :with_m
269
+ attr_accessor :table_name
270
+ attr_accessor :srid, :with_z, :with_m, :geographic
247
271
  attr_reader :spatial
248
272
 
249
- def initialize(base = nil, name = nil, type=nil, limit=nil, default=nil, null=nil, srid=-1, with_z=false, with_m=false)
250
- super(base, name, type, limit, default,null)
273
+ def initialize(base = nil, name = nil, type=nil, limit=nil, default=nil, null=nil, srid=-1, with_z=false, with_m=false, geographic=false)
274
+ super(base, name, type, limit, default, null)
275
+ @table_name = nil
251
276
  @spatial = true
252
277
  @srid = srid
253
278
  @with_z = with_z
254
279
  @with_m = with_m
280
+ @geographic = geographic
255
281
  end
256
282
 
257
- def to_sql(table_name)
258
- if @spatial
259
- type_sql = type_to_sql(type.to_sym)
283
+ def sql_type
284
+ if geographic
285
+ type_sql = base.geometry_data_types[type.to_sym][:name]
286
+ type_sql += "Z" if with_z
287
+ type_sql += "M" if with_m
288
+ # SRID is not yet supported (defaults to 4326)
289
+ #type_sql += ", #{srid}" if (srid && srid != -1)
290
+ type_sql = "geography(#{type_sql})"
291
+ type_sql
292
+ else
293
+ super
294
+ end
295
+ end
296
+
297
+ def to_sql
298
+ if spatial && !geographic
299
+ type_sql = base.geometry_data_types[type.to_sym][:name]
260
300
  type_sql += "M" if with_m and !with_z
261
301
  if with_m and with_z
262
302
  dimension = 4
@@ -265,7 +305,7 @@ module ActiveRecord
265
305
  else
266
306
  dimension = 2
267
307
  end
268
-
308
+
269
309
  column_sql = "SELECT AddGeometryColumn('#{table_name}','#{name}',#{srid},'#{type_sql}',#{dimension})"
270
310
  column_sql += ";ALTER TABLE #{table_name} ALTER #{name} SET NOT NULL" if null == false
271
311
  column_sql
@@ -273,12 +313,6 @@ module ActiveRecord
273
313
  super
274
314
  end
275
315
  end
276
-
277
- private
278
-
279
- def type_to_sql(name, limit=nil)
280
- base.type_to_sql(name, limit) rescue name
281
- end
282
316
  end
283
317
  end
284
318
  end
@@ -288,14 +322,60 @@ module ActiveRecord
288
322
  class SpatialPostgreSQLColumn < PostgreSQLColumn
289
323
  include SpatialAdapter::SpatialColumn
290
324
 
325
+ def initialize(name, default, sql_type = nil, null = true, srid=-1, with_z=false, with_m=false, geographic = false)
326
+ super(name, default, sql_type, null, srid, with_z, with_m)
327
+ @geographic = geographic
328
+ end
329
+
330
+ def geographic?
331
+ @geographic
332
+ end
333
+
291
334
  #Transforms a string to a geometry. PostGIS returns a HewEWKB string.
292
335
  def self.string_to_geometry(string)
293
336
  return string unless string.is_a?(String)
294
337
  GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb(string) rescue nil
295
338
  end
296
339
 
297
- def self.create_simplified(name,default,null = true)
298
- new(name,default,"geometry",null,nil,nil,nil)
340
+ def self.create_simplified(name, default, null = true)
341
+ new(name, default, "geometry", null)
342
+ end
343
+
344
+ def self.create_from_geography(name, default, sql_type, null = true)
345
+ params = extract_geography_params(sql_type)
346
+ new(name, default, sql_type, null, params[:srid], params[:with_z], params[:with_m], true)
347
+ end
348
+
349
+ private
350
+
351
+ # Add detection of PostGIS-specific geography columns
352
+ def geometry_simplified_type(sql_type)
353
+ case sql_type
354
+ when /geography\(point/i then :point
355
+ when /geography\(linestring/i then :line_string
356
+ when /geography\(polygon/i then :polygon
357
+ when /geography\(multipoint/i then :multi_point
358
+ when /geography\(multilinestring/i then :multi_line_string
359
+ when /geography\(multipolygon/i then :multi_polygon
360
+ when /geography\(geometrycollection/i then :geometry_collection
361
+ when /geography/i then :geometry
362
+ else
363
+ super
364
+ end
365
+ end
366
+
367
+ def self.extract_geography_params(sql_type)
368
+ params = {
369
+ :srid => 0,
370
+ :with_z => false,
371
+ :with_m => false
372
+ }
373
+ if sql_type =~ /geography(?:\((?:\w+?)(Z)?(M)?(?:,(\d+))?\))?/i
374
+ params[:with_z] = $1 == 'Z'
375
+ params[:with_m] = $2 == 'M'
376
+ params[:srid] = $3.to_i
377
+ end
378
+ params
299
379
  end
300
380
  end
301
381
  end
@@ -2,7 +2,7 @@ ActiveRecord::SchemaDumper.ignore_tables << "spatial_ref_sys" << "geometry_colum
2
2
 
3
3
  ActiveRecord::SchemaDumper.class_eval do
4
4
  # These are the valid options for a column specification (spatial options added)
5
- VALID_COLUMN_SPEC_KEYS = [:name, :limit, :precision, :scale, :default, :null, :srid, :with_z, :with_m]
5
+ VALID_COLUMN_SPEC_KEYS = [:name, :limit, :precision, :scale, :default, :null, :srid, :with_z, :with_m, :geographic]
6
6
 
7
7
  def table(table, stream)
8
8
  columns = @connection.columns(table)
@@ -129,6 +129,7 @@ ActiveRecord::SchemaDumper.class_eval do
129
129
  spec[:srid] = column.srid.inspect if column.srid != -1
130
130
  spec[:with_z] = 'true' if column.with_z
131
131
  spec[:with_m] = 'true' if column.with_m
132
+ spec[:geographic] = 'true' if column.geographic?
132
133
  end
133
134
  spec
134
135
  end
@@ -1,8 +1,8 @@
1
1
  module SpatialAdapter
2
2
  module SpatialColumn
3
- attr_reader :spatial, :geometry_type, :srid, :with_z, :with_m
3
+ attr_reader :geometry_type, :srid, :with_z, :with_m
4
4
 
5
- def initialize(name, default, sql_type = nil, null = true,srid=-1,with_z=false,with_m=false)
5
+ def initialize(name, default, sql_type = nil, null = true, srid=-1, with_z=false, with_m=false)
6
6
  super(name, default, sql_type, null)
7
7
  @geometry_type = geometry_simplified_type(@sql_type)
8
8
  @srid = srid
@@ -10,6 +10,10 @@ module SpatialAdapter
10
10
  @with_m = with_m
11
11
  end
12
12
 
13
+ def geographic?
14
+ false
15
+ end
16
+
13
17
  # Redefines type_cast to add support for geometries
14
18
  # alias_method :type_cast_without_spatial, :type_cast
15
19
  def type_cast(value)
@@ -43,17 +47,17 @@ module SpatialAdapter
43
47
 
44
48
  private
45
49
 
46
- #Redefines the simplified_type method to add behabiour for when a column is of type geometry
50
+ #Redefines the simplified_type method to spatial columns
47
51
  def simplified_type(field_type)
48
52
  case field_type
49
- when /geometry|point|linestring|polygon|multipoint|multilinestring|multipolygon|geometrycollection/i then :geometry
53
+ when /geography|geometry|point|linestring|polygon|multipoint|multilinestring|multipolygon|geometrycollection/i then :geometry
50
54
  else super
51
55
  end
52
56
  end
53
57
 
54
- #less simlpified geometric type to be use in migrations
55
- def geometry_simplified_type(field_type)
56
- case field_type
58
+ # less simlpified geometric type to be use in migrations
59
+ def geometry_simplified_type(sql_type)
60
+ case sql_type
57
61
  when /^point$/i then :point
58
62
  when /^linestring$/i then :line_string
59
63
  when /^polygon$/i then :polygon
@@ -93,4 +93,98 @@ ActiveRecord::Schema.define() do
93
93
  );
94
94
  select AddGeometryColumn('point4_models', 'geom', 4326, 'POINT', 4);
95
95
  SQL
96
+
97
+ if ActiveRecord::Base.connection.supports_geographic?
98
+ execute <<-SQL
99
+ drop table if exists geography_point_models;
100
+ create table geography_point_models
101
+ (
102
+ id serial primary key,
103
+ extra varchar(255),
104
+ geom geography(POINT)
105
+ );
106
+ create index index_geography_point_models_on_geom on geography_point_models using gist (geom);
107
+ create index index_geography_point_models_on_extra on geography_point_models (extra);
108
+
109
+ drop table if exists geography_line_string_models;
110
+ create table geography_line_string_models
111
+ (
112
+ id serial primary key,
113
+ extra varchar(255),
114
+ geom geography(LINESTRING)
115
+ );
116
+
117
+ drop table if exists geography_polygon_models;
118
+ create table geography_polygon_models
119
+ (
120
+ id serial primary key,
121
+ extra varchar(255),
122
+ geom geography(POLYGON)
123
+ );
124
+
125
+ drop table if exists geography_multi_point_models;
126
+ create table geography_multi_point_models
127
+ (
128
+ id serial primary key,
129
+ extra varchar(255),
130
+ geom geography(MULTIPOINT)
131
+ );
132
+
133
+ drop table if exists geography_multi_line_string_models;
134
+ create table geography_multi_line_string_models
135
+ (
136
+ id serial primary key,
137
+ extra varchar(255),
138
+ geom geography(MULTILINESTRING)
139
+ );
140
+
141
+ drop table if exists geography_multi_polygon_models;
142
+ create table geography_multi_polygon_models
143
+ (
144
+ id serial primary key,
145
+ extra varchar(255),
146
+ geom geography(MULTIPOLYGON)
147
+ );
148
+
149
+ drop table if exists geography_geometry_collection_models;
150
+ create table geography_geometry_collection_models
151
+ (
152
+ id serial primary key,
153
+ extra varchar(255),
154
+ geom geography(GEOMETRYCOLLECTION)
155
+ );
156
+
157
+ drop table if exists geography_models;
158
+ create table geography_models
159
+ (
160
+ id serial primary key,
161
+ extra varchar(255),
162
+ geom geography
163
+ );
164
+
165
+ drop table if exists geography_pointz_models;
166
+ create table geography_pointz_models
167
+ (
168
+ id serial primary key,
169
+ extra varchar(255),
170
+ geom geography(POINTZ)
171
+ );
172
+
173
+ drop table if exists geography_pointm_models;
174
+ create table geography_pointm_models
175
+ (
176
+ id serial primary key,
177
+ extra varchar(255),
178
+ geom geography(POINTM)
179
+ );
180
+
181
+ drop table if exists geography_point4_models;
182
+ create table geography_point4_models
183
+ (
184
+ id serial primary key,
185
+ extra varchar(255),
186
+ geom geography(POINTZM)
187
+ );
188
+ SQL
189
+ end
96
190
  end
@@ -30,3 +30,36 @@ end
30
30
 
31
31
  class Point4Model < ActiveRecord::Base
32
32
  end
33
+
34
+ class GeographyPointModel < ActiveRecord::Base
35
+ end
36
+
37
+ class GeographyLineStringModel < ActiveRecord::Base
38
+ end
39
+
40
+ class GeographyPolygonModel < ActiveRecord::Base
41
+ end
42
+
43
+ class GeographyMultiPointModel < ActiveRecord::Base
44
+ end
45
+
46
+ class GeographyMultiLineStringModel < ActiveRecord::Base
47
+ end
48
+
49
+ class GeographyMultiPolygonModel < ActiveRecord::Base
50
+ end
51
+
52
+ class GeographyGeometryCollectionModel < ActiveRecord::Base
53
+ end
54
+
55
+ class GeographyModel < ActiveRecord::Base
56
+ end
57
+
58
+ class GeographyPointzModel < ActiveRecord::Base
59
+ end
60
+
61
+ class GeographyPointmModel < ActiveRecord::Base
62
+ end
63
+
64
+ class GeographyPoint4Model < ActiveRecord::Base
65
+ end
@@ -8,9 +8,9 @@ describe "Modified MysqlAdapter" do
8
8
  @connection = ActiveRecord::Base.connection
9
9
  end
10
10
 
11
- describe '#supports_geography?' do
11
+ describe '#supports_geographic?' do
12
12
  it "should be false" do
13
- @connection.supports_geography?.should == false
13
+ @connection.supports_geographic?.should == false
14
14
  end
15
15
  end
16
16
 
@@ -56,27 +56,39 @@ describe "Modified PostgreSQLAdapter" do
56
56
  end
57
57
  end
58
58
 
59
- describe '#supports_geography?' do
59
+ describe '#supports_geographic?' do
60
60
  it "should be true for PostGIS version 1.5.0" do
61
61
  @connection.stub!(:postgis_version).and_return('1.5.0')
62
- @connection.supports_geography?.should == true
62
+ @connection.supports_geographic?.should == true
63
63
  end
64
64
 
65
65
  it "should be true for PostGIS newer than 1.5.0" do
66
66
  @connection.stub!(:postgis_version).and_return('1.5.1')
67
- @connection.supports_geography?.should == true
67
+ @connection.supports_geographic?.should == true
68
68
  end
69
69
 
70
70
  it "should be true for PostGIS older than 1.5.0" do
71
71
  @connection.stub!(:postgis_version).and_return('1.4.0')
72
- @connection.supports_geography?.should == false
72
+ @connection.supports_geographic?.should == false
73
73
  end
74
74
  end
75
75
 
76
76
  describe "#columns" do
77
77
  describe "type" do
78
- it "should be SpatialPostgreSQLColumn if column is a spatial data type" do
79
- PointModel.columns.select{|c| c.name == 'geom'}.first.should be_a(ActiveRecord::ConnectionAdapters::SpatialPostgreSQLColumn)
78
+ it "should be a regular SpatialPostgreSQLColumn if column is a geometry data type" do
79
+ column = PointModel.columns.select{|c| c.name == 'geom'}.first
80
+ column.should be_a(ActiveRecord::ConnectionAdapters::SpatialPostgreSQLColumn)
81
+ column.type.should == :geometry
82
+ column.geometry_type.should == :point
83
+ column.should_not be_geographic
84
+ end
85
+
86
+ it "should be a geographic SpatialPostgreSQLColumn if column is a geography data type" do
87
+ column = GeographyPointModel.columns.select{|c| c.name == 'geom'}.first
88
+ column.should be_a(ActiveRecord::ConnectionAdapters::SpatialPostgreSQLColumn)
89
+ column.type.should == :geometry
90
+ column.geometry_type.should == :point
91
+ column.should be_geographic
80
92
  end
81
93
 
82
94
  it "should be PostgreSQLColumn if column is not a spatial data type" do
@@ -85,37 +97,69 @@ describe "Modified PostgreSQLAdapter" do
85
97
  end
86
98
 
87
99
  describe "@geometry_type" do
88
- it "should be :point for columns restricted to POINT types" do
100
+ it "should be :point for geometry columns restricted to POINT types" do
89
101
  PointModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :point
90
102
  end
91
103
 
92
- it "should be :line_string for columns restricted to LINESTRING types" do
104
+ it "should be :line_string for geometry columns restricted to LINESTRING types" do
93
105
  LineStringModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :line_string
94
106
  end
95
107
 
96
- it "should be :polygon for columns restricted to POLYGON types" do
108
+ it "should be :polygon for geometry columns restricted to POLYGON types" do
97
109
  PolygonModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :polygon
98
110
  end
99
111
 
100
- it "should be :multi_point for columns restricted to MULTIPOINT types" do
112
+ it "should be :multi_point for geometry columns restricted to MULTIPOINT types" do
101
113
  MultiPointModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :multi_point
102
114
  end
103
115
 
104
- it "should be :multi_line_string for columns restricted to MULTILINESTRING types" do
116
+ it "should be :multi_line_string for geometry columns restricted to MULTILINESTRING types" do
105
117
  MultiLineStringModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :multi_line_string
106
118
  end
107
119
 
108
- it "should be :multi_polygon for columns restricted to MULTIPOLYGON types" do
120
+ it "should be :multi_polygon for geometry columns restricted to MULTIPOLYGON types" do
109
121
  MultiPolygonModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :multi_polygon
110
122
  end
111
123
 
112
- it "should be :geometry_collection for columns restricted to GEOMETRYCOLLECTION types" do
124
+ it "should be :geometry_collection for geometry columns restricted to GEOMETRYCOLLECTION types" do
113
125
  GeometryCollectionModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :geometry_collection
114
126
  end
115
127
 
116
- it "should be :geometry for columns not restricted to a type" do
128
+ it "should be :geometry for geometry columns not restricted to a type" do
117
129
  GeometryModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :geometry
118
130
  end
131
+
132
+ it "should be :point for geography columns restricted to POINT types" do
133
+ GeographyPointModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :point
134
+ end
135
+
136
+ it "should be :line_string for geography columns restricted to LINESTRING types" do
137
+ GeographyLineStringModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :line_string
138
+ end
139
+
140
+ it "should be :polygon for geography columns restricted to POLYGON types" do
141
+ GeographyPolygonModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :polygon
142
+ end
143
+
144
+ it "should be :multi_point for geography columns restricted to MULTIPOINT types" do
145
+ GeographyMultiPointModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :multi_point
146
+ end
147
+
148
+ it "should be :multi_line_string for geography columns restricted to MULTILINESTRING types" do
149
+ GeographyMultiLineStringModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :multi_line_string
150
+ end
151
+
152
+ it "should be :multi_polygon for geography columns restricted to MULTIPOLYGON types" do
153
+ GeographyMultiPolygonModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :multi_polygon
154
+ end
155
+
156
+ it "should be :geometry_collection for geography columns restricted to GEOMETRYCOLLECTION types" do
157
+ GeographyGeometryCollectionModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :geometry_collection
158
+ end
159
+
160
+ it "should be :geometry for geography columns not restricted to a type" do
161
+ GeographyModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :geometry
162
+ end
119
163
  end
120
164
  end
121
165
 
@@ -22,17 +22,38 @@ describe "Spatially-enabled Migrations" do
22
22
  t.send(type, :geom)
23
23
  end
24
24
  end
25
-
25
+
26
26
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
27
27
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
28
- geom_column.geometry_type.should == type
29
28
  geom_column.type.should == :geometry
29
+ geom_column.geometry_type.should == type
30
+ geom_column.should_not be_geographic
30
31
  geom_column.with_z.should == false
31
32
  geom_column.with_m.should == false
32
33
  geom_column.srid.should == -1
33
34
  end
35
+
36
+ it "should create #{type.to_s} geographic columns" do
37
+ ActiveRecord::Schema.define do
38
+ create_table :migrated_geometry_models, :force => true do |t|
39
+ t.integer :extra
40
+ t.column :geom, type, :geographic => true
41
+ end
42
+ end
43
+
44
+ geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
45
+
46
+ geom_column.should be_a(SpatialAdapter::SpatialColumn)
47
+ geom_column.type.should == :geometry
48
+ geom_column.geometry_type.should == type
49
+ geom_column.should be_geographic
50
+ geom_column.with_z.should == false
51
+ geom_column.with_m.should == false
52
+ #geom_column.srid.should == 4326 # SRID is currently irrelevant for geography columns
53
+ end
34
54
  end
35
55
 
56
+
36
57
  it "should create 3d (xyz) geometry columns" do
37
58
  ActiveRecord::Schema.define do
38
59
  create_table :migrated_geometry_models, :force => true do |t|
@@ -84,19 +105,70 @@ describe "Spatially-enabled Migrations" do
84
105
  geom_column.srid.should == -1
85
106
  end
86
107
 
87
-
88
- it "should create GEOMETRY columns with specified SRID" do
108
+ it "should create 3d (xyz) geographic columns" do
109
+ ActiveRecord::Schema.define do
110
+ create_table :migrated_geometry_models, :force => true do |t|
111
+ t.integer :extra
112
+ t.point :geom, :with_z => true, :geographic => true
113
+ end
114
+ end
115
+
116
+ geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
117
+ geom_column.should be_a(SpatialAdapter::SpatialColumn)
118
+ geom_column.should be_geographic
119
+ geom_column.with_z.should == true
120
+ geom_column.with_m.should == false
121
+ end
122
+
123
+
124
+ it "should create 3d (xym) geographic columns" do
125
+ ActiveRecord::Schema.define do
126
+ create_table :migrated_geometry_models, :force => true do |t|
127
+ t.integer :extra
128
+ t.point :geom, :with_m => true, :geographic => true
129
+ end
130
+ end
131
+
132
+ geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
133
+ geom_column.should be_a(SpatialAdapter::SpatialColumn)
134
+ geom_column.geometry_type.should == :point
135
+ geom_column.type.should == :geometry
136
+ geom_column.should be_geographic
137
+ geom_column.with_z.should == false
138
+ geom_column.with_m.should == true
139
+ end
140
+
141
+
142
+ it "should create 4d (xyzm) geographic columns" do
143
+ ActiveRecord::Schema.define do
144
+ create_table :migrated_geometry_models, :force => true do |t|
145
+ t.integer :extra
146
+ t.point :geom, :with_z => true, :with_m => true, :geographic => true
147
+ end
148
+ end
149
+
150
+ geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
151
+ geom_column.should be_a(SpatialAdapter::SpatialColumn)
152
+ geom_column.geometry_type.should == :point
153
+ geom_column.should be_geographic
154
+ geom_column.type.should == :geometry
155
+ geom_column.with_z.should == true
156
+ geom_column.with_m.should == true
157
+ end
158
+
159
+
160
+ it "should create geometry columns with specified SRID" do
89
161
  ActiveRecord::Schema.define do
90
162
  create_table :migrated_geometry_models, :force => true do |t|
91
163
  t.integer :extra
92
164
  t.geometry :geom, :srid => 4326
93
165
  end
94
166
  end
95
-
167
+
96
168
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
97
169
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
98
- geom_column.geometry_type.should == :geometry
99
170
  geom_column.type.should == :geometry
171
+ geom_column.geometry_type.should == :geometry
100
172
  geom_column.with_z.should == false
101
173
  geom_column.with_m.should == false
102
174
  geom_column.srid.should == 4326
@@ -115,70 +187,116 @@ describe "Spatially-enabled Migrations" do
115
187
  after :each do
116
188
  @connection.drop_table "migrated_geometry_models"
117
189
  end
118
-
190
+
119
191
  SpatialAdapter.geometry_data_types.keys.each do |type|
120
192
  it "should add #{type.to_s} columns" do
121
193
  ActiveRecord::Schema.define do
122
194
  add_column :migrated_geometry_models, :geom, type
123
195
  end
124
-
196
+
125
197
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
126
198
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
127
- geom_column.geometry_type.should == type
128
199
  geom_column.type.should == :geometry
200
+ geom_column.geometry_type.should == type
129
201
  geom_column.with_z.should == false
130
202
  geom_column.with_m.should == false
131
203
  geom_column.srid.should == -1
132
204
  end
133
205
  end
134
-
206
+
135
207
  it "should add 3d (xyz) geometry columns" do
136
208
  ActiveRecord::Schema.define do
137
209
  add_column :migrated_geometry_models, :geom, :point, :with_z => true
138
210
  end
139
-
211
+
140
212
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
141
213
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
214
+ geom_column.type.should == :geometry
215
+ geom_column.geometry_type.should == :point
142
216
  geom_column.with_z.should == true
143
217
  geom_column.with_m.should == false
144
218
  geom_column.srid.should == -1
145
219
  end
146
-
147
-
220
+
221
+
148
222
  it "should add 3d (xym) geometry columns" do
149
223
  ActiveRecord::Schema.define do
150
224
  add_column :migrated_geometry_models, :geom, :point, :with_m => true
151
225
  end
152
-
226
+
153
227
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
154
228
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
155
- geom_column.geometry_type.should == :point
156
229
  geom_column.type.should == :geometry
230
+ geom_column.geometry_type.should == :point
157
231
  geom_column.with_z.should == false
158
232
  geom_column.with_m.should == true
159
233
  geom_column.srid.should == -1
160
234
  end
161
-
162
-
235
+
236
+
163
237
  it "should add 4d (xyzm) geometry columns" do
164
238
  ActiveRecord::Schema.define do
165
239
  add_column :migrated_geometry_models, :geom, :point, :with_z => true, :with_m => true
166
240
  end
167
-
241
+
168
242
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
169
243
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
170
- geom_column.geometry_type.should == :point
171
244
  geom_column.type.should == :geometry
245
+ geom_column.geometry_type.should == :point
172
246
  geom_column.with_z.should == true
173
247
  geom_column.with_m.should == true
174
248
  geom_column.srid.should == -1
175
249
  end
250
+
251
+ it "should add 3d (xyz) geography columns" do
252
+ ActiveRecord::Schema.define do
253
+ add_column :migrated_geometry_models, :geom, :point, :with_z => true, :geographic => true
254
+ end
255
+
256
+ geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
257
+ geom_column.should be_a(SpatialAdapter::SpatialColumn)
258
+ geom_column.type.should == :geometry
259
+ geom_column.should be_geographic
260
+ geom_column.geometry_type.should == :point
261
+ geom_column.with_z.should == true
262
+ geom_column.with_m.should == false
263
+ end
264
+
265
+
266
+ it "should add 3d (xym) geography columns" do
267
+ ActiveRecord::Schema.define do
268
+ add_column :migrated_geometry_models, :geom, :point, :with_m => true, :geographic => true
269
+ end
270
+
271
+ geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
272
+ geom_column.should be_a(SpatialAdapter::SpatialColumn)
273
+ geom_column.type.should == :geometry
274
+ geom_column.should be_geographic
275
+ geom_column.geometry_type.should == :point
276
+ geom_column.with_z.should == false
277
+ geom_column.with_m.should == true
278
+ end
279
+
280
+
281
+ it "should add 4d (xyzm) geography columns" do
282
+ ActiveRecord::Schema.define do
283
+ add_column :migrated_geometry_models, :geom, :point, :with_z => true, :with_m => true, :geographic => true
284
+ end
285
+
286
+ geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
287
+ geom_column.should be_a(SpatialAdapter::SpatialColumn)
288
+ geom_column.type.should == :geometry
289
+ geom_column.should be_geographic
290
+ geom_column.geometry_type.should == :point
291
+ geom_column.with_z.should == true
292
+ geom_column.with_m.should == true
293
+ end
176
294
 
177
295
  it "should add GEOMETRY columns with specified SRID" do
178
296
  ActiveRecord::Schema.define do
179
297
  add_column :migrated_geometry_models, :geom, :geometry, :srid => 4326
180
298
  end
181
-
299
+
182
300
  geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
183
301
  geom_column.should be_a(SpatialAdapter::SpatialColumn)
184
302
  geom_column.geometry_type.should == :geometry
@@ -190,13 +308,10 @@ describe "Spatially-enabled Migrations" do
190
308
  end
191
309
 
192
310
  describe "removing columns" do
193
- before :each do
194
- end
195
-
196
311
  after :each do
197
312
  @connection.drop_table "migrated_geometry_models"
198
313
  end
199
-
314
+
200
315
  SpatialAdapter.geometry_data_types.keys.each do |type|
201
316
  it "should remove #{type.to_s} columns using DropGeometryColumn" do
202
317
  ActiveRecord::Schema.define do
@@ -205,7 +320,7 @@ describe "Spatially-enabled Migrations" do
205
320
  t.send(type, :geom)
206
321
  end
207
322
  end
208
-
323
+
209
324
  @connection.should_receive(:execute).with(/DropGeometryColumn(.*migrated_geometry_models.*geom)/)
210
325
  ActiveRecord::Schema.define do
211
326
  remove_column :migrated_geometry_models, :geom
@@ -213,6 +328,23 @@ describe "Spatially-enabled Migrations" do
213
328
  @connection.should_receive(:execute).with(anything())
214
329
  end
215
330
  end
331
+
332
+
333
+ SpatialAdapter.geometry_data_types.keys.each do |type|
334
+ it "should remove #{type.to_s} geography columns using ALTER TABLE DROP COLUMN" do
335
+ ActiveRecord::Schema.define do
336
+ create_table :migrated_geometry_models, :force => true do |t|
337
+ t.integer :extra
338
+ t.send(type, :geom, :geographic => true)
339
+ end
340
+ end
341
+
342
+ @connection.should_receive(:execute).with(/alter table.*migrated_geometry_models.*drop.*geom/i)
343
+ ActiveRecord::Schema.define do
344
+ remove_column :migrated_geometry_models, :geom
345
+ end
346
+ @connection.should_receive(:execute).with(anything())
347
+ end
348
+ end
216
349
  end
217
-
218
350
  end
@@ -74,6 +74,72 @@ describe "Spatially-enabled Models" do
74
74
  @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point4.as_hex_ewkb))
75
75
  model.save.should == true
76
76
  end
77
+
78
+ it 'should save Point geography objects' do
79
+ model = GeographyPointModel.new(:extra => 'test', :geom => GeometryFactory.point)
80
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point.as_hex_ewkb))
81
+ model.save.should == true
82
+ end
83
+
84
+ it 'should save LineString geography objects' do
85
+ model = GeographyLineStringModel.new(:extra => 'test', :geom => GeometryFactory.line_string)
86
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.line_string.as_hex_ewkb))
87
+ model.save.should == true
88
+ end
89
+
90
+ it 'should save Polygon geography objects' do
91
+ model = GeographyPolygonModel.new(:extra => 'test', :geom => GeometryFactory.polygon)
92
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.polygon.as_hex_ewkb))
93
+ model.save.should == true
94
+ end
95
+
96
+ it 'should save MultiPoint geography objects' do
97
+ model = GeographyMultiPointModel.new(:extra => 'test', :geom => GeometryFactory.multi_point)
98
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_point.as_hex_ewkb))
99
+ model.save.should == true
100
+ end
101
+
102
+ it 'should save MultiLineString geography objects' do
103
+ model = GeographyMultiLineStringModel.new(:extra => 'test', :geom => GeometryFactory.multi_line_string)
104
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_line_string.as_hex_ewkb))
105
+ model.save.should == true
106
+ end
107
+
108
+ it 'should save MultiPolygon geography objects' do
109
+ model = GeographyMultiPolygonModel.new(:extra => 'test', :geom => GeometryFactory.multi_polygon)
110
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_polygon.as_hex_ewkb))
111
+ model.save.should == true
112
+ end
113
+
114
+ it 'should save GeometryCollection geography objects' do
115
+ model = GeographyGeometryCollectionModel.new(:extra => 'test', :geom => GeometryFactory.geometry_collection)
116
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.geometry_collection.as_hex_ewkb))
117
+ model.save.should == true
118
+ end
119
+
120
+ it 'should save Geography objects' do
121
+ model = GeographyModel.new(:extra => 'test', :geom => GeometryFactory.point)
122
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point.as_hex_ewkb))
123
+ model.save.should == true
124
+ end
125
+
126
+ it 'should save 3D Point (with Z coord) geography objects' do
127
+ model = GeographyPointzModel.new(:extra => 'test', :geom => GeometryFactory.pointz)
128
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.pointz.as_hex_ewkb))
129
+ model.save.should == true
130
+ end
131
+
132
+ it 'should save 3D Point (with M coord) geography objects' do
133
+ model = GeographyPointmModel.new(:extra => 'test', :geom => GeometryFactory.pointm)
134
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.pointm.as_hex_ewkb))
135
+ model.save.should == true
136
+ end
137
+
138
+ it 'should save 4D Point geography objects' do
139
+ model = GeographyPoint4Model.new(:extra => 'test', :geom => GeometryFactory.point4)
140
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point4.as_hex_ewkb))
141
+ model.save.should == true
142
+ end
77
143
  end
78
144
 
79
145
  describe "finding records" do
@@ -123,13 +189,68 @@ describe "Spatially-enabled Models" do
123
189
  end
124
190
 
125
191
  it 'should retrieve 3D Point (with M coord) objects' do
126
- model = PointmModel.create(:extra => 'test', :geom => GeometryFactory.pointm)
127
- PointmModel.find(model.id).geom.should == GeometryFactory.pointm
192
+ model = GeographyPointmModel.create(:extra => 'test', :geom => GeometryFactory.pointm)
193
+ GeographyPointmModel.find(model.id).geom.should == GeometryFactory.pointm
128
194
  end
129
195
 
130
196
  it 'should retrieve 4D Point objects' do
131
- model = Point4Model.create(:extra => 'test', :geom => GeometryFactory.point4)
132
- Point4Model.find(model.id).geom.should == GeometryFactory.point4
197
+ model = GeographyPoint4Model.create(:extra => 'test', :geom => GeometryFactory.point4)
198
+ GeographyPoint4Model.find(model.id).geom.should == GeometryFactory.point4
199
+ end
200
+
201
+ it 'should retrieve Point geography objects' do
202
+ model = GeographyPointModel.create(:extra => 'test', :geom => GeometryFactory.point)
203
+ GeographyPointModel.find(model.id).geom.should == GeometryFactory.point
204
+ end
205
+
206
+ it 'should retrieve LineString geography objects' do
207
+ model = GeographyLineStringModel.create(:extra => 'test', :geom => GeometryFactory.line_string)
208
+ GeographyLineStringModel.find(model.id).geom.should == GeometryFactory.line_string
209
+ end
210
+
211
+ it 'should retrieve Polygon geography objects' do
212
+ model = GeographyPolygonModel.create(:extra => 'test', :geom => GeometryFactory.polygon)
213
+ GeographyPolygonModel.find(model.id).geom.should == GeometryFactory.polygon
214
+ end
215
+
216
+ it 'should retrieve MultiPoint geography objects' do
217
+ model = GeographyMultiPointModel.create(:extra => 'test', :geom => GeometryFactory.multi_point)
218
+ GeographyMultiPointModel.find(model.id).geom.should == GeometryFactory.multi_point
219
+ end
220
+
221
+ it 'should retrieve MultiLineString geography objects' do
222
+ model = GeographyMultiLineStringModel.create(:extra => 'test', :geom => GeometryFactory.multi_line_string)
223
+ GeographyMultiLineStringModel.find(model.id).geom.should == GeometryFactory.multi_line_string
224
+ end
225
+
226
+ it 'should retrieve MultiPolygon geography objects' do
227
+ model = GeographyMultiPolygonModel.create(:extra => 'test', :geom => GeometryFactory.multi_polygon)
228
+ GeographyMultiPolygonModel.find(model.id).geom.should == GeometryFactory.multi_polygon
229
+ end
230
+
231
+ it 'should retrieve GeometryCollection geography objects' do
232
+ model = GeographyGeometryCollectionModel.create(:extra => 'test', :geom => GeometryFactory.geometry_collection)
233
+ GeographyGeometryCollectionModel.find(model.id).geom.should == GeometryFactory.geometry_collection
234
+ end
235
+
236
+ it 'should retrieve Geometry geography objects' do
237
+ model = GeographyModel.create(:extra => 'test', :geom => GeometryFactory.point)
238
+ GeographyModel.find(model.id).geom.should == GeometryFactory.point
239
+ end
240
+
241
+ it 'should retrieve 3D Point (with Z coord) geography objects' do
242
+ model = GeographyPointzModel.create(:extra => 'test', :geom => GeometryFactory.pointz)
243
+ GeographyPointzModel.find(model.id).geom.should == GeometryFactory.pointz
244
+ end
245
+
246
+ it 'should retrieve 3D Point (with M coord) geography objects' do
247
+ model = GeographyPointmModel.create(:extra => 'test', :geom => GeometryFactory.pointm)
248
+ GeographyPointmModel.find(model.id).geom.should == GeometryFactory.pointm
249
+ end
250
+
251
+ it 'should retrieve 4D Point geography objects' do
252
+ model = GeographyPoint4Model.create(:extra => 'test', :geom => GeometryFactory.point4)
253
+ GeographyPoint4Model.find(model.id).geom.should == GeometryFactory.point4
133
254
  end
134
255
  end
135
256
  end
@@ -12,14 +12,20 @@ describe "Spatially-enabled Schema Dumps" do
12
12
  t.point :geom, :with_m => true, :with_z => true, :srid => 4326
13
13
  end
14
14
  add_index :migrated_geometry_models, :geom, :spatial => true, :name => 'test_spatial_index'
15
+
16
+ create_table :migrated_geography_models, :force => true do |t|
17
+ t.integer :extra
18
+ t.point :geom, :with_m => true, :with_z => true, :geographic => true
19
+ end
15
20
  end
16
21
 
17
22
  File.open('schema.rb', "w") do |file|
18
23
  ActiveRecord::SchemaDumper.dump(@connection, file)
19
24
  end
20
25
 
21
- # Drop the original table
22
- @connection.execute "drop table migrated_geometry_models"
26
+ # Drop the original tables
27
+ @connection.drop_table "migrated_geometry_models"
28
+ @connection.drop_table "migrated_geography_models"
23
29
 
24
30
  # Load the dumped schema
25
31
  load('schema.rb')
@@ -29,11 +35,12 @@ describe "Spatially-enabled Schema Dumps" do
29
35
  # delete the schema file
30
36
  File.delete('schema.rb')
31
37
 
32
- # Drop the new table
33
- @connection.execute "drop table migrated_geometry_models"
38
+ # Drop the new tables
39
+ @connection.drop_table "migrated_geometry_models"
40
+ @connection.drop_table "migrated_geography_models"
34
41
  end
35
42
 
36
- it "should preserve spatial attributes of tables" do
43
+ it "should preserve spatial attributes of geometry tables" do
37
44
  columns = @connection.columns("migrated_geometry_models")
38
45
 
39
46
  columns.should have(3).items
@@ -46,6 +53,19 @@ describe "Spatially-enabled Schema Dumps" do
46
53
  geom_column.srid.should == 4326
47
54
  end
48
55
 
56
+ it "should preserve spatial attributes of geography tables" do
57
+ columns = @connection.columns("migrated_geography_models")
58
+
59
+ columns.should have(3).items
60
+ geom_column = columns.select{|c| c.name == 'geom'}.first
61
+ geom_column.should be_a(SpatialAdapter::SpatialColumn)
62
+ geom_column.geometry_type.should == :point
63
+ geom_column.type.should == :geometry
64
+ geom_column.with_z.should == true
65
+ geom_column.with_m.should == true
66
+ geom_column.should be_geographic
67
+ end
68
+
49
69
  it "should preserve spatial indexes" do
50
70
  indexes = @connection.indexes("migrated_geometry_models")
51
71
 
data/spec/spec_helper.rb CHANGED
@@ -43,11 +43,11 @@ class GeometryFactory
43
43
  end
44
44
 
45
45
  def multi_point
46
- MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]], 4326)
46
+ MultiPoint.from_coordinates([[12.4,-23.3],[-65.1,23.4],[23.55555555,23]], 4326)
47
47
  end
48
48
 
49
49
  def multi_line_string
50
- MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]]),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]])], 4326)
50
+ MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]]),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,23.3]])], 4326)
51
51
  end
52
52
 
53
53
  def multi_polygon
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spatial_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Deffendol