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/lib/spatial_adapter.rb
CHANGED
@@ -16,7 +16,7 @@ include GeoRuby::SimpleFeatures
|
|
16
16
|
|
17
17
|
module SpatialAdapter
|
18
18
|
# Translation of geometric data types
|
19
|
-
def geometry_data_types
|
19
|
+
def self.geometry_data_types
|
20
20
|
{
|
21
21
|
:point => { :name => "POINT" },
|
22
22
|
:line_string => { :name => "LINESTRING" },
|
@@ -28,14 +28,10 @@ module SpatialAdapter
|
|
28
28
|
:geometry => { :name => "GEOMETRY"}
|
29
29
|
}
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
class NotCompatibleError < ::StandardError
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
require 'spatial_adapter/common
|
37
|
-
require 'spatial_adapter/common/spatial_column'
|
38
|
-
require 'spatial_adapter/common/schema_definitions'
|
39
|
-
require 'spatial_adapter/common/schema_dumper'
|
40
|
-
require 'spatial_adapter/common/table_definition'
|
36
|
+
require 'spatial_adapter/common'
|
41
37
|
require 'spatial_adapter/railtie' if defined?(Rails::Railtie)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'spatial_adapter/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = %q{spatial_adapter}
|
7
|
+
s.version = SpatialAdapter::VERSION
|
8
|
+
|
9
|
+
s.platform = $platform || RUBY_PLATFORM[/java/] || Gem::Platform::RUBY
|
10
|
+
|
11
|
+
s.authors = ["Pete Deffendol", "Guilhem Vellut"]
|
12
|
+
s.email = %q{pete@fragility.us}
|
13
|
+
s.homepage = %q{http://github.com/fragility/spatial_adapter}
|
14
|
+
s.summary = "spatial_adapter-#{SpatialAdapter::VERSION}"
|
15
|
+
s.description = %q{Provides enhancements to ActiveRecord to handle spatial
|
16
|
+
datatypes in PostgreSQL and MySQL.}
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.extra_rdoc_files = ["README.rdoc", "MIT-LICENSE"]
|
22
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
|
25
|
+
s.add_development_dependency 'rake'
|
26
|
+
s.add_development_dependency 'rspec'
|
27
|
+
if s.platform.to_s == 'ruby'
|
28
|
+
s.add_development_dependency 'pg'
|
29
|
+
s.add_development_dependency 'mysql'
|
30
|
+
s.add_development_dependency 'mysql2', '<= 0.2.13'
|
31
|
+
end
|
32
|
+
|
33
|
+
if s.platform.to_s == 'java'
|
34
|
+
s.add_development_dependency 'activerecord-jdbcmysql-adapter'
|
35
|
+
end
|
36
|
+
|
37
|
+
s.add_dependency 'activerecord', '>= 2.2.2', '< 3.1.0'
|
38
|
+
s.add_dependency 'GeoRuby', '>= 1.3.0'
|
39
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
jdbcmysql_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(100),
|
9
|
+
more_extra varchar(100),
|
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(100),
|
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(100),
|
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(100),
|
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(100),
|
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(100),
|
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(100),
|
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(100),
|
68
|
+
geom geometry
|
69
|
+
) ENGINE=MyISAM"
|
70
|
+
end
|
data/spec/db/mysql2_raw.rb
CHANGED
@@ -5,8 +5,8 @@ ActiveRecord::Schema.define() do
|
|
5
5
|
execute "create table point_models
|
6
6
|
(
|
7
7
|
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
8
|
-
extra varchar(
|
9
|
-
more_extra varchar(
|
8
|
+
extra varchar(100),
|
9
|
+
more_extra varchar(100),
|
10
10
|
geom point not null
|
11
11
|
) ENGINE=MyISAM"
|
12
12
|
execute "create spatial index index_point_models_on_geom on point_models (geom)"
|
@@ -16,7 +16,7 @@ ActiveRecord::Schema.define() do
|
|
16
16
|
execute "create table line_string_models
|
17
17
|
(
|
18
18
|
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
19
|
-
extra varchar(
|
19
|
+
extra varchar(100),
|
20
20
|
geom linestring
|
21
21
|
) ENGINE=MyISAM"
|
22
22
|
|
@@ -24,7 +24,7 @@ ActiveRecord::Schema.define() do
|
|
24
24
|
execute "create table polygon_models
|
25
25
|
(
|
26
26
|
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
27
|
-
extra varchar(
|
27
|
+
extra varchar(100),
|
28
28
|
geom polygon
|
29
29
|
) ENGINE=MyISAM"
|
30
30
|
|
@@ -32,7 +32,7 @@ ActiveRecord::Schema.define() do
|
|
32
32
|
execute "create table multi_point_models
|
33
33
|
(
|
34
34
|
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
35
|
-
extra varchar(
|
35
|
+
extra varchar(100),
|
36
36
|
geom multipoint
|
37
37
|
) ENGINE=MyISAM"
|
38
38
|
|
@@ -40,7 +40,7 @@ ActiveRecord::Schema.define() do
|
|
40
40
|
execute "create table multi_line_string_models
|
41
41
|
(
|
42
42
|
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
43
|
-
extra varchar(
|
43
|
+
extra varchar(100),
|
44
44
|
geom multilinestring
|
45
45
|
) ENGINE=MyISAM"
|
46
46
|
|
@@ -48,7 +48,7 @@ ActiveRecord::Schema.define() do
|
|
48
48
|
execute "create table multi_polygon_models
|
49
49
|
(
|
50
50
|
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
51
|
-
extra varchar(
|
51
|
+
extra varchar(100),
|
52
52
|
geom multipolygon
|
53
53
|
) ENGINE=MyISAM"
|
54
54
|
|
@@ -56,7 +56,7 @@ ActiveRecord::Schema.define() do
|
|
56
56
|
execute "create table geometry_collection_models
|
57
57
|
(
|
58
58
|
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
59
|
-
extra varchar(
|
59
|
+
extra varchar(100),
|
60
60
|
geom geometrycollection
|
61
61
|
) ENGINE=MyISAM"
|
62
62
|
|
@@ -64,7 +64,7 @@ ActiveRecord::Schema.define() do
|
|
64
64
|
execute "create table geometry_models
|
65
65
|
(
|
66
66
|
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
67
|
-
extra varchar(
|
67
|
+
extra varchar(100),
|
68
68
|
geom geometry
|
69
69
|
) ENGINE=MyISAM"
|
70
70
|
end
|
data/spec/db/mysql_raw.rb
CHANGED
@@ -5,8 +5,8 @@ ActiveRecord::Schema.define() do
|
|
5
5
|
execute "create table point_models
|
6
6
|
(
|
7
7
|
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
8
|
-
extra varchar(
|
9
|
-
more_extra varchar(
|
8
|
+
extra varchar(100),
|
9
|
+
more_extra varchar(100),
|
10
10
|
geom point not null
|
11
11
|
) ENGINE=MyISAM"
|
12
12
|
execute "create spatial index index_point_models_on_geom on point_models (geom)"
|
@@ -16,7 +16,7 @@ ActiveRecord::Schema.define() do
|
|
16
16
|
execute "create table line_string_models
|
17
17
|
(
|
18
18
|
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
19
|
-
extra varchar(
|
19
|
+
extra varchar(100),
|
20
20
|
geom linestring
|
21
21
|
) ENGINE=MyISAM"
|
22
22
|
|
@@ -24,7 +24,7 @@ ActiveRecord::Schema.define() do
|
|
24
24
|
execute "create table polygon_models
|
25
25
|
(
|
26
26
|
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
27
|
-
extra varchar(
|
27
|
+
extra varchar(100),
|
28
28
|
geom polygon
|
29
29
|
) ENGINE=MyISAM"
|
30
30
|
|
@@ -32,7 +32,7 @@ ActiveRecord::Schema.define() do
|
|
32
32
|
execute "create table multi_point_models
|
33
33
|
(
|
34
34
|
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
35
|
-
extra varchar(
|
35
|
+
extra varchar(100),
|
36
36
|
geom multipoint
|
37
37
|
) ENGINE=MyISAM"
|
38
38
|
|
@@ -40,7 +40,7 @@ ActiveRecord::Schema.define() do
|
|
40
40
|
execute "create table multi_line_string_models
|
41
41
|
(
|
42
42
|
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
43
|
-
extra varchar(
|
43
|
+
extra varchar(100),
|
44
44
|
geom multilinestring
|
45
45
|
) ENGINE=MyISAM"
|
46
46
|
|
@@ -48,7 +48,7 @@ ActiveRecord::Schema.define() do
|
|
48
48
|
execute "create table multi_polygon_models
|
49
49
|
(
|
50
50
|
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
51
|
-
extra varchar(
|
51
|
+
extra varchar(100),
|
52
52
|
geom multipolygon
|
53
53
|
) ENGINE=MyISAM"
|
54
54
|
|
@@ -56,7 +56,7 @@ ActiveRecord::Schema.define() do
|
|
56
56
|
execute "create table geometry_collection_models
|
57
57
|
(
|
58
58
|
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
59
|
-
extra varchar(
|
59
|
+
extra varchar(100),
|
60
60
|
geom geometrycollection
|
61
61
|
) ENGINE=MyISAM"
|
62
62
|
|
@@ -64,7 +64,7 @@ ActiveRecord::Schema.define() do
|
|
64
64
|
execute "create table geometry_models
|
65
65
|
(
|
66
66
|
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
67
|
-
extra varchar(
|
67
|
+
extra varchar(100),
|
68
68
|
geom geometry
|
69
69
|
) ENGINE=MyISAM"
|
70
70
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'shared/mysql_connection_adapter_spec'
|
3
|
+
require 'shared/mysql_migration_spec'
|
4
|
+
require 'shared/mysql_schema_dumper_spec'
|
5
|
+
require 'shared/mysql_models_spec'
|
6
|
+
require 'shared/common_model_actions_spec'
|
7
|
+
require 'spatial_adapter/jdbcmysql'
|
8
|
+
require 'db/jdbcmysql_raw'
|
9
|
+
require 'models/common'
|
10
|
+
|
11
|
+
describe ActiveRecord::ConnectionAdapters::MysqlAdapter do
|
12
|
+
it_should_behave_like 'common model actions'
|
13
|
+
it_should_behave_like 'a modified mysql adapter' do
|
14
|
+
let(:establish){ jdbcmysql_connection }
|
15
|
+
end
|
16
|
+
it_should_behave_like 'spatially enabled migrations' do
|
17
|
+
let(:establish){ jdbcmysql_connection }
|
18
|
+
end
|
19
|
+
it_should_behave_like 'spatially enabled schema dump' do
|
20
|
+
let(:establish){ jdbcmysql_connection }
|
21
|
+
end
|
22
|
+
it_should_behave_like 'spatially enabled models' do
|
23
|
+
let(:establish){ jdbcmysql_connection }
|
24
|
+
end
|
25
|
+
end
|
data/spec/mysql2_spec.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'shared/mysql_connection_adapter_spec'
|
3
|
+
require 'shared/mysql_migration_spec'
|
4
|
+
require 'shared/mysql_schema_dumper_spec'
|
5
|
+
require 'shared/mysql_models_spec'
|
6
|
+
require 'shared/common_model_actions_spec'
|
7
|
+
require 'spatial_adapter/mysql2'
|
8
|
+
require 'db/mysql2_raw'
|
9
|
+
require 'models/common'
|
10
|
+
|
11
|
+
describe ActiveRecord::ConnectionAdapters::Mysql2Adapter do
|
12
|
+
it_should_behave_like 'common model actions'
|
13
|
+
it_should_behave_like 'a modified mysql adapter' do
|
14
|
+
let(:establish){ mysql2_connection }
|
15
|
+
let(:column) do
|
16
|
+
ActiveRecord::ConnectionAdapters::Mysql2Column
|
17
|
+
end
|
18
|
+
let(:spatial_column) do
|
19
|
+
ActiveRecord::ConnectionAdapters::SpatialMysql2Column
|
20
|
+
end
|
21
|
+
end
|
22
|
+
it_should_behave_like 'spatially enabled migrations' do
|
23
|
+
let(:establish){ mysql2_connection }
|
24
|
+
end
|
25
|
+
it_should_behave_like 'spatially enabled schema dump' do
|
26
|
+
let(:establish){ mysql2_connection }
|
27
|
+
end
|
28
|
+
it_should_behave_like 'spatially enabled models' do
|
29
|
+
let(:establish){ mysql2_connection }
|
30
|
+
end
|
31
|
+
end
|
data/spec/mysql_spec.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'shared/mysql_connection_adapter_spec'
|
3
|
+
require 'shared/mysql_migration_spec'
|
4
|
+
require 'shared/mysql_schema_dumper_spec'
|
5
|
+
require 'shared/mysql_models_spec'
|
6
|
+
require 'shared/common_model_actions_spec'
|
7
|
+
require 'spatial_adapter/mysql'
|
8
|
+
require 'db/mysql_raw'
|
9
|
+
require 'models/common'
|
10
|
+
|
11
|
+
describe ActiveRecord::ConnectionAdapters::MysqlAdapter do
|
12
|
+
it_should_behave_like 'common model actions'
|
13
|
+
it_should_behave_like 'a modified mysql adapter'
|
14
|
+
it_should_behave_like 'spatially enabled migrations'
|
15
|
+
it_should_behave_like 'spatially enabled schema dump'
|
16
|
+
it_should_behave_like 'spatially enabled models'
|
17
|
+
end
|
@@ -8,66 +8,66 @@ describe "Modified PostgreSQLAdapter" do
|
|
8
8
|
postgis_connection
|
9
9
|
@connection = ActiveRecord::Base.connection
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
describe '#postgis_version' do
|
13
13
|
it 'should report a version number if PostGIS is installed' do
|
14
14
|
@connection.should_receive(:select_value).with('SELECT postgis_full_version()').and_return('POSTGIS="1.5.0" GEOS="3.2.0-CAPI-1.6.0" PROJ="Rel. 4.7.1, 23 September 2009" LIBXML="2.7.6" USE_STATS')
|
15
15
|
@connection.postgis_version.should_not be_nil
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
it 'should report nil if PostGIS is not installed' do
|
19
19
|
@connection.should_receive(:select_value).with('SELECT postgis_full_version()').and_raise(ActiveRecord::StatementInvalid)
|
20
20
|
@connection.postgis_version.should be_nil
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
describe '#postgis_major_version' do
|
25
25
|
it 'should be the first component of the version number' do
|
26
26
|
@connection.stub!(:postgis_version).and_return('1.5.0')
|
27
27
|
@connection.postgis_major_version.should == 1
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it 'should be nil if PostGIS is not installed' do
|
31
31
|
@connection.stub!(:postgis_version).and_return(nil)
|
32
32
|
@connection.postgis_major_version.should be_nil
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
describe '#postgis_minor_version' do
|
37
37
|
it 'should be the second component of the version number' do
|
38
38
|
@connection.stub!(:postgis_version).and_return('1.5.0')
|
39
39
|
@connection.postgis_minor_version.should == 5
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
it 'should be nil if PostGIS is not installed' do
|
43
43
|
@connection.stub!(:postgis_version).and_return(nil)
|
44
44
|
@connection.postgis_minor_version.should be_nil
|
45
45
|
end
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
describe '#spatial?' do
|
49
49
|
it 'should be true if PostGIS is installed' do
|
50
50
|
@connection.should_receive(:select_value).with('SELECT postgis_full_version()').and_return('POSTGIS="1.5.0" GEOS="3.2.0-CAPI-1.6.0" PROJ="Rel. 4.7.1, 23 September 2009" LIBXML="2.7.6" USE_STATS')
|
51
51
|
@connection.should be_spatial
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
it 'should be false if PostGIS is not installed' do
|
55
55
|
@connection.should_receive(:select_value).with('SELECT postgis_full_version()').and_raise(ActiveRecord::StatementInvalid)
|
56
56
|
@connection.should_not be_spatial
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
describe '#supports_geographic?' do
|
61
61
|
it "should be true for PostGIS version 1.5.0" do
|
62
62
|
@connection.stub!(:postgis_version).and_return('1.5.0')
|
63
63
|
@connection.supports_geographic?.should == true
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
it "should be true for PostGIS newer than 1.5.0" do
|
67
67
|
@connection.stub!(:postgis_version).and_return('1.5.1')
|
68
68
|
@connection.supports_geographic?.should == true
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
it "should be true for PostGIS older than 1.5.0" do
|
72
72
|
@connection.stub!(:postgis_version).and_return('1.4.0')
|
73
73
|
@connection.supports_geographic?.should == false
|
@@ -82,24 +82,24 @@ describe "Modified PostgreSQLAdapter" do
|
|
82
82
|
column.geometry_type.should == :point
|
83
83
|
column.should_not be_geographic
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
it "should be a geographic SpatialPostgreSQLColumn if column is a geography data type" do
|
87
87
|
column = GeographyPointModel.columns.select{|c| c.name == 'geom'}.first
|
88
88
|
column.should be_a(ActiveRecord::ConnectionAdapters::SpatialPostgreSQLColumn)
|
89
89
|
column.geometry_type.should == :point
|
90
90
|
column.should be_geographic
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
it "should be PostgreSQLColumn if column is not a spatial data type" do
|
94
94
|
PointModel.columns.select{|c| c.name == 'extra'}.first.should be_a(ActiveRecord::ConnectionAdapters::PostgreSQLColumn)
|
95
95
|
end
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
describe "@geometry_type" do
|
99
99
|
it "should be :point for geometry columns restricted to POINT types" do
|
100
100
|
PointModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :point
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
it "should be :line_string for geometry columns restricted to LINESTRING types" do
|
104
104
|
LineStringModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :line_string
|
105
105
|
end
|
@@ -115,23 +115,23 @@ describe "Modified PostgreSQLAdapter" do
|
|
115
115
|
it "should be :multi_line_string for geometry columns restricted to MULTILINESTRING types" do
|
116
116
|
MultiLineStringModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :multi_line_string
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
it "should be :multi_polygon for geometry columns restricted to MULTIPOLYGON types" do
|
120
120
|
MultiPolygonModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :multi_polygon
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
it "should be :geometry_collection for geometry columns restricted to GEOMETRYCOLLECTION types" do
|
124
124
|
GeometryCollectionModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :geometry_collection
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
127
|
it "should be :geometry for geometry columns not restricted to a type" do
|
128
128
|
GeometryModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :geometry
|
129
129
|
end
|
130
|
-
|
130
|
+
|
131
131
|
it "should be :point for geography columns restricted to POINT types" do
|
132
132
|
GeographyPointModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :point
|
133
133
|
end
|
134
|
-
|
134
|
+
|
135
135
|
it "should be :line_string for geography columns restricted to LINESTRING types" do
|
136
136
|
GeographyLineStringModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :line_string
|
137
137
|
end
|
@@ -147,51 +147,51 @@ describe "Modified PostgreSQLAdapter" do
|
|
147
147
|
it "should be :multi_line_string for geography columns restricted to MULTILINESTRING types" do
|
148
148
|
GeographyMultiLineStringModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :multi_line_string
|
149
149
|
end
|
150
|
-
|
150
|
+
|
151
151
|
it "should be :multi_polygon for geography columns restricted to MULTIPOLYGON types" do
|
152
152
|
GeographyMultiPolygonModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :multi_polygon
|
153
153
|
end
|
154
|
-
|
154
|
+
|
155
155
|
it "should be :geometry_collection for geography columns restricted to GEOMETRYCOLLECTION types" do
|
156
156
|
GeographyGeometryCollectionModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :geometry_collection
|
157
157
|
end
|
158
|
-
|
158
|
+
|
159
159
|
it "should be :geometry for geography columns not restricted to a type" do
|
160
160
|
GeographyModel.columns.select{|c| c.name == 'geom'}.first.geometry_type.should == :geometry
|
161
161
|
end
|
162
162
|
end
|
163
163
|
end
|
164
|
-
|
164
|
+
|
165
165
|
describe "#indexes" do
|
166
166
|
before :each do
|
167
167
|
@indexes = @connection.indexes('point_models')
|
168
168
|
end
|
169
|
-
|
169
|
+
|
170
170
|
it "should return an IndexDefinition for each index on the table" do
|
171
171
|
@indexes.should have(2).items
|
172
172
|
@indexes.each do |i|
|
173
173
|
i.should be_a(ActiveRecord::ConnectionAdapters::IndexDefinition)
|
174
174
|
end
|
175
175
|
end
|
176
|
-
|
176
|
+
|
177
177
|
it "should indicate the correct columns in the index" do
|
178
178
|
@indexes.select{|i| i.name == 'index_point_models_on_geom'}.first.columns.should == ['geom']
|
179
179
|
@indexes.select{|i| i.name == 'index_point_models_on_extra'}.first.columns.should == ['extra', 'more_extra']
|
180
180
|
end
|
181
|
-
|
181
|
+
|
182
182
|
it "should be marked as spatial if a GiST index on a geometry column" do
|
183
183
|
@indexes.select{|i| i.name == 'index_point_models_on_geom'}.first.spatial.should == true
|
184
184
|
end
|
185
|
-
|
185
|
+
|
186
186
|
it "should be marked as spatial if a GiST index on a geography column" do
|
187
187
|
@indexes = @connection.indexes('geography_point_models')
|
188
188
|
@indexes.select{|i| i.name == 'index_geography_point_models_on_geom'}.first.spatial.should == true
|
189
189
|
end
|
190
|
-
|
190
|
+
|
191
191
|
it "should not be marked as spatial if not a GiST index" do
|
192
192
|
@indexes.select{|i| i.name == 'index_point_models_on_extra'}.first.spatial.should == false
|
193
193
|
end
|
194
|
-
|
194
|
+
|
195
195
|
it "should not be marked as spatial if a GiST index on a non-geometry column" do
|
196
196
|
@connection.execute(<<-SQL)
|
197
197
|
create table non_spatial_models
|
@@ -206,22 +206,17 @@ describe "Modified PostgreSQLAdapter" do
|
|
206
206
|
@indexes.select{|i| i.name == 'index_non_spatial_models_on_location'}.first.spatial.should == false
|
207
207
|
@connection.execute 'drop table non_spatial_models'
|
208
208
|
end
|
209
|
-
end
|
210
|
-
|
209
|
+
end
|
210
|
+
|
211
211
|
describe "#add_index" do
|
212
|
-
after :each do
|
213
|
-
@connection.should_receive(:execute).with(any_args())
|
214
|
-
@connection.remove_index('geometry_models', 'geom')
|
215
|
-
end
|
216
|
-
|
217
212
|
it "should create a spatial index given :spatial => true" do
|
218
213
|
@connection.should_receive(:execute).with(/using gist/i)
|
219
214
|
@connection.add_index('geometry_models', 'geom', :spatial => true)
|
220
215
|
end
|
221
|
-
|
216
|
+
|
222
217
|
it "should not create a spatial index unless specified" do
|
223
218
|
@connection.should_not_receive(:execute).with(/using gist/i)
|
224
219
|
@connection.add_index('geometry_models', 'extra')
|
225
220
|
end
|
226
221
|
end
|
227
|
-
end
|
222
|
+
end
|