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.
- data/.gitignore +3 -0
- data/Gemfile +3 -0
- data/README.rdoc +30 -17
- data/Rakefile +11 -0
- data/init.rb +1 -0
- data/lib/spatial_adapter/base/mysql/adapter.rb +54 -0
- data/lib/spatial_adapter/base/mysql/spatial_column.rb +12 -0
- data/lib/spatial_adapter/base/mysql.rb +9 -0
- data/lib/spatial_adapter/common/schema_dumper.rb +12 -12
- data/lib/spatial_adapter/common/spatial_column.rb +4 -4
- data/lib/spatial_adapter/common/table_definition.rb +8 -10
- data/lib/spatial_adapter/common.rb +10 -0
- data/lib/spatial_adapter/jdbcmysql.rb +50 -0
- data/lib/spatial_adapter/mysql.rb +43 -85
- data/lib/spatial_adapter/mysql2.rb +39 -86
- data/lib/spatial_adapter/postgresql.rb +315 -324
- data/lib/spatial_adapter/version.rb +3 -0
- data/lib/spatial_adapter.rb +3 -7
- data/spatial_adapter.gemspec +39 -0
- data/spec/db/jdbcmysql_raw.rb +70 -0
- data/spec/db/mysql2_raw.rb +9 -9
- data/spec/db/mysql_raw.rb +9 -9
- data/spec/jdbcmysql_spec.rb +25 -0
- data/spec/mysql2_spec.rb +31 -0
- data/spec/mysql_spec.rb +17 -0
- data/spec/postgresql/connection_adapter_spec.rb +34 -39
- data/spec/postgresql/migration_spec.rb +51 -51
- data/spec/postgresql/models_spec.rb +37 -37
- data/spec/postgresql/schema_dumper_spec.rb +12 -12
- data/spec/postgresql_spec.rb +5 -0
- data/spec/{shared_examples.rb → shared/common_model_actions_spec.rb} +2 -2
- data/spec/shared/mysql_connection_adapter_spec.rb +110 -0
- data/spec/{mysql/migration_spec.rb → shared/mysql_migration_spec.rb} +17 -17
- data/spec/shared/mysql_models_spec.rb +58 -0
- data/spec/{mysql/schema_dumper_spec.rb → shared/mysql_schema_dumper_spec.rb} +24 -27
- data/spec/spec_helper.rb +25 -21
- metadata +131 -84
- data/VERSION +0 -1
- data/spec/README.txt +0 -22
- data/spec/mysql/connection_adapter_spec.rb +0 -106
- data/spec/mysql/models_spec.rb +0 -65
- data/spec/mysql2/connection_adapter_spec.rb +0 -106
- data/spec/mysql2/migration_spec.rb +0 -64
- data/spec/mysql2/models_spec.rb +0 -65
- data/spec/mysql2/schema_dumper_spec.rb +0 -56
data/spec/mysql2/models_spec.rb
DELETED
@@ -1,65 +0,0 @@
|
|
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
|
-
|
@@ -1,56 +0,0 @@
|
|
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
|