spatial_adapter 1.1.2 → 1.2.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/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.2
1
+ 1.2.0
@@ -0,0 +1,97 @@
1
+ require 'spatial_adapter'
2
+ require 'active_record/connection_adapters/mysql2_adapter'
3
+
4
+ ActiveRecord::ConnectionAdapters::Mysql2Adapter.class_eval do
5
+ include SpatialAdapter
6
+
7
+ def supports_geographic?
8
+ false
9
+ end
10
+
11
+ alias :original_native_database_types :native_database_types
12
+ def native_database_types
13
+ original_native_database_types.merge!(geometry_data_types)
14
+ end
15
+
16
+ alias :original_quote :quote
17
+ #Redefines the quote method to add behaviour for when a Geometry is encountered ; used when binding variables in find_by methods
18
+ def quote(value, column = nil)
19
+ if value.kind_of?(GeoRuby::SimpleFeatures::Geometry)
20
+ "GeomFromWKB(0x#{value.as_hex_wkb},#{value.srid})"
21
+ else
22
+ original_quote(value,column)
23
+ end
24
+ end
25
+
26
+ #Redefinition of columns to add the information that a column is geometric
27
+ def columns(table_name, name = nil)#:nodoc:
28
+ sql = "SHOW FIELDS FROM #{quote_table_name(table_name)}"
29
+ columns = []
30
+ result = execute(sql, name)
31
+ result.each do |field|
32
+ klass = field[1] =~ /geometry|point|linestring|polygon|multipoint|multilinestring|multipolygon|geometrycollection/i ? ActiveRecord::ConnectionAdapters::SpatialMysql2Column : ActiveRecord::ConnectionAdapters::Mysql2Column
33
+ columns << klass.new(field[0], field[4], field[1], field[2] == "YES")
34
+ end
35
+ columns
36
+ end
37
+
38
+
39
+ #operations relative to migrations
40
+
41
+ #Redefines add_index to support the case where the index is spatial
42
+ #If the :spatial key in the options table is true, then the sql string for a spatial index is created
43
+ def add_index(table_name,column_name,options = {})
44
+ index_name = options[:name] || index_name(table_name,:column => Array(column_name))
45
+
46
+ if options[:spatial]
47
+ execute "CREATE SPATIAL INDEX #{index_name} ON #{table_name} (#{Array(column_name).join(", ")})"
48
+ else
49
+ super
50
+ end
51
+ end
52
+
53
+ #Check the nature of the index : If it is SPATIAL, it is indicated in the IndexDefinition object (redefined to add the spatial flag in spatial_adapter_common.rb)
54
+ def indexes(table_name, name = nil)#:nodoc:
55
+ indexes = []
56
+ current_index = nil
57
+ (execute("SHOW KEYS FROM #{table_name}", name) || []).each do |row|
58
+ if current_index != row[2]
59
+ next if row[2] == "PRIMARY" # skip the primary key
60
+ current_index = row[2]
61
+ indexes << ActiveRecord::ConnectionAdapters::IndexDefinition.new(row[0], row[2], row[1] == "0", [], row[10] == "SPATIAL")
62
+ end
63
+ indexes.last.columns << row[4]
64
+ end
65
+ indexes
66
+ end
67
+
68
+ #Get the table creation options : Only the engine for now. The text encoding could also be parsed and returned here.
69
+ def options_for(table)
70
+ result = execute("show table status like '#{table}'")
71
+ engine = result.first[1]
72
+ if engine !~ /inno/i #inno is default so do nothing for it in order not to clutter the migration
73
+ "ENGINE=#{engine}"
74
+ else
75
+ nil
76
+ end
77
+ end
78
+ end
79
+
80
+
81
+ module ActiveRecord
82
+ module ConnectionAdapters
83
+ class SpatialMysql2Column < Mysql2Column
84
+ include SpatialAdapter::SpatialColumn
85
+
86
+ #MySql-specific geometry string parsing. By default, MySql returns geometries in strict wkb format with "0" characters in the first 4 positions.
87
+ def self.string_to_geometry(string)
88
+ return string unless string.is_a?(String)
89
+ begin
90
+ GeoRuby::SimpleFeatures::Geometry.from_ewkb(string[4..-1])
91
+ rescue Exception => exception
92
+ nil
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
data/spec/README.txt CHANGED
@@ -6,7 +6,7 @@ You will need to set up empty databases for each adapter you want to test.
6
6
 
