spatial_adapter 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
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
metadata CHANGED
@@ -1,144 +1,191 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: spatial_adapter
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 2
8
- - 0
9
- version: 1.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Pete Deffendol
13
9
  - Guilhem Vellut
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
-
18
- date: 2011-01-08 00:00:00 -07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: activerecord
13
+ date: 2011-10-04 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: &70168907686900 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *70168907686900
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &70168907686360 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *70168907686360
37
+ - !ruby/object:Gem::Dependency
38
+ name: pg
39
+ requirement: &70168907685840 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *70168907685840
48
+ - !ruby/object:Gem::Dependency
49
+ name: mysql
50
+ requirement: &70168907685200 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *70168907685200
59
+ - !ruby/object:Gem::Dependency
60
+ name: mysql2
61
+ requirement: &70168907684660 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - <=
65
+ - !ruby/object:Gem::Version
66
+ version: 0.2.13
67
+ type: :development
23
68
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
69
+ version_requirements: *70168907684660
70
+ - !ruby/object:Gem::Dependency
71
+ name: activerecord
72
+ requirement: &70168907684080 !ruby/object:Gem::Requirement
25
73
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- segments:
30
- - 2
31
- - 2
32
- - 2
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
33
77
  version: 2.2.2
78
+ - - <
79
+ - !ruby/object:Gem::Version
80
+ version: 3.1.0
34
81
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: GeoRuby
38
82
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
83
+ version_requirements: *70168907684080
84
+ - !ruby/object:Gem::Dependency
85
+ name: GeoRuby
86
+ requirement: &70168907683140 !ruby/object:Gem::Requirement
40
87
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- segments:
45
- - 1
46
- - 3
47
- - 0
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
48
91
  version: 1.3.0
49
92
  type: :runtime
50
- version_requirements: *id002
51
- description: Provides enhancements to ActiveRecord to handle spatial datatypes in PostgreSQL and MySQL.
93
+ prerelease: false
94
+ version_requirements: *70168907683140
95
+ description: ! "Provides enhancements to ActiveRecord to handle spatial\n datatypes
96
+ in PostgreSQL and MySQL."
52
97
  email: pete@fragility.us
53
98
  executables: []
54
-
55
99
  extensions: []
56
-
57
- extra_rdoc_files:
100
+ extra_rdoc_files:
58
101
  - README.rdoc
59
- files:
102
+ - MIT-LICENSE
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
60
106
  - MIT-LICENSE
61
107
  - README.rdoc
62
- - VERSION
108
+ - Rakefile
109
+ - init.rb
63
110
  - lib/spatial_adapter.rb
111
+ - lib/spatial_adapter/base/mysql.rb
112
+ - lib/spatial_adapter/base/mysql/adapter.rb
113
+ - lib/spatial_adapter/base/mysql/spatial_column.rb
114
+ - lib/spatial_adapter/common.rb
64
115
  - lib/spatial_adapter/common/raw_geom_info.rb
65
116
  - lib/spatial_adapter/common/schema_definitions.rb
66
117
  - lib/spatial_adapter/common/schema_dumper.rb
67
118
  - lib/spatial_adapter/common/spatial_column.rb
68
119
  - lib/spatial_adapter/common/table_definition.rb
120
+ - lib/spatial_adapter/jdbcmysql.rb
69
121
  - lib/spatial_adapter/mysql.rb
70
122
  - lib/spatial_adapter/mysql2.rb
71
123
  - lib/spatial_adapter/postgresql.rb
72
124
  - lib/spatial_adapter/railtie.rb
125
+ - lib/spatial_adapter/version.rb
73
126
  - rails/init.rb
74
- - spec/README.txt
127
+ - spatial_adapter.gemspec
128
+ - spec/db/jdbcmysql_raw.rb
75
129
  - spec/db/mysql2_raw.rb
76
130
  - spec/db/mysql_raw.rb
77
131
  - spec/db/postgis_raw.rb
132
+ - spec/jdbcmysql_spec.rb
78
133
  - 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
134
+ - spec/mysql2_spec.rb
135
+ - spec/mysql_spec.rb
87
136
  - spec/postgresql/connection_adapter_spec.rb
88
137
  - spec/postgresql/migration_spec.rb
89
138
  - spec/postgresql/models_spec.rb
90
139
  - spec/postgresql/schema_dumper_spec.rb
