beh_spatial_adapter 1.1.2

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.
@@ -0,0 +1,222 @@
1
+ require 'spec_helper'
2
+ require 'shared_examples'
3
+ require 'spatial_adapter/postgresql'
4
+ require 'db/postgis_raw'
5
+ require 'models/common'
6
+
7
+ describe "Spatially-enabled Models" do
8
+ before :each do
9
+ postgis_connection
10
+ @connection = ActiveRecord::Base.connection
11
+ GeometryFactory.default_srid = @connection.default_srid
12
+ end
13
+
14
+ describe "inserting records" do
15
+ it 'should save Point objects' do
16
+ model = PointModel.new(:extra => 'test', :geom => GeometryFactory.point)
17
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point.as_hex_ewkb))
18
+ model.save.should == true
19
+ end
20
+
21
+ it 'should save LineString objects' do
22
+ model = LineStringModel.new(:extra => 'test', :geom => GeometryFactory.line_string)
23
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.line_string.as_hex_ewkb))
24
+ model.save.should == true
25
+ end
26
+
27
+ it 'should save Polygon objects' do
28
+ model = PolygonModel.new(:extra => 'test', :geom => GeometryFactory.polygon)
29
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.polygon.as_hex_ewkb))
30
+ model.save.should == true
31
+ end
32
+
33
+ it 'should save MultiPoint objects' do
34
+ model = MultiPointModel.new(:extra => 'test', :geom => GeometryFactory.multi_point)
35
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_point.as_hex_ewkb))
36
+ model.save.should == true
37
+ end
38
+
39
+ it 'should save MultiLineString objects' do
40
+ model = MultiLineStringModel.new(:extra => 'test', :geom => GeometryFactory.multi_line_string)
41
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_line_string.as_hex_ewkb))
42
+ model.save.should == true
43
+ end
44
+
45
+ it 'should save MultiPolygon objects' do
46
+ model = MultiPolygonModel.new(:extra => 'test', :geom => GeometryFactory.multi_polygon)
47
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_polygon.as_hex_ewkb))
48
+ model.save.should == true
49
+ end
50
+
51
+ it 'should save GeometryCollection objects' do
52
+ model = GeometryCollectionModel.new(:extra => 'test', :geom => GeometryFactory.geometry_collection)
53
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.geometry_collection.as_hex_ewkb))
54
+ model.save.should == true
55
+ end
56
+
57
+ it 'should save Geometry objects' do
58
+ model = GeometryModel.new(:extra => 'test', :geom => GeometryFactory.point)
59
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point.as_hex_ewkb))
60
+ model.save.should == true
61
+ end
62
+
63
+ it 'should save 3D Point (with Z coord) objects' do
64
+ model = PointzModel.new(:extra => 'test', :geom => GeometryFactory.pointz)
65
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.pointz.as_hex_ewkb))
66
+ model.save.should == true
67
+ end
68
+
69
+ it 'should save 3D Point (with M coord) objects' do
70
+ model = PointmModel.new(:extra => 'test', :geom => GeometryFactory.pointm)
71
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.pointm.as_hex_ewkb))
72
+ model.save.should == true
73
+ end
74
+
75
+ it 'should save 4D Point objects' do
76
+ model = Point4Model.new(:extra => 'test', :geom => GeometryFactory.point4)
77
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point4.as_hex_ewkb))
78
+ model.save.should == true
79
+ end
80
+
81
+ it 'should save Point geography objects' do
82
+ model = GeographyPointModel.new(:extra => 'test', :geom => GeometryFactory.point)
83
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point.as_hex_ewkb))
84
+ model.save.should == true
85
+ end
86
+
87
+ it 'should save LineString geography objects' do
88
+ model = GeographyLineStringModel.new(:extra => 'test', :geom => GeometryFactory.line_string)
89
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.line_string.as_hex_ewkb))
90
+ model.save.should == true
91
+ end
92
+
93
+ it 'should save Polygon geography objects' do
94
+ model = GeographyPolygonModel.new(:extra => 'test', :geom => GeometryFactory.polygon)
95
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.polygon.as_hex_ewkb))
96
+ model.save.should == true
97
+ end
98
+
99
+ it 'should save MultiPoint geography objects' do
100
+ model = GeographyMultiPointModel.new(:extra => 'test', :geom => GeometryFactory.multi_point)
101
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_point.as_hex_ewkb))
102
+ model.save.should == true
103
+ end
104
+
105
+ it 'should save MultiLineString geography objects' do
106
+ model = GeographyMultiLineStringModel.new(:extra => 'test', :geom => GeometryFactory.multi_line_string)
107
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_line_string.as_hex_ewkb))
108
+ model.save.should == true
109
+ end
110
+
111
+ it 'should save MultiPolygon geography objects' do
112
+ model = GeographyMultiPolygonModel.new(:extra => 'test', :geom => GeometryFactory.multi_polygon)
113
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.multi_polygon.as_hex_ewkb))
114
+ model.save.should == true
115
+ end
116
+
117
+ it 'should save GeometryCollection geography objects' do
118
+ model = GeographyGeometryCollectionModel.new(:extra => 'test', :geom => GeometryFactory.geometry_collection)
119
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.geometry_collection.as_hex_ewkb))
120
+ model.save.should == true
121
+ end
122
+
123
+ it 'should save Geography objects' do
124
+ model = GeographyModel.new(:extra => 'test', :geom => GeometryFactory.point)
125
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point.as_hex_ewkb))
126
+ model.save.should == true
127
+ end
128
+
129
+ it 'should save 3D Point (with Z coord) geography objects' do
130
+ model = GeographyPointzModel.new(:extra => 'test', :geom => GeometryFactory.pointz)
131
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.pointz.as_hex_ewkb))
132
+ model.save.should == true
133
+ end
134
+
135
+ it 'should save 3D Point (with M coord) geography objects' do
136
+ model = GeographyPointmModel.new(:extra => 'test', :geom => GeometryFactory.pointm)
137
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.pointm.as_hex_ewkb))
138
+ model.save.should == true
139
+ end
140
+
141
+ it 'should save 4D Point geography objects' do
142
+ model = GeographyPoint4Model.new(:extra => 'test', :geom => GeometryFactory.point4)
143
+ @connection.should_receive(:select_value).with(Regexp.new(GeometryFactory.point4.as_hex_ewkb))
144
+ model.save.should == true
145
+ end
146
+ end
147
+
148
+ include CommonModelActions
149
+
150
+ describe "finding records" do
151
+ it 'should retrieve 3D Point (with Z coord) objects' do
152
+ model = PointzModel.create(:extra => 'test', :geom => GeometryFactory.pointz)
153
+ PointzModel.find(model.id).geom.should == GeometryFactory.pointz
154
+ end
155
+
156
+ it 'should retrieve 3D Point (with M coord) objects' do
157
+ model = GeographyPointmModel.create(:extra => 'test', :geom => GeometryFactory.pointm)
158
+ GeographyPointmModel.find(model.id).geom.should == GeometryFactory.pointm
159
+ end
160
+
161
+ it 'should retrieve 4D Point objects' do
162
+ model = GeographyPoint4Model.create(:extra => 'test', :geom => GeometryFactory.point4)
163
+ GeographyPoint4Model.find(model.id).geom.should == GeometryFactory.point4
164
+ end
165
+
166
+ it 'should retrieve Point geography objects' do
167
+ model = GeographyPointModel.create(:extra => 'test', :geom => GeometryFactory.point)
168
+ GeographyPointModel.find(model.id).geom.should == GeometryFactory.point
169
+ end
170
+
171
+ it 'should retrieve LineString geography objects' do
172
+ model = GeographyLineStringModel.create(:extra => 'test', :geom => GeometryFactory.line_string)
173
+ GeographyLineStringModel.find(model.id).geom.should == GeometryFactory.line_string
174
+ end
175
+
176
+ it 'should retrieve Polygon geography objects' do
177
+ model = GeographyPolygonModel.create(:extra => 'test', :geom => GeometryFactory.polygon)
178
+ GeographyPolygonModel.find(model.id).geom.should == GeometryFactory.polygon
179
+ end
180
+
181
+ it 'should retrieve MultiPoint geography objects' do
182
+ model = GeographyMultiPointModel.create(:extra => 'test', :geom => GeometryFactory.multi_point)
183
+ GeographyMultiPointModel.find(model.id).geom.should == GeometryFactory.multi_point
184
+ end
185
+
186
+ it 'should retrieve MultiLineString geography objects' do
187
+ model = GeographyMultiLineStringModel.create(:extra => 'test', :geom => GeometryFactory.multi_line_string)
188
+ GeographyMultiLineStringModel.find(model.id).geom.should == GeometryFactory.multi_line_string
189
+ end
190
+
191
+ it 'should retrieve MultiPolygon geography objects' do
192
+ model = GeographyMultiPolygonModel.create(:extra => 'test', :geom => GeometryFactory.multi_polygon)
193
+ GeographyMultiPolygonModel.find(model.id).geom.should == GeometryFactory.multi_polygon
194
+ end
195
+
196
+ it 'should retrieve GeometryCollection geography objects' do
197
+ model = GeographyGeometryCollectionModel.create(:extra => 'test', :geom => GeometryFactory.geometry_collection)
198
+ GeographyGeometryCollectionModel.find(model.id).geom.should == GeometryFactory.geometry_collection
199
+ end
200
+
201
+ it 'should retrieve Geometry geography objects' do
202
+ model = GeographyModel.create(:extra => 'test', :geom => GeometryFactory.point)
203
+ GeographyModel.find(model.id).geom.should == GeometryFactory.point
204
+ end
205
+
206
+ it 'should retrieve 3D Point (with Z coord) geography objects' do
207
+ model = GeographyPointzModel.create(:extra => 'test', :geom => GeometryFactory.pointz)
208
+ GeographyPointzModel.find(model.id).geom.should == GeometryFactory.pointz
209
+ end
210
+
211
+ it 'should retrieve 3D Point (with M coord) geography objects' do
212
+ model = GeographyPointmModel.create(:extra => 'test', :geom => GeometryFactory.pointm)
213
+ GeographyPointmModel.find(model.id).geom.should == GeometryFactory.pointm
214
+ end
215
+
216
+ it 'should retrieve 4D Point geography objects' do
217
+ model = GeographyPoint4Model.create(:extra => 'test', :geom => GeometryFactory.point4)
218
+ GeographyPoint4Model.find(model.id).geom.should == GeometryFactory.point4
219
+ end
220
+ end
221
+ end
222
+
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+ require 'spatial_adapter/postgresql'
3
+
4
+ describe "Spatially-enabled Schema Dumps" do
5
+ before :all do
6
+ postgis_connection
7
+ @connection = ActiveRecord::Base.connection
8
+
9
+ # Create a new table
10
+ ActiveRecord::Schema.define do
11
+ create_table :migrated_geometry_models, :force => true do |t|
12
+ t.integer :extra
13
+ t.point :geom, :with_m => true, :with_z => true, :srid => 4326
14
+ end
15
+ add_index :migrated_geometry_models, :geom, :spatial => true, :name => 'test_spatial_index'
16
+
17
+ create_table :migrated_geography_models, :force => true do |t|
18
+ t.integer :extra
19
+ t.point :geom, :with_m => true, :with_z => true, :geographic => true
20
+ end
21
+ end
22
+
23
+ File.open('schema.rb', "w") do |file|
24
+ ActiveRecord::SchemaDumper.dump(@connection, file)
25
+ end
26
+
27
+ # Drop the original tables
28
+ @connection.drop_table "migrated_geometry_models"
29
+ @connection.drop_table "migrated_geography_models"
30
+
31
+ # Load the dumped schema
32
+ load('schema.rb')
33
+ end
34
+
35
+ after :all do
36
+ # delete the schema file
37
+ File.delete('schema.rb')
38
+
39
+ # Drop the new tables
40
+ @connection.drop_table "migrated_geometry_models"
41
+ @connection.drop_table "migrated_geography_models"
42
+ end
43
+
44
+ it "should preserve spatial attributes of geometry tables" do
45
+ columns = @connection.columns("migrated_geometry_models")
46
+
47
+ columns.should have(3).items
48
+ geom_column = columns.select{|c| c.name == 'geom'}.first
49
+ geom_column.should be_a(SpatialAdapter::SpatialColumn)
50
+ geom_column.geometry_type.should == :point
51
+ geom_column.type.should == :string
52
+ geom_column.with_z.should == true
53
+ geom_column.with_m.should == true
54
+ geom_column.srid.should == 4326
55
+ end
56
+
57
+ it "should preserve spatial attributes of geography tables" do
58
+ columns = @connection.columns("migrated_geography_models")
59
+
60
+ columns.should have(3).items
61
+ geom_column = columns.select{|c| c.name == 'geom'}.first
62
+ geom_column.should be_a(SpatialAdapter::SpatialColumn)
63
+ geom_column.geometry_type.should == :point
64
+ geom_column.type.should == :string
65
+ geom_column.with_z.should == true
66
+ geom_column.with_m.should == true
67
+ geom_column.should be_geographic
68
+ end
69
+
70
+ it "should preserve spatial indexes" do
71
+ indexes = @connection.indexes("migrated_geometry_models")
72
+
73
+ indexes.should have(1).item
74
+
75
+ indexes.first.name.should == 'test_spatial_index'
76
+ indexes.first.columns.should == ["geom"]
77
+ indexes.first.spatial.should == true
78
+ end
79
+ end
@@ -0,0 +1,97 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'geo_ruby'
4
+ gem 'activerecord', '=2.2.2'
5
+ #gem 'activerecord', '=3.0.0'
6
+ require 'active_record'
7
+
8
+ $:.unshift((File.join(File.dirname(__FILE__), '..', 'lib')))
9
+
10
+ include GeoRuby::SimpleFeatures
11
+
12
+
13
+ def postgis_connection
14
+ ActiveRecord::Base.establish_connection(
15
+ :adapter => 'postgresql',
16
+ :database => 'spatial_adapter'
17
+ )
18
+ # Turn off those annoying NOTICE messages
19
+ ActiveRecord::Base.connection.execute 'set client_min_messages = warning'
20
+
21
+ # Don't output migration logging
22
+ ActiveRecord::Migration.verbose = false
23
+ end
24
+
25
+ def mysql_connection
26
+ ActiveRecord::Base.establish_connection(
27
+ :adapter => 'mysql',
28
+ :database => 'spatial_adapter',
29
+ :username => 'root',
30
+ :host => 'localhost'
31
+ )
32
+
33
+ # Don't output migration logging
34
+ ActiveRecord::Migration.verbose = false
35
+ end
36
+
37
+ def oracle_enhanced_connection
38
+ ActiveRecord::Base.establish_connection(
39
+ :adapter => 'oracle_enhanced',
40
+ :database => '//localhost:1521/orcl',
41
+ :username => 'spatial_adapter',
42
+ :password => 'test'
43
+ )
44
+
45
+ # Don't output migration logging
46
+ ActiveRecord::Migration.verbose = false
47
+ end
48
+
49
+ class GeometryFactory
50
+ @@default_srid = 4326
51
+
52
+ class << self
53
+ def default_srid=(new_srid)
54
+ @@default_srid = new_srid
55
+ end
56
+
57
+ def point
58
+ Point.from_x_y(1.0, 2.0, @@default_srid)
59
+ end
60
+
61
+ def line_string
62
+ LineString.from_coordinates([[1.4,2.5],[1.5,6.7]], @@default_srid)
63
+ end
64
+
65
+ def polygon
66
+ Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]], @@default_srid)
67
+ end
68
+
69
+ def multi_point
70
+ MultiPoint.from_coordinates([[12.4,-23.3],[-65.1,23.4],[23.55555555,23.0]], @@default_srid)
71
+ end
72
+
73
+ def multi_line_string
74
+ 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]])], @@default_srid)
75
+ end
76
+
77
+ def multi_polygon
78
+ MultiPolygon.from_polygons([Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]]),Polygon.from_coordinates([[[0.0,0.0],[4.0,0.0],[4.0,4.0],[0.0,4.0],[0.0,0.0]],[[1.0,1.0],[3.0,1.0],[3.0,3.0],[1.0,3.0],[1.0,1.0]]])], @@default_srid)
79
+ end
80
+
81
+ def geometry_collection
82
+ GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4),LineString.from_coordinates([[5.7,12.45],[67.55,54.0]])], @@default_srid)
83
+ end
84
+
85
+ def pointz
86
+ Point.from_x_y_z(1.0, 2.0, 3.0, @@default_srid)
87
+ end
88
+
89
+ def pointm
90
+ Point.from_x_y_m(1.0, 2.0, 3.0, @@default_srid)
91
+ end
92
+
93
+ def point4
94
+ Point.from_x_y_z_m(1.0, 2.0, 3.0, 4.0, @@default_srid)
95
+ end
96
+ end
97
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: beh_spatial_adapter
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Pete Deffendol
9
+ - Guilhem Vellut
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2010-04-29 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activerecord
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 2.2.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 2.2.2
31
+ - !ruby/object:Gem::Dependency
32
+ name: GeoRuby
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: 1.3.0
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 1.3.0
47
+ description: Provides enhancements to ActiveRecord to handle spatial datatypes in
48
+ PostgreSQL and MySQL.
49
+ email: pete@fragility.us
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files:
53
+ - README.rdoc
54
+ files:
55
+ - MIT-LICENSE
56
+ - README.rdoc
57
+ - VERSION
58
+ - lib/spatial_adapter.rb
59
+ - lib/spatial_adapter/common/raw_geom_info.rb
60
+ - lib/spatial_adapter/common/schema_definitions.rb
61
+ - lib/spatial_adapter/common/schema_dumper.rb
62
+ - lib/spatial_adapter/common/spatial_column.rb
63
+ - lib/spatial_adapter/common/table_definition.rb
64
+ - lib/spatial_adapter/mysql.rb
65
+ - lib/spatial_adapter/oracle_enhanced.rb
66
+ - lib/spatial_adapter/postgresql.rb
67
+ - lib/spatial_adapter/railtie.rb
68
+ - rails/init.rb
69
+ - spec/db/mysql_raw.rb
70
+ - spec/db/postgis_raw.rb
71
+ - spec/models/common.rb
72
+ - spec/mysql/connection_adapter_spec.rb
73
+ - spec/mysql/migration_spec.rb
74
+ - spec/mysql/models_spec.rb
75
+ - spec/mysql/schema_dumper_spec.rb
76
+ - spec/postgresql/connection_adapter_spec.rb
77
+ - spec/postgresql/migration_spec.rb
78
+ - spec/postgresql/models_spec.rb
79
+ - spec/postgresql/schema_dumper_spec.rb
80
+ - spec/spec_helper.rb
81
+ - spec/README.txt
82
+ homepage: http://github.com/fragility/spatial_adapter
83
+ licenses: []
84
+ post_install_message:
85
+ rdoc_options:
86
+ - --charset=UTF-8
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 1.8.25
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Spatial Adapter for ActiveRecord
107
+ test_files:
108
+ - spec/db/mysql_raw.rb
109
+ - spec/db/postgis_raw.rb
110
+ - spec/models/common.rb
111
+ - spec/mysql/connection_adapter_spec.rb
112
+ - spec/mysql/migration_spec.rb
113
+ - spec/mysql/models_spec.rb
114
+ - spec/mysql/schema_dumper_spec.rb
115
+ - spec/postgresql/connection_adapter_spec.rb
116
+ - spec/postgresql/migration_spec.rb
117
+ - spec/postgresql/models_spec.rb
118
+ - spec/postgresql/schema_dumper_spec.rb
119
+ - spec/spec_helper.rb
120
+ - spec/README.txt