7
7
  Create an empty database "spatial_adapter" and ensure that the PostGIS extensions are loaded.
8
8
 
9
- run "rake spec:postgis" to run the specs
9
+ run "rake spec:postgresql" to run the specs
10
10
 
11
11
  == MySQL
12
12
 
@@ -14,3 +14,9 @@ Create an empty database "spatial_adapter" - the spatial extensions are already
14
14
 
15
15
  run "rake spec:mysql" to run the specs
16
16
 
17
+ == MySQL2
18
+
19
+ Create an empty database "spatial_adapter" - the spatial extensions are already available.
20
+
21
+ run "rake spec:mysql2" to run the specs
22
+
@@ -0,0 +1,70 @@
1
+ mysql2_connection
2
+
3
+ ActiveRecord::Schema.define() do
4
+ execute "drop table if exists point_models"
5
+ execute "create table point_models
6
+ (
7
+ id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
8
+ extra varchar(255),
9
+ more_extra varchar(255),
10
+ geom point not null
11
+ ) ENGINE=MyISAM"
12
+ execute "create spatial index index_point_models_on_geom on point_models (geom)"
13
+ execute "create index index_point_models_on_extra on point_models (extra, more_extra)"
14
+
15
+ execute "drop table if exists line_string_models"
16
+ execute "create table line_string_models
17
+ (
18
+ id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
19
+ extra varchar(255),
20
+ geom linestring
21
+ ) ENGINE=MyISAM"
22
+
23
+ execute "drop table if exists polygon_models"
24
+ execute "create table polygon_models
25
+ (
26
+ id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
27
+ extra varchar(255),
28
+ geom polygon
29
+ ) ENGINE=MyISAM"
30
+
31
+ execute "drop table if exists multi_point_models"
32
+ execute "create table multi_point_models
33
+ (
34
+ id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
35
+ extra varchar(255),
36
+ geom multipoint
37
+ ) ENGINE=MyISAM"
38
+
39
+ execute "drop table if exists multi_line_string_models"
40
+ execute "create table multi_line_string_models
41
+ (
42
+ id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
43
+ extra varchar(255),
44
+ geom multilinestring
45
+ ) ENGINE=MyISAM"
46
+
47
+ execute "drop table if exists multi_polygon_models"
48
+ execute "create table multi_polygon_models
49
+ (
50
+ id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
51
+ extra varchar(255),
52
+ geom multipolygon
53
+ ) ENGINE=MyISAM"
54
+
55
+ execute "drop table if exists geometry_collection_models"
56
+ execute "create table geometry_collection_models
57
+ (
58
+ id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
59
+ extra varchar(255),
60
+ geom geometrycollection
61
+ ) ENGINE=MyISAM"
62
+
63
+ execute "drop table if exists geometry_models"
64
+ execute "create table geometry_models
65
+ (
66
+ id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
67
+ extra varchar(255),
68
+ geom geometry
69
+ ) ENGINE=MyISAM"
70
+ end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require 'spec_helper'
2
2
  require 'spatial_adapter/mysql'
3
3
  require 'db/mysql_raw'
4
4
  require 'models/common'
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require 'spec_helper'
2
2
  require 'spatial_adapter/mysql'
3
3
 
4
4
  class MigratedGeometryModel < ActiveRecord::Base
@@ -1,4 +1,5 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require 'spec_helper'
2
+ require 'shared_examples'
2
3
  require 'spatial_adapter/mysql'
3
4
  require 'db/mysql_raw'
4
5
  require 'models/common'
@@ -59,46 +60,6 @@ describe "Spatially-enabled Models" do
59
60
  end
60
61
  end
61
62
 
