activerecord-postgis-adapter 0.5.1 → 0.6.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 (32) hide show
  1. data/Documentation.rdoc +322 -0
  2. data/History.rdoc +5 -0
  3. data/README.rdoc +42 -290
  4. data/Version +1 -1
  5. data/lib/active_record/connection_adapters/postgis_adapter.rb +35 -21
  6. data/lib/active_record/connection_adapters/postgis_adapter/rails3/create_connection.rb +96 -0
  7. data/lib/active_record/connection_adapters/postgis_adapter/{databases.rake → rails3/databases.rake} +7 -1
  8. data/lib/active_record/connection_adapters/postgis_adapter/{main_adapter.rb → rails3/main_adapter.rb} +9 -9
  9. data/lib/active_record/connection_adapters/postgis_adapter/{spatial_column.rb → rails3/spatial_column.rb} +4 -8
  10. data/lib/active_record/connection_adapters/postgis_adapter/{spatial_table_definition.rb → rails3/spatial_table_definition.rb} +5 -9
  11. data/lib/active_record/connection_adapters/postgis_adapter/rails4/create_connection.rb +88 -0
  12. data/lib/active_record/connection_adapters/postgis_adapter/rails4/databases.rake +52 -0
  13. data/lib/active_record/connection_adapters/postgis_adapter/rails4/main_adapter.rb +310 -0
  14. data/lib/active_record/connection_adapters/postgis_adapter/rails4/postgis_database_tasks.rb +232 -0
  15. data/lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_column.rb +220 -0
  16. data/lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_table_definition.rb +140 -0
  17. data/lib/active_record/connection_adapters/postgis_adapter/railtie.rb +3 -28
  18. data/lib/active_record/connection_adapters/postgis_adapter/{arel_tosql.rb → shared/arel_tosql.rb} +3 -7
  19. data/lib/active_record/connection_adapters/postgis_adapter/shared/jdbc_compat.rb +133 -0
  20. data/lib/active_record/connection_adapters/postgis_adapter/shared/railtie.rb +66 -0
  21. data/lib/active_record/connection_adapters/postgis_adapter/shared/setup.rb +57 -0
  22. data/lib/active_record/connection_adapters/postgis_adapter/{version.rb → shared/version.rb} +1 -1
  23. data/lib/activerecord-postgis-adapter.rb +37 -0
  24. data/lib/rgeo/active_record/postgis_adapter/railtie.rb +1 -1
  25. data/test/tc_basic.rb +43 -16
  26. data/test/tc_ddl.rb +2 -2
  27. data/test/tc_nested_class.rb +2 -2
  28. data/test/tc_spatial_queries.rb +14 -9
  29. data/test/tc_tasks.rb +110 -0
  30. metadata +27 -14
  31. data/lib/active_record/connection_adapters/postgis_adapter/jdbc_connection.rb +0 -78
  32. data/lib/active_record/connection_adapters/postgis_adapter/pg_connection.rb +0 -27
data/test/tc_tasks.rb ADDED
@@ -0,0 +1,110 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Tests for the PostGIS ActiveRecord adapter
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010-2012 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+ require 'minitest/autorun'
37
+ require 'rgeo/active_record/adapter_test_helper'
38
+
39
+
40
+ module RGeo
41
+ module ActiveRecord # :nodoc:
42
+ module PostGISAdapter # :nodoc:
43
+ module Tests # :nodoc:
44
+
45
+ class TestTasks < ::MiniTest::Unit::TestCase # :nodoc:
46
+
47
+ DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database.yml'
48
+ OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database_local.yml'
49
+
50
+ class << self
51
+ def before_open_database(args_)
52
+ @new_database_config = args_[:config].merge('database' => 'postgis_adapter_test2')
53
+ @new_database_config.stringify_keys!
54
+ end
55
+ attr_reader :new_database_config
56
+ end
57
+
58
+ include AdapterTestHelper
59
+
60
+
61
+ def cleanup_tables
62
+ ::ActiveRecord::Base.remove_connection
63
+ ::ActiveRecord::Base.clear_active_connections!
64
+ TestTasks::DEFAULT_AR_CLASS.connection.execute("DROP DATABASE IF EXISTS \"postgis_adapter_test2\"")
65
+ end
66
+
67
+
68
+ define_test_methods do
69
+
70
+
71
+ def test_create_database_from_extension_in_postgis_schema
72
+ unless defined?(::ActiveRecord::ConnectionAdapters::PostGISAdapter::PostGISDatabaseTasks)
73
+ skip('No task tests for Rails 3')
74
+ end
75
+ ::ActiveRecord::Tasks::DatabaseTasks.create(TestTasks.new_database_config.merge('schema_search_path' => 'public,postgis'))
76
+ ::ActiveRecord::Base.connection.select_values("SELECT * from postgis.spatial_ref_sys")
77
+ end
78
+
79
+
80
+ def test_create_database_from_extension_in_public_schema
81
+ unless defined?(::ActiveRecord::ConnectionAdapters::PostGISAdapter::PostGISDatabaseTasks)
82
+ skip('No task tests for Rails 3')
83
+ end
84
+ ::ActiveRecord::Tasks::DatabaseTasks.create(TestTasks.new_database_config)
85
+ ::ActiveRecord::Base.connection.select_values("SELECT * from public.spatial_ref_sys")
86
+ end
87
+
88
+
89
+ def test_schema_dump
90
+ unless defined?(::ActiveRecord::ConnectionAdapters::PostGISAdapter::PostGISDatabaseTasks)
91
+ skip('No task tests for Rails 3')
92
+ end
93
+ filename_ = ::File.expand_path('../tmp/tmp.sql', ::File.dirname(__FILE__))
94
+ ::FileUtils.rm_f(filename_)
95
+ ::FileUtils.mkdir_p(::File.dirname(filename_))
96
+ ::ActiveRecord::Tasks::DatabaseTasks.create(TestTasks.new_database_config.merge('schema_search_path' => 'public,postgis'))
97
+ ::ActiveRecord::Tasks::DatabaseTasks.structure_dump(TestTasks.new_database_config, filename_)
98
+ sql_ = ::File.read(filename_)
99
+ assert(sql_ !~ /CREATE/)
100
+ end
101
+
102
+
103
+ end
104
+
105
+ end
106
+
107
+ end
108
+ end
109
+ end
110
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgis-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-04 00:00:00.000000000 Z
12
+ date: 2013-03-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rgeo-activerecord
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.4.6
21
+ version: 0.5.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,9 +26,9 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 0.4.6
29
+ version: 0.5.0
30
30
  - !ruby/object:Gem::Dependency
