spatial_adapter 1.2.0 → 1.3.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.
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
@@ -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