62
- describe "finding records" do
63
- it 'should retrieve Point objects' do
64
- model = PointModel.create(:extra => 'test', :geom => GeometryFactory.point)
65
- PointModel.find(model.id).geom.should == GeometryFactory.point
66
- end
67
-
68
- it 'should retrieve LineString objects' do
69
- model = LineStringModel.create(:extra => 'test', :geom => GeometryFactory.line_string)
70
- LineStringModel.find(model.id).geom.should == GeometryFactory.line_string
71
- end
72
-
73
- it 'should retrieve Polygon objects' do
74
- model = PolygonModel.create(:extra => 'test', :geom => GeometryFactory.polygon)
75
- PolygonModel.find(model.id).geom.should == GeometryFactory.polygon
76
- end
77
-
78
- it 'should retrieve MultiPoint objects' do
79
- model = MultiPointModel.create(:extra => 'test', :geom => GeometryFactory.multi_point)
80
- MultiPointModel.find(model.id).geom.should == GeometryFactory.multi_point
81
- end
82
-
83
- it 'should retrieve MultiLineString objects' do
84
- model = MultiLineStringModel.create(:extra => 'test', :geom => GeometryFactory.multi_line_string)
85
- MultiLineStringModel.find(model.id).geom.should == GeometryFactory.multi_line_string
86
- end
87
-
88
- it 'should retrieve MultiPolygon objects' do
89
- model = MultiPolygonModel.create(:extra => 'test', :geom => GeometryFactory.multi_polygon)
90
- MultiPolygonModel.find(model.id).geom.should == GeometryFactory.multi_polygon
91
- end
92
-
93
- it 'should retrieve GeometryCollection objects' do
94
- model = GeometryCollectionModel.create(:extra => 'test', :geom => GeometryFactory.geometry_collection)
95
- GeometryCollectionModel.find(model.id).geom.should == GeometryFactory.geometry_collection
96
- end
97
-
98
- it 'should retrieve Geometry objects' do
99
- model = GeometryModel.create(:extra => 'test', :geom => GeometryFactory.point)
100
- GeometryModel.find(model.id).geom.should == GeometryFactory.point
101
- end
102
- end
63
+ include CommonModelActions
103
64
  end
104
65
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require 'spec_helper'
2
2
  require 'spatial_adapter/mysql'
3
3
 