91
- - spec/shared_examples.rb
140
+ - spec/postgresql_spec.rb
141
+ - spec/shared/common_model_actions_spec.rb
142
+ - spec/shared/mysql_connection_adapter_spec.rb
143
+ - spec/shared/mysql_migration_spec.rb
144
+ - spec/shared/mysql_models_spec.rb
145
+ - spec/shared/mysql_schema_dumper_spec.rb
92
146
  - spec/spec_helper.rb
93
- has_rdoc: true
94
147
  homepage: http://github.com/fragility/spatial_adapter
95
148
  licenses: []
96
-
97
149
  post_install_message:
98
- rdoc_options: []
99
-
100
- require_paths:
150
+ rdoc_options:
151
+ - --charset=UTF-8
152
+ require_paths:
101
153
  - lib
102
- required_ruby_version: !ruby/object:Gem::Requirement
154
+ required_ruby_version: !ruby/object:Gem::Requirement
103
155
  none: false
104
- requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- segments:
108
- - 0
109
- version: "0"
110
- required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
161
  none: false
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- segments:
116
- - 0
117
- version: "0"
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
118
166
  requirements: []
119
-
120
167
  rubyforge_project:
121
- rubygems_version: 1.3.7
168
+ rubygems_version: 1.8.10
122
169
  signing_key:
123
170
  specification_version: 3
124
- summary: Spatial Adapter for ActiveRecord
125
- test_files:
126
- - spec/README.txt
171
+ summary: spatial_adapter-1.3.0
172
+ test_files:
173
+ - spec/db/jdbcmysql_raw.rb
127
174
  - spec/db/mysql2_raw.rb
128
175
  - spec/db/mysql_raw.rb
129
176
  - spec/db/postgis_raw.rb
177
+ - spec/jdbcmysql_spec.rb
130
178
  - spec/models/common.rb
131
- - spec/mysql/connection_adapter_spec.rb
132
- - spec/mysql/migration_spec.rb
133
- - spec/mysql/models_spec.rb
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
179
+ - spec/mysql2_spec.rb
180
+ - spec/mysql_spec.rb
139
181
  - spec/postgresql/connection_adapter_spec.rb
140
182
  - spec/postgresql/migration_spec.rb
141
183
  - spec/postgresql/models_spec.rb
142
184
  - spec/postgresql/schema_dumper_spec.rb
143
- - spec/shared_examples.rb
185
+ - spec/postgresql_spec.rb
186
+ - spec/shared/common_model_actions_spec.rb
187
+ - spec/shared/mysql_connection_adapter_spec.rb
188
+ - spec/shared/mysql_migration_spec.rb
189
+ - spec/shared/mysql_models_spec.rb
190
+ - spec/shared/mysql_schema_dumper_spec.rb
144
191
  - spec/spec_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.2.0
data/spec/README.txt DELETED
@@ -1,22 +0,0 @@
1
- = Running Tests
2
-
3
- You will need to set up empty databases for each adapter you want to test.
4
-
5
- == PostgreSQL
6
-
7
- Create an empty database "spatial_adapter" and ensure that the PostGIS extensions are loaded.
8
-
9
- run "rake spec:postgresql" to run the specs
10
-
11
- == MySQL
12
-
13
- Create an empty database "spatial_adapter" - the spatial extensions are already available.
14
-
15
- run "rake spec:mysql" to run the specs
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
-
@@ -1,106 +0,0 @@
1
- require 'spec_helper'
2
- require 'spatial_adapter/mysql'
3
- require 'db/mysql_raw'
4
- require 'models/common'
5
-
6
- describe "Modified MysqlAdapter" do
7
- before :each do
8
- mysql_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 SpatialMysqlColumn if column is a spatial data type" do
21
- PointModel.columns.select{|c| c.name == 'geom'}.first.should be_a(ActiveRecord::ConnectionAdapters::SpatialMysqlColumn)
22
- end
23
-
24
- it "should be SpatialMysqlColumn if column is not a spatial data type" do
25
- PointModel.columns.select{|c| c.name == 'extra'}.first.should be_a(ActiveRecord::ConnectionAdapters::MysqlColumn)
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
@@ -1,65 +0,0 @@
1
- require 'spec_helper'
2
- require 'shared_examples'
3
- require 'spatial_adapter/mysql'
4
- require 'db/mysql_raw'
5
- require 'models/common'
6
-
7
- describe "Spatially-enabled Models" do
8
- before :each do
9
- mysql_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
-
@@ -1,106 +0,0 @@
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
@@ -1,64 +0,0 @@
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