31
- name: appraisal
31
+ name: rake
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
@@ -44,7 +44,7 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: rake
47
+ name: minitest
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
@@ -82,24 +82,36 @@ email: dazuma@gmail.com
82
82
  executables: []
83
83
  extensions: []
84
84
  extra_rdoc_files:
85
+ - Documentation.rdoc
85
86
  - History.rdoc
86
87
  - README.rdoc
87
88
  files:
88
- - lib/active_record/connection_adapters/postgis_adapter/arel_tosql.rb
89
- - lib/active_record/connection_adapters/postgis_adapter/jdbc_connection.rb
90
- - lib/active_record/connection_adapters/postgis_adapter/main_adapter.rb
91
- - lib/active_record/connection_adapters/postgis_adapter/pg_connection.rb
89
+ - lib/active_record/connection_adapters/postgis_adapter/rails3/create_connection.rb
90
+ - lib/active_record/connection_adapters/postgis_adapter/rails3/main_adapter.rb
91
+ - lib/active_record/connection_adapters/postgis_adapter/rails3/spatial_column.rb
92
+ - lib/active_record/connection_adapters/postgis_adapter/rails3/spatial_table_definition.rb
93
+ - lib/active_record/connection_adapters/postgis_adapter/rails4/create_connection.rb
94
+ - lib/active_record/connection_adapters/postgis_adapter/rails4/main_adapter.rb
95
+ - lib/active_record/connection_adapters/postgis_adapter/rails4/postgis_database_tasks.rb
96
+ - lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_column.rb
97
+ - lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_table_definition.rb
92
98
  - lib/active_record/connection_adapters/postgis_adapter/railtie.rb
93
- - lib/active_record/connection_adapters/postgis_adapter/spatial_column.rb
94
- - lib/active_record/connection_adapters/postgis_adapter/spatial_table_definition.rb
95
- - lib/active_record/connection_adapters/postgis_adapter/version.rb
99
+ - lib/active_record/connection_adapters/postgis_adapter/shared/arel_tosql.rb
100
+ - lib/active_record/connection_adapters/postgis_adapter/shared/jdbc_compat.rb
101
+ - lib/active_record/connection_adapters/postgis_adapter/shared/railtie.rb
102
+ - lib/active_record/connection_adapters/postgis_adapter/shared/setup.rb
103
+ - lib/active_record/connection_adapters/postgis_adapter/shared/version.rb
96
104
  - lib/active_record/connection_adapters/postgis_adapter.rb
105
+ - lib/activerecord-postgis-adapter.rb
97
106
  - lib/rgeo/active_record/postgis_adapter/railtie.rb
98
- - lib/active_record/connection_adapters/postgis_adapter/databases.rake
107
+ - lib/active_record/connection_adapters/postgis_adapter/rails3/databases.rake
108
+ - lib/active_record/connection_adapters/postgis_adapter/rails4/databases.rake
99
109
  - test/tc_basic.rb
100
110
  - test/tc_ddl.rb
101
111
  - test/tc_nested_class.rb
102
112
  - test/tc_spatial_queries.rb
113
+ - test/tc_tasks.rb
114
+ - Documentation.rdoc
103
115
  - History.rdoc
104
116
  - README.rdoc
105
117
  - Version
@@ -132,3 +144,4 @@ test_files:
132
144
  - test/tc_ddl.rb