4
4
  describe "Spatially-enabled Schema Dumps" do
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+ require 'spatial_adapter/mysql2'
3
+ require 'db/mysql2_raw'
4
+ require 'models/common'
5
+
6
+ describe "Modified Mysql2Adapter" do
7
+ before :each do
8
+ mysql2_connection
9
+ @connection = ActiveRecord::Base.connection
10
+ end
11
+
12
+ describe '#supports_geographic?' do
13
+ it "should be false" do
14
+ @connection.supports_geographic?.should == false
15
+ end
16
+ end
17
+
18
+ describe "#columns" do
19
+ describe "type" do
20
+ it "should be SpatialMysql2Column if column is a spatial data type" do
21
+ PointModel.columns.select{|c| c.name == 'geom'}.first.should be_a(ActiveRecord::ConnectionAdapters::SpatialMysql2Column)
22
+ end
23
+
24
+ it "should be Mysql2Column if column is not a spatial data type" do
25
+ PointModel.columns.select{|c| c.name == 'extra'}.first.should be_a(ActiveRecord::ConnectionAdapters::Mysql2Column)
26
+ end
27
+ end
28
+
29
+ describe "@geometry_type" do
30
+ it "should be :point for columns restricted to POINT types" do
31
+ PointModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :point
32
+ end
33
+
34
+ it "should be :line_string for columns restricted to LINESTRING types" do
35
+ LineStringModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :line_string
36
+ end
37
+
38
+ it "should be :polygon for columns restricted to POLYGON types" do
39
+ PolygonModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :polygon
40
+ end
41
+
42
+ it "should be :multi_point for columns restricted to MULTIPOINT types" do
43
+ MultiPointModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :multi_point
44
+ end
45
+
46
+ it "should be :multi_line_string for columns restricted to MULTILINESTRING types" do
47
+ MultiLineStringModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :multi_line_string
48
+ end
49
+
50
+ it "should be :multi_polygon for columns restricted to MULTIPOLYGON types" do
51
+ MultiPolygonModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :multi_polygon
52
+ end
53
+
54
+ it "should be :geometry_collection for columns restricted to GEOMETRYCOLLECTION types" do
55
+ GeometryCollectionModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :geometry_collection
56
+ end
57
+
58
+ it "should be :geometry for columns not restricted to a type" do
59
+ GeometryModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :geometry
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "#indexes" do
65
+ before :each do
66
+ @indexes = @connection.indexes('point_models')
67
+ end
68
+
69
+ it "should return an IndexDefinition for each index on the table" do
70
+ @indexes.should have(2).items
71
+ @indexes.each do |i|
72
+ i.should be_a(ActiveRecord::ConnectionAdapters::IndexDefinition)
73
+ end
74
+ end
75
+
76
+ it "should indicate the correct columns in the index" do
77
+ @indexes.select{|i| i.name == 'index_point_models_on_geom'}.first.columns.should == ['geom']
78
+ @indexes.select{|i| i.name == 'index_point_models_on_extra'}.first.columns.should == ['extra', 'more_extra']
79
+ end
80
+
81
+ it "should be marked as spatial if a spatial index" do
82
+ @indexes.select{|i| i.columns.include?('geom')}.first.spatial.should == true
83
+ end
84
+
85
+ it "should not be marked as spatial if not a spatial index" do
86
+ @indexes.select{|i| i.columns.include?('extra')}.first.spatial.should == false
87
+ end
88
+ end
89
+
90
+ describe "#add_index" do
91
+ after :each do
92
+ @connection.should_receive(:execute).with(any_args())
93
+ @connection.remove_index('geometry_models', 'geom')
94
+ end
95
+
96
+ it "should create a spatial index given :spatial => true" do
97
+ @connection.should_receive(:execute).with(/create spatial index/i)
98
+ @connection.add_index('geometry_models', 'geom', :spatial => true)
99
+ end
100
+
101
+ it "should not create a spatial index unless specified" do
102
+ @connection.should_not_receive(:execute).with(/create spatial index/i)
103
+ @connection.add_index('geometry_models', 'extra')
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+ require 'spatial_adapter/mysql2'
3
+
4
+ class MigratedGeometryModel < ActiveRecord::Base
5
+ end
6
+
7
+ describe "Spatially-enabled Migrations" do
8
+ before :each do
9
+ mysql2_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.geometry_type.should == type
30
+ geom_column.type.should == :string
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "adding columns" do
36
+ before :each do
37
+ ActiveRecord::Schema.define do
38
+ create_table :migrated_geometry_models, :force => true do |t|
39
+ t.integer :extra
40
+ end
41
+ end
42
+ end
43
+
44
+ after :each do
45
+ @connection.drop_table "migrated_geometry_models"
46
+ end
47
+
48
+ SpatialAdapter.geometry_data_types.keys.each do |type|
49
+ it "should add #{type.to_s} columns" do
50
+ ActiveRecord::Schema.define do
51
+ add_column :migrated_geometry_models, :geom, type
52
+ end
53
+
54
+ geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
55
+ geom_column.should be_a(SpatialAdapter::SpatialColumn)
56
+ geom_column.geometry_type.should == type
57
+ geom_column.type.should == :string
58
+ geom_column.with_z.should == false
59
+ geom_column.with_m.should == false
60
+ geom_column.srid.should == -1
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+ require 'shared_examples'
3
+ require 'spatial_adapter/mysql2'
4
+ require 'db/mysql2_raw'
5
+ require 'models/common'
6
+
7
+ describe "Spatially-enabled Models" do
8
+ before :each do
9
+ mysql2_connection
10
+ @connection = ActiveRecord::Base.connection
11
+ end
12
+
13
+ describe "inserting records" do
14
+ it 'should save Point objects' do
15
+ model = PointModel.new(:extra => 'test', :geom => GeometryFactory.point)
16
+ @connection.should_receive(:insert_sql).with(Regexp.new(GeometryFactory.point.as_hex_wkb), anything(), anything(), anything(), anything())
17
+ model.save.should == true
18
+ end
19
+
20
+ it 'should save LineString objects' do
21
+ model = LineStringModel.new(:extra => 'test', :geom => GeometryFactory.line_string)
22
+ @connection.should_receive(:insert_sql).with(Regexp.new(GeometryFactory.line_string.as_hex_wkb), anything(), anything(), anything(), anything())
23
+ model.save.should == true
24
+ end
25
+
26
+ it 'should save Polygon objects' do
27
+ model = PolygonModel.new(:extra => 'test', :geom => GeometryFactory.polygon)
28
+ @connection.should_receive(:insert_sql).with(Regexp.new(GeometryFactory.polygon.as_hex_wkb), anything(), anything(), anything(), anything())
29
+ model.save.should == true
30
+ end
31
+
32
+ it 'should save MultiPoint objects' do
33
+ model = MultiPointModel.new(:extra => 'test', :geom => GeometryFactory.multi_point)
34
+ @connection.should_receive(:insert_sql).with(Regexp.new(GeometryFactory.multi_point.as_hex_wkb), anything(), anything(), anything(), anything())
35
+ model.save.should == true
36
+ end
37
+
38
+ it 'should save MultiLineString objects' do
39
+ model = MultiLineStringModel.new(:extra => 'test', :geom => GeometryFactory.multi_line_string)
40
+ @connection.should_receive(:insert_sql).with(Regexp.new(GeometryFactory.multi_line_string.as_hex_wkb), anything(), anything(), anything(), anything())
41
+ model.save.should == true
42
+ end
43
+
44
+ it 'should save MultiPolygon objects' do
45
+ model = MultiPolygonModel.new(:extra => 'test', :geom => GeometryFactory.multi_polygon)
46
+ @connection.should_receive(:insert_sql).with(Regexp.new(GeometryFactory.multi_polygon.as_hex_wkb), anything(), anything(), anything(), anything())
47
+ model.save.should == true
48
+ end
49
+
50
+ it 'should save GeometryCollection objects' do
51
+ model = GeometryCollectionModel.new(:extra => 'test', :geom => GeometryFactory.geometry_collection)
52
+ @connection.should_receive(:insert_sql).with(Regexp.new(GeometryFactory.geometry_collection.as_hex_wkb), anything(), anything(), anything(), anything())
53
+ model.save.should == true
54
+ end
55
+
56
+ it 'should save Geometry objects' do
57
+ model = GeometryModel.new(:extra => 'test', :geom => GeometryFactory.point)
58
+ @connection.should_receive(:insert_sql).with(Regexp.new(GeometryFactory.point.as_hex_wkb), anything(), anything(), anything(), anything())
59
+ model.save.should == true
60
+ end
61
+ end
62
+
63
+ include CommonModelActions
64
+ end
65
+
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+ require 'spatial_adapter/mysql2'
3
+
4
+ describe "Spatially-enabled Schema Dumps" do
5
+ before :all do
6
+ mysql2_connection
7
+ @connection = ActiveRecord::Base.connection
8
+
9
+ # Create a new table
10
+ ActiveRecord::Schema.define do
11
+ create_table :migrated_geometry_models, :options=> "ENGINE=MyISAM", :force => true do |t|
12
+ t.integer :extra
13
+ t.point :geom, :null => false
14
+ end
15
+ add_index :migrated_geometry_models, :geom, :spatial => true, :name => 'test_spatial_index'
16
+ end
17
+
18
+ File.open('schema.rb', "w") do |file|
19
+ ActiveRecord::SchemaDumper.dump(@connection, file)
20
+ end
21
+
22
+ # Drop the original table
23
+ @connection.drop_table "migrated_geometry_models"
24
+
25
+ # Load the dumped schema
26
+ load('schema.rb')
27
+ end
28
+
29
+ after :all do
30
+ # delete the schema file
31
+ File.delete('schema.rb')
32
+
33
+ # Drop the new table
34
+ @connection.drop_table "migrated_geometry_models"
35
+ end
36
+
37
+ it "should preserve spatial attributes of tables" do
38
+ columns = @connection.columns("migrated_geometry_models")
39
+
40
+ columns.should have(3).items
41
+ geom_column = columns.select{|c| c.name == 'geom'}.first
42
+ geom_column.should be_a(SpatialAdapter::SpatialColumn)
43
+ geom_column.geometry_type.should == :point
44
+ geom_column.type.should == :string
45
+ end
46
+
47
+ it "should preserve spatial indexes" do
48
+ indexes = @connection.indexes("migrated_geometry_models")
49
+
50
+ indexes.should have(1).item
51
+
52
+ indexes.first.name.should == 'test_spatial_index'
53
+ indexes.first.columns.should == ["geom"]
54
+ indexes.first.spatial.should == true
55
+ end
56
+ end
@@ -1,5 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
1
+ require 'spec_helper'
3
2
  require 'spatial_adapter/postgresql'
4
3
  require 'db/postgis_raw'
5
4
  require 'models/common'
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require 'spec_helper'
2
2
  require 'spatial_adapter/postgresql'
3
3
 
4
4
  class MigratedGeometryModel < ActiveRecord::Base
@@ -1,4 +1,5 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require 'spec_helper'
2
+ require 'shared_examples'
2
3
  require 'spatial_adapter/postgresql'
3
4
  require 'db/postgis_raw'
4
5
  require 'models/common'
@@ -143,47 +144,9 @@ describe "Spatially-enabled Models" do
143
144
  end
144
145
  end
145
146
 
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
147
+ include CommonModelActions
186
148
 
149
+ describe "finding records" do
187
150
  it 'should retrieve 3D Point (with Z coord) objects' do
188
151
  model = PointzModel.create(:extra => 'test', :geom => GeometryFactory.pointz)
189
152
  PointzModel.find(model.id).geom.should == GeometryFactory.pointz
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require 'spec_helper'
2
2
  require 'spatial_adapter/postgresql'
3
3
 
4
4
  describe "Spatially-enabled Schema Dumps" do
@@ -0,0 +1,43 @@
1
+ share_as :CommonModelActions do
2
+ describe 'finding records' do
3
+ it 'should retrieve Point objects' do
4
+ model = PointModel.create(:extra => 'test', :geom => GeometryFactory.point)
5
+ PointModel.find(model.id).geom.should == GeometryFactory.point
6
+ end
7
+
8
+ it 'should retrieve LineString objects' do
9
+ model = LineStringModel.create(:extra => 'test', :geom => GeometryFactory.line_string)
10
+ LineStringModel.find(model.id).geom.should == GeometryFactory.line_string
11
+ end
12
+
13
+ it 'should retrieve Polygon objects' do
14
+ model = PolygonModel.create(:extra => 'test', :geom => GeometryFactory.polygon)
15
+ PolygonModel.find(model.id).geom.should == GeometryFactory.polygon
16
+ end
17
+
18
+ it 'should retrieve MultiPoint objects' do
19
+ model = MultiPointModel.create(:extra => 'test', :geom => GeometryFactory.multi_point)
20
+ MultiPointModel.find(model.id).geom.should == GeometryFactory.multi_point
21
+ end
22
+
23
+ it 'should retrieve MultiLineString objects' do
24
+ model = MultiLineStringModel.create(:extra => 'test', :geom => GeometryFactory.multi_line_string)
25
+ MultiLineStringModel.find(model.id).geom.should == GeometryFactory.multi_line_string
26
+ end
27
+
28
+ it 'should retrieve MultiPolygon objects' do
29
+ model = MultiPolygonModel.create(:extra => 'test', :geom => GeometryFactory.multi_polygon)
30
+ MultiPolygonModel.find(model.id).geom.should == GeometryFactory.multi_polygon
31
+ end
32
+
33
+ it 'should retrieve GeometryCollection objects' do
34
+ model = GeometryCollectionModel.create(:extra => 'test', :geom => GeometryFactory.geometry_collection)
35
+ GeometryCollectionModel.find(model.id).geom.should == GeometryFactory.geometry_collection
36
+ end
37
+
38
+ it 'should retrieve Geometry objects' do
39
+ model = GeometryModel.create(:extra => 'test', :geom => GeometryFactory.point)
40
+ GeometryModel.find(model.id).geom.should == GeometryFactory.point
41
+ end
42
+ end
43
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'spec'
3
3
  require 'geo_ruby'