133
145
  - test/tc_nested_class.rb
134
146
  - test/tc_spatial_queries.rb
147
+ - test/tc_tasks.rb
@@ -1,78 +0,0 @@
1
- require 'active_record/connection_adapters/jdbcpostgresql_adapter'
2
-
3
- # Extend JDBC's PostgreSQLAdapter implementation for compatibility with
4
- # ActiveRecord's default PostgreSQLAdapter.
5
- class ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
6
- # Add `query` method for compatibility
7
- def query(*args)
8
- select_rows(*args)
9
- end
10
-
11
- # Backport from master, so PostGIS adapater will work with current stable
12
- # activerecord-jdbc-adapter gem.
13
- #
14
- # https://github.com/jruby/activerecord-jdbc-adapter/pull/200
15
- unless method_defined?(:schema_search_path=)
16
- def schema_search_path=(schema_csv)
17
- if schema_csv
18
- execute "SET search_path TO #{schema_csv}"
19
- @schema_search_path = schema_csv
20
- end
21
- end
22
- end
23
-
24
- # Backport from master, so PostGIS adapater will work with current stable
25
- # activerecord-jdbc-adapter gem.
26
- #
27
- # https://github.com/jruby/activerecord-jdbc-adapter/pull/200
28
- unless method_defined?(:schema_search_path)
29
- # Returns the active schema search path.
30
- def schema_search_path
31
- @schema_search_path ||= exec_query('SHOW search_path', 'SCHEMA')[0]['search_path']
32
- end
33
- end
34
-
35
- # For ActiveRecord 3.1 compatibility: Add the "postgis" adapter to the
36
- # matcher of jdbc-like adapters.
37
- def self.visitor_for(pool)
38
- config = pool.spec.config
39
- adapter = config[:adapter]
40
- adapter_spec = config[:adapter_spec] || self
41
- if adapter =~ /^(jdbc|jndi|postgis)$/
42
- adapter_spec.arel2_visitors(config).values.first.new(pool)
43
- else
44
- adapter_spec.arel2_visitors(config)[adapter].new(pool)
45
- end
46
- end
47
- end
48
-
49
- class ::ActiveRecord::Base
50
- class << self
51
- # ActiveRecord looks for the postgis_connection factory method in
52
- # this class.
53
- #
54
- # Based on the default `postgresql_connection` definition from
55
- # activerecord-jdbc-adapter's:
56
- # lib/arjdbc/postgresql/connection_methods.rb
57
- def postgis_connection(config)
58
- begin
59
- require 'jdbc/postgres'
60
- ::Jdbc::Postgres.load_driver(:require) if defined?(::Jdbc::Postgres.load_driver)
61
- rescue LoadError # assuming driver.jar is on the class-path
62
- end
63
- require "arjdbc/postgresql"
64
- config[:username] ||= ::Java::JavaLang::System.get_property("user.name")
65
- config[:host] ||= "localhost"
66
- config[:port] ||= 5432
67
- config[:url] ||= "jdbc:postgresql://#{config[:host]}:#{config[:port]}/#{config[:database]}"
68
- config[:url] << config[:pg_params] if config[:pg_params]
69
- config[:driver] ||= defined?(::Jdbc::Postgres.driver_name) ? ::Jdbc::Postgres.driver_name : 'org.postgresql.Driver'
70
- config[:adapter_class] = ::ActiveRecord::ConnectionAdapters::PostGISAdapter::MainAdapter
71
- config[:adapter_spec] = ::ArJdbc::PostgreSQL
72
- conn = jdbc_connection(config)
73
- conn.execute("SET SEARCH_PATH TO #{config[:schema_search_path]}") if config[:schema_search_path]
74
- conn
75
- end
76
- alias_method :jdbcpostgis_connection, :postgis_connection
77
- end
78
- end
@@ -1,27 +0,0 @@
1
- require 'pg'
2
-
3
- class ::ActiveRecord::Base
4
- # ActiveRecord looks for the postgis_connection factory method in
5
- # this class.
6
- #
7
- # Based on the default `postgresql_connection` definition from
8
- # activerecord's:
9
- # lib/active_record/connection_adapters/postgresql_adapter.rb
10
- def self.postgis_connection(config_)
11
- config_ = config_.symbolize_keys
12
- host_ = config_[:host]
13
- port_ = config_[:port] || 5432
14
- username_ = config_[:username].to_s if config_[:username]
15
- password_ = config_[:password].to_s if config_[:password]
16
-
17
- if config_.key?(:database)
18
- database_ = config_[:database]
19
- else
20
- raise ::ArgumentError, "No database specified. Missing argument: database."
21
- end
22
-
23
- # The postgres drivers don't allow the creation of an unconnected PGconn object,
24
- # so just pass a nil connection object for the time being.
25
- ::ActiveRecord::ConnectionAdapters::PostGISAdapter::MainAdapter.new(nil, logger, [host_, port_, nil, nil, database_, username_, password_], config_)
26
- end
27
- end