4
- gem 'activerecord', '=2.3.5'
5
- #gem 'activerecord', '=3.0.0.beta3'
4
+ gem 'activerecord', '=3.0.3'
6
5
  require 'active_record'
7
6
 
8
7
  $:.unshift((File.join(File.dirname(__FILE__), '..', 'lib')))
@@ -34,6 +33,18 @@ def mysql_connection
34
33
  ActiveRecord::Migration.verbose = false
35
34
  end
36
35
 
36
+ def mysql2_connection
37
+ ActiveRecord::Base.establish_connection(
38
+ :adapter => 'mysql2',
39
+ :database => 'spatial_adapter',
40
+ :username => 'root',
41
+ :host => 'localhost'
42
+ )
43
+
44
+ # Don't output migration logging
45
+ ActiveRecord::Migration.verbose = false
46
+ end
47
+
37
48
  class GeometryFactory
38
49
  class << self
39
50
  def point
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 1
8
7
  - 2
9
- version: 1.1.2
8
+ - 0
9
+ version: 1.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Pete Deffendol
@@ -15,13 +15,14 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-04-29 00:00:00 -06:00
18
+ date: 2011-01-08 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: activerecord
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
@@ -36,6 +37,7 @@ dependencies:
36
37
  name: GeoRuby
37
38
  prerelease: false
38
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
39
41
  requirements:
40
42
  - - ">="
41
43
  - !ruby/object:Gem::Version
@@ -65,19 +67,40 @@ files:
65
67
  - lib/spatial_adapter/common/spatial_column.rb
66
68
  - lib/spatial_adapter/common/table_definition.rb
67
69
  - lib/spatial_adapter/mysql.rb
70
+ - lib/spatial_adapter/mysql2.rb
68
71
  - lib/spatial_adapter/postgresql.rb
69
72
  - lib/spatial_adapter/railtie.rb
70
73
  - rails/init.rb
74
+ - spec/README.txt
75
+ - spec/db/mysql2_raw.rb
76
+ - spec/db/mysql_raw.rb
77
+ - spec/db/postgis_raw.rb
78
+ - spec/models/common.rb
79
+ - spec/mysql/connection_adapter_spec.rb
80
+ - spec/mysql/migration_spec.rb
81
+ - spec/mysql/models_spec.rb
82
+ - spec/mysql/schema_dumper_spec.rb
83
+ - spec/mysql2/connection_adapter_spec.rb
84
+ - spec/mysql2/migration_spec.rb
85
+ - spec/mysql2/models_spec.rb
86
+ - spec/mysql2/schema_dumper_spec.rb
87
+ - spec/postgresql/connection_adapter_spec.rb
88
+ - spec/postgresql/migration_spec.rb
89
+ - spec/postgresql/models_spec.rb
90
+ - spec/postgresql/schema_dumper_spec.rb
91
+ - spec/shared_examples.rb
92
+ - spec/spec_helper.rb
71
93
  has_rdoc: true
72
94
  homepage: http://github.com/fragility/spatial_adapter
73
95
  licenses: []
74
96
 
75
97
  post_install_message:
76
- rdoc_options:
77
- - --charset=UTF-8
98
+ rdoc_options: []
99
+
78
100
  require_paths:
79
101
  - lib
80
102
  required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
81
104
  requirements:
82
105
  - - ">="
83
106
  - !ruby/object:Gem::Version
@@ -85,6 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
108
  - 0
86
109
  version: "0"
87
110
  required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
88
112
  requirements:
89
113
  - - ">="
90
114
  - !ruby/object:Gem::Version
@@ -94,11 +118,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
118
  requirements: []
95
119
 
96
120
  rubyforge_project:
97
- rubygems_version: 1.3.6
121
+ rubygems_version: 1.3.7
98
122
  signing_key:
99
123
  specification_version: 3
100
124
  summary: Spatial Adapter for ActiveRecord
101
125
  test_files:
126
+ - spec/README.txt
127
+ - spec/db/mysql2_raw.rb
102
128
  - spec/db/mysql_raw.rb
103
129
  - spec/db/postgis_raw.rb
104
130
  - spec/models/common.rb
@@ -106,9 +132,13 @@ test_files:
106
132
  - spec/mysql/migration_spec.rb
107
133
  - spec/mysql/models_spec.rb
108
134
  - spec/mysql/schema_dumper_spec.rb
135
+ - spec/mysql2/connection_adapter_spec.rb
136
+ - spec/mysql2/migration_spec.rb
137
+ - spec/mysql2/models_spec.rb
138
+ - spec/mysql2/schema_dumper_spec.rb
109
139
  - spec/postgresql/connection_adapter_spec.rb
110
140
  - spec/postgresql/migration_spec.rb
111
141
  - spec/postgresql/models_spec.rb
112
142
  - spec/postgresql/schema_dumper_spec.rb
143
+ - spec/shared_examples.rb
113
144
  - spec/spec_helper.rb
114
- - spec/README.txt