activerecord-postgis-adapter 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,20 @@
1
+ === 0.5.0 / 2012-12-12
2
+
3
+ Thanks to the many who have submitted pull requests. A bunch of them are in this release. Special thanks to Nick Muerdter, who succeeded in porting the adapter to work with the JDBC Postgres adapter in JRuby, and also got Travis up and running for the project.
4
+
5
+ * Add JRuby compatibility with the activerecord-jdbcpostgresql-adapter gem. (Pull request by Nick Muerdter)
6
+ * Allow WKT to be to be specified as a string-like object rather than having to be a String. (Pull request by Bryan Larsen)
7
+ * Ignore postgis_topology tables 'layer' and 'topology' in rake db:schema:dump. (Pull request by Greg Phillips)
8
+ * Create schemas specified in schema_search_path only if they don't exist. (Pull request by legendetm)
9
+ * Force the postgis_topology extension be created in the topology schema. (Pull request by Dimitri Roche)
10
+ * Specifically set the ownership of the postgis related tables to the regular user. (Pull request by corneverbruggen)
11
+ * The gemspec no longer includes the timestamp in the version, so that bundler can pull from github. (Reported by corneverbruggen)
12
+ * Update tests for PostGIS 2.0 compatibility.
13
+ * Travis-CI integration. (Pull request by Nick Muerdter)
14
+ * Add a missing srid in the Readme. (Pull request by gouthamvel)
15
+ * Readme clarifies that BoundingBox objects can be used in a query only for projected coordinate systems. (Reported by Tee Parham)
16
+ * Update URLs to point to new website.
17
+
1
18
  === 0.4.3 / 2012-04-13
2
19
 
3
20
  * Rake tasks failed on Rails 3.0.x because of an issue with rgeo-activerecord pre-0.4.5. Now we require the fixed version.
@@ -36,10 +36,10 @@ Examples:
36
36
  create_table :my_spatial_table do |t|
37
37
  t.column :shape, :geometry # or t.geometry :shape
38
38
  t.line_string :path, :srid => 3785
39
- t.point :latlon, :geographic => true
39
+ t.point :lonlat, :geographic => true
40
40
  end
41
41
  change_table :my_spatial_table do |t|
42
- t.index :latlon, :spatial => true
42
+ t.index :lonlat, :spatial => true
43
43
  end
44
44
 
45
45
  === Spatial Attributes
@@ -71,16 +71,16 @@ Examples, given the spatial table defined above:
71
71
  # By default, use the GEOS implementation for spatial columns.
72
72
  self.rgeo_factory_generator = RGeo::Geos.factory_generator
73
73
 
74
- # But use a geographic implementation for the :latlon column.
75
- set_rgeo_factory_for_column(:latlon, RGeo::Geographic.spherical_factory)
74
+ # But use a geographic implementation for the :lonlat column.
75
+ set_rgeo_factory_for_column(:lonlat, RGeo::Geographic.spherical_factory(:srid => 4326))
76
76
 
77
77
  end
78
78
 
79
79
  Now you can interact with the data using the RGeo types:
80
80
 
81
81
  rec = MySpatialTable.new
82
- rec.latlon = 'POINT(-122 47)' # You can set by feature object or WKT.
83
- loc = rec.latlon # Accessing always returns a feature object, in
82
+ rec.lonlat = 'POINT(-122 47)' # You can set by feature object or WKT.
83
+ loc = rec.lonlat # Accessing always returns a feature object, in
84
84
  # this case, a geographic that understands latitude.
85
85
  loc.latitude # => 47
86
86
  rec.shape = loc # the factory for the :shape column is GEOS, so the
@@ -92,11 +92,11 @@ Now you can interact with the data using the RGeo types:
92
92
  You can create simple queries based on objective equality in the same way
93
93
  you would on a scalar column:
94
94
 
95
- rec = MySpatialTable.where(:latlon => RGeo::Geos.factory.point(-122, 47)).first
95
+ rec = MySpatialTable.where(:lonlat => RGeo::Geos.factory.point(-122, 47)).first
96
96
 
97
97
  You can also use WKT:
98
98
 
99
- rec = MySpatialTable.where(:latlon => 'POINT(-122 47)').first
99
+ rec = MySpatialTable.where(:lonlat => 'POINT(-122 47)').first
100
100
 
101
101
  Most more complex spatial queries require the use of SQL functions. You
102
102
  can write such queries in raw SQL, but you may find the "squeel" gem
@@ -104,17 +104,23 @@ very helpful in this regard. Using squeel, you can write queries like
104
104
  the following:
105
105
 
106
106
  my_polygon = get_my_polygon()
107
- MySpatialTable.where{st_intersects(latlon, my_polygon)}.first
107
+ MySpatialTable.where{st_intersects(lonlat, my_polygon)}.first
108
+
109
+ Note that using squeel to create SQL functions requires Rails 3.1 or later.
108
110
 
109
111
  One common query is to find all objects displaying in a window. This can
110
- be done using the overlap (&&) operator with a bounding box, as follows:
112
+ be done using the overlap (&&) operator with a bounding box. Here's an
113
+ example that finds linestrings in the "path" column that intersect a
114
+ bounding box:
111
115
 
112
- sw = get_sw_corner()
113
- ne = get_ne_corner()
116
+ sw = get_sw_corner_in_projected_coordinates()
117
+ ne = get_ne_corner_in_projected_coordinates()
114
118
  window = RGeo::Cartesian::BoundingBox.create_from_points(sw, ne)
115
- MySpatialTable.where{latlon.op('&&', window)}.all
119
+ MySpatialTable.where{path.op('&&', window)}.all
116
120
 
117
- Note that using squeel to create SQL functions requires Rails 3.1 or later.
121
+ Note that bounding box queries make sense only in a projected coordinate
122
+ system; you shouldn't try to run such a query against a lat/long
123
+ (geographic) column.
118
124
 
119
125
  == Installation And Configuration
120
126
 
@@ -122,14 +128,15 @@ Note that using squeel to create SQL functions requires Rails 3.1 or later.
122
128
 
123
129
  This adapter has the following requirements:
124
130
 
125
- * Ruby 1.8.7 or later. Ruby 1.9.2 or later preferred.
131
+ * Ruby 1.8.7 or later. Ruby 1.9.2 or later preferred. JRuby 1.6.3 or later also supported.
126
132
  * PostgreSQL 9.0 or later.
127
- * PostGIS 1.5 or later.
128
- * pg gem 0.11 or later.
133
+ * PostGIS 1.5, PostGIS 2.0, or later.
129
134
  * \ActiveRecord 3.0.3 or later. Earlier versions will not work.
130
135
  Should be compatible with Rails versions through 3.2.x.
131
- * rgeo gem 0.3.10 or later.
132
- * rgeo-activerecord gem 0.4.4 or later.
136
+ * rgeo gem 0.3.20 or later.
137
+ * rgeo-activerecord gem 0.4.6 or later.
138
+
139
+ Please note that this version of the adapter is targeted towards Rails 3.x only. The upcoming version 0.6 will target Rails 4.0.
133
140
 
134
141
  Install this adapter as a gem:
135
142
 
@@ -172,7 +179,7 @@ database. Generally, the value should be set to true, although you can
172
179
  also set it to a comma-delimited list of extension names (which should
173
180
  include the base "postgis" extension) if you want to customize which
174
181
  extensions are installed. This is the easiest and cleanest way to create
175
- a PostGIS-enabled database, but it requires PostgreSQL 9.1 or later and
182
+ a PostGIS-enabled database, but it requires PostgreSQL 9.1 or later AND
176
183
  PostGIS 2.0 or later.
177
184
 
178
185
  The <i>script_dir</i> parameter is specific to the PostGIS adapter, and
@@ -278,10 +285,14 @@ current known issues.
278
285
  * Other rake tasks may not be supported. Unfortunately, Rails makes it
279
286
  difficult for custom \ActiveRecord adapters to support the standard
280
287
  rake tasks.
288
+ * Rails 4 is not yet supported. The good news is that the base PostgreSQL
289
+ adapter has been refactored in Rails 4 to make it easier to extend, so
290
+ once we get it ported to Rails 4, activerecord-postgis-adapter should
291
+ be cleaner and more stable.
281
292
 
282
293
  === Development and support
283
294
 
284
- Documentation is available at http://virtuoso.rubyforge.org/activerecord-postgis-adapter/README_rdoc.html
295
+ Documentation is available at http://dazuma.github.com/activerecord-postgis-adapter/rdoc
285
296
 
286
297
  Source code is hosted on Github at http://github.com/dazuma/activerecord-postgis-adapter
287
298
 
@@ -298,7 +309,7 @@ Contact the author at dazuma at gmail dot com.
298
309
  The PostGIS Adapter and its supporting libraries (including RGeo) are
299
310
  written by Daniel Azuma (http://www.daniel-azuma.com).
300
311
 
301
- Development is supported by Pirq. (http://www.pirq.com).
312
+ Development is supported by Pirq. (http://pirq.com).
302
313
 
303
314
  This adapter implementation owes some debt to the spatial_adapter plugin
304
315
  (http://github.com/fragility/spatial_adapter). Although we made some
data/Version CHANGED
@@ -1 +1 @@
1
- 0.4.3
1
+ 0.5.0
@@ -35,7 +35,12 @@
35
35
 
36
36
 
37
37
  require 'rgeo/active_record'
38
- require 'active_record/connection_adapters/postgresql_adapter'
38
+
39
+ if defined?(::RUBY_ENGINE) && ::RUBY_ENGINE == 'jruby'
40
+ require 'active_record/connection_adapters/postgis_adapter/jdbc_connection'
41
+ else
42
+ require 'active_record/connection_adapters/postgis_adapter/pg_connection'
43
+ end
39
44
 
40
45
 
41
46
  # The activerecord-postgis-adapter gem installs the *postgis*
@@ -43,38 +48,6 @@ require 'active_record/connection_adapters/postgresql_adapter'
43
48
 
44
49
  module ActiveRecord
45
50
 
46
-
47
- # ActiveRecord looks for the postgis_connection factory method in
48
- # this class.
49
-
50
- class Base
51
-
52
-
53
- # Create a postgis connection adapter.
54
-
55
- def self.postgis_connection(config_)
56
- require 'pg'
57
-
58
- config_ = config_.symbolize_keys
59
- host_ = config_[:host]
60
- port_ = config_[:port] || 5432
61
- username_ = config_[:username].to_s if config_[:username]
62
- password_ = config_[:password].to_s if config_[:password]
63
- if config_.has_key?(:database)
64
- database_ = config_[:database]
65
- else
66
- raise ::ArgumentError, "No database specified. Missing argument: database."
67
- end
68
-
69
- # The postgres drivers don't allow the creation of an unconnected PGconn object,
70
- # so just pass a nil connection object for the time being.
71
- ::ActiveRecord::ConnectionAdapters::PostGISAdapter::MainAdapter.new(nil, logger, [host_, port_, nil, nil, database_, username_, password_], config_)
72
- end
73
-
74
-
75
- end
76
-
77
-
78
51
  # All ActiveRecord adapters go in this namespace.
79
52
  module ConnectionAdapters
80
53
 
@@ -102,3 +75,5 @@ require 'active_record/connection_adapters/postgis_adapter/arel_tosql.rb'
102
75
  ignore_tables_ = ::ActiveRecord::SchemaDumper.ignore_tables
103
76
  ignore_tables_ << 'geometry_columns' unless ignore_tables_.include?('geometry_columns')
104
77
  ignore_tables_ << 'spatial_ref_sys' unless ignore_tables_.include?('spatial_ref_sys')
78
+ ignore_tables_ << 'layer' unless ignore_tables_.include?('layer')
79
+ ignore_tables_ << 'topology' unless ignore_tables_.include?('topology')
@@ -68,13 +68,18 @@ def create_database(config_)
68
68
  search_path_ = search_path_.split(",").map{ |sp_| sp_.strip }
69
69
  auth_ = has_su_ ? " AUTHORIZATION #{username_}" : ''
70
70
  search_path_.each do |schema_|
71
- conn_.execute("CREATE SCHEMA #{schema_}#{auth_}") unless schema_.downcase == 'public'
71
+ exists = schema_.downcase == 'public' || conn_.execute("SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='#{schema_}'").try(:first)
72
+ conn_.execute("CREATE SCHEMA #{schema_}#{auth_}") unless exists
72
73
  end
73
74
 
74
75
  # Install postgis definitions into the database.
75
76
  # Note: a superuser is required to run the postgis definitions.
76
77
  # If a separate superuser is provided, we need to grant privileges on
77
78
  # the postgis definitions over to the regular user afterwards.
79
+ # We also need to set the ownership of the postgis tables (spatial_ref_sys
80
+ # and geometry_columns) to the regular user. This is required to e.g.
81
+ # be able to disable referential integrity on the database when using
82
+ # a database cleaner truncation strategy during testing.
78
83
  # The schema for the postgis definitions is chosen as follows:
79
84
  # If "postgis" is present in the search path, use it.
80
85
  # Otherwise, use the last schema in the search path.
@@ -93,12 +98,19 @@ def create_database(config_)
93
98
  postgis_extension_ = 'postgis' if postgis_extension_ == true
94
99
  postgis_extension_ = postgis_extension_.to_s.split(',') unless postgis_extension_.is_a?(::Array)
95
100
  postgis_extension_.each do |extname_|
96
- conn_.execute("CREATE EXTENSION #{extname_} SCHEMA #{postgis_schema_}")
101
+ if extname_ == 'postgis_topology'
102
+ raise ArgumentError, "'topology' must be in schema_search_path for postgis_topology" unless search_path_.include?('topology')
103
+ conn_.execute("CREATE EXTENSION #{extname_} SCHEMA topology")
104
+ else
105
+ conn_.execute("CREATE EXTENSION #{extname_} SCHEMA #{postgis_schema_}")
106
+ end
97
107
  end
98
108
  end
99
109
  if has_su_
100
110
  conn_.execute("GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA #{postgis_schema_} TO #{username_}")
101
111
  conn_.execute("GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA #{postgis_schema_} TO #{username_}")
112
+ conn_.execute("ALTER TABLE geometry_columns OWNER TO #{username_}")
113
+ conn_.execute("ALTER TABLE spatial_ref_sys OWNER TO #{username_}")
102
114
  end
103
115
  end
104
116
 
@@ -0,0 +1,69 @@
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
+ # ActiveRecord looks for the postgis_connection factory method in
51
+ # this class.
52
+ #
53
+ # Based on the default `postgresql_connection` definition from
54
+ # activerecord-jdbc-adapter's:
55
+ # lib/arjdbc/postgresql/connection_methods.rb
56
+ def self.postgis_connection(config)
57
+ require "arjdbc/postgresql"
58
+ config[:host] ||= "localhost"
59
+ config[:port] ||= 5432
60
+ config[:url] ||= "jdbc:postgresql://#{config[:host]}:#{config[:port]}/#{config[:database]}"
61
+ config[:url] << config[:pg_params] if config[:pg_params]
62
+ config[:driver] ||= "org.postgresql.Driver"
63
+ config[:adapter_class] = ::ActiveRecord::ConnectionAdapters::PostGISAdapter::MainAdapter
64
+ config[:adapter_spec] = ::ArJdbc::PostgreSQL
65
+ conn = jdbc_connection(config)
66
+ conn.execute("SET SEARCH_PATH TO #{config[:schema_search_path]}") if config[:schema_search_path]
67
+ conn
68
+ end
69
+ end
@@ -121,6 +121,15 @@ module ActiveRecord
121
121
  table_name_ = table_name_.to_s
122
122
  spatial_info_ = spatial_column_info(table_name_)
123
123
  column_definitions(table_name_).collect do |col_name_, type_, default_, notnull_|
124
+ # JDBC support: JDBC adapter returns a hash for column definitions,
125
+ # instead of an array of values.
126
+ if col_name_.kind_of?(::Hash)
127
+ notnull_ = col_name_["column_not_null"]
128
+ default_ = col_name_["column_default"]
129
+ type_ = col_name_["column_type"]
130
+ col_name_ = col_name_["column_name"]
131
+ end
132
+
124
133
  SpatialColumn.new(@rgeo_factory_settings, table_name_, col_name_, default_, type_,
125
134
  notnull_ == 'f', type_ =~ /geometry/i ? spatial_info_[col_name_] : nil)
126
135
  end
@@ -157,7 +166,7 @@ module ActiveRecord
157
166
  oid_ = row_[3]
158
167
  indtype_ = row_[4]
159
168
 
160
- columns_ = query(<<-SQL, "Columns for index #{row_[0]} on #{table_name_}").inject({}){ |h_, r_| h_[r_[0]] = [r_[1], r_[2]]; h_ }
169
+ columns_ = query(<<-SQL, "Columns for index #{row_[0]} on #{table_name_}").inject({}){ |h_, r_| h_[r_[0].to_s] = [r_[1], r_[2]]; h_ }
161
170
  SELECT a.attnum, a.attname, t.typname
162
171
  FROM pg_attribute a, pg_type t
163
172
  WHERE a.attrelid = #{oid_}
@@ -0,0 +1,28 @@
1
+ require 'active_record/connection_adapters/postgresql_adapter'
2
+ require 'pg'
3
+
4
+ class ::ActiveRecord::Base
5
+ # ActiveRecord looks for the postgis_connection factory method in
6
+ # this class.
7
+ #
8
+ # Based on the default `postgresql_connection` definition from
9
+ # activerecord's:
10
+ # lib/active_record/connection_adapters/postgresql_adapter.rb
11
+ def self.postgis_connection(config_)
12
+ config_ = config_.symbolize_keys
13
+ host_ = config_[:host]
14
+ port_ = config_[:port] || 5432
15
+ username_ = config_[:username].to_s if config_[:username]
16
+ password_ = config_[:password].to_s if config_[:password]
17
+
18
+ if config_.key?(:database)
19
+ database_ = config_[:database]
20
+ else
21
+ raise ::ArgumentError, "No database specified. Missing argument: database."
22
+ end
23
+
24
+ # The postgres drivers don't allow the creation of an unconnected PGconn object,
25
+ # so just pass a nil connection object for the time being.
26
+ ::ActiveRecord::ConnectionAdapters::PostGISAdapter::MainAdapter.new(nil, logger, [host_, port_, nil, nil, database_, username_, password_], config_)
27
+ end
28
+ end
@@ -165,11 +165,11 @@ module ActiveRecord
165
165
  else
166
166
  constraints_ = nil
167
167
  end
168
- case input_
169
- when ::RGeo::Feature::Geometry
168
+ if ::RGeo::Feature::Geometry === input_
170
169
  factory_ = factory_settings_.get_column_factory(table_name_, column_, constraints_)
171
170
  ::RGeo::Feature.cast(input_, factory_) rescue nil
172
- when ::String
171
+ elsif input_.respond_to?(:to_str)
172
+ input_ = input_.to_str
173
173
  if input_.length == 0
174
174
  nil
175
175
  else
@@ -45,6 +45,7 @@ module RGeo
45
45
  class TestBasic < ::Test::Unit::TestCase # :nodoc:
46
46
 
47
47
  DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database.yml'
48
+ OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database_local.yml'
48
49
  include AdapterTestHelper
49
50
 
50
51
  define_test_methods do
@@ -170,7 +171,8 @@ module RGeo
170
171
  end
171
172
 
172
173
 
173
- def test_save_and_load_no_constraints
174
+ # no_constraints no longer supported in PostGIS 2.0
175
+ def _test_save_and_load_no_constraints
174
176
  klass_ = populate_ar_class(:no_constraints)
175
177
  factory1_ = ::RGeo::Cartesian.preferred_factory(:srid => 3785)
176
178
  factory2_ = ::RGeo::Cartesian.preferred_factory(:srid => 2000)
@@ -198,6 +200,15 @@ module RGeo
198
200
  end
199
201
 
200
202
 
203
+ def test_custom_column
204
+ klass_ = populate_ar_class(:mercator_point)
205
+ rec_ = klass_.new
206
+ rec_.latlon = 'POINT(0 0)'
207
+ rec_.save
208
+ assert_not_nil(klass_.select("CURRENT_TIMESTAMP as ts").first.ts)
209
+ end
210
+
211
+
201
212
  end
202
213
 
203
214
  end
@@ -45,6 +45,7 @@ module RGeo
45
45
  class TestDDL < ::Test::Unit::TestCase # :nodoc:
46
46
 
47
47
  DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database.yml'
48
+ OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database_local.yml'
48
49
  include AdapterTestHelper
49
50
 
50
51
  define_test_methods do
@@ -60,14 +61,15 @@ module RGeo
60
61
  assert_equal(::RGeo::Feature::Geometry, col_.geometric_type)
61
62
  assert_equal(true, col_.has_spatial_constraints?)
62
63
  assert_equal(false, col_.geographic?)
63
- assert_equal(-1, col_.srid)
64
+ assert_equal(if(klass_.connection.postgis_lib_version >= "2") then 0 else -1 end, col_.srid)
64
65
  assert(klass_.cached_attributes.include?('latlon'))
65
66
  klass_.connection.drop_table(:spatial_test)
66
67
  assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
67
68
  end
68
69
 
69
70
 
70
- def test_create_no_constraints_geometry
71
+ # no_constraints no longer supported in PostGIS 2.0
72
+ def _test_create_no_constraints_geometry
71
73
  klass_ = create_ar_class
72
74
  klass_.connection.create_table(:spatial_test) do |t_|
73
75
  t_.column 'geom', :geometry, :limit => {:no_constraints => true}
@@ -133,7 +135,7 @@ module RGeo
133
135
  assert_equal(2, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
134
136
  cols_ = klass_.columns
135
137
  assert_equal(::RGeo::Feature::Geometry, cols_[-3].geometric_type)
136
- assert_equal(-1, cols_[-3].srid)
138
+ assert_equal(if(klass_.connection.postgis_lib_version >= "2") then 0 else -1 end, cols_[-3].srid)
137
139
  assert_equal(true, cols_[-3].has_spatial_constraints?)
138
140
  assert_equal(::RGeo::Feature::Point, cols_[-2].geometric_type)
139
141
  assert_equal(4326, cols_[-2].srid)
@@ -144,7 +146,8 @@ module RGeo
144
146
  end
145
147
 
146
148
 
147
- def test_add_no_constraints_geometry_column
149
+ # no_constraints no longer supported in PostGIS 2.0
150
+ def _test_add_no_constraints_geometry_column
148
151
  klass_ = create_ar_class
149
152
  klass_.connection.create_table(:spatial_test) do |t_|
150
153
  t_.column('latlon', :geometry)
@@ -156,7 +159,7 @@ module RGeo
156
159
  assert_equal(1, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
157
160
  cols_ = klass_.columns
158
161
  assert_equal(::RGeo::Feature::Geometry, cols_[-3].geometric_type)
159
- assert_equal(-1, cols_[-3].srid)
162
+ assert_equal(if(klass_.connection.postgis_lib_version >= "2") then 0 else -1 end, cols_[-3].srid)
160
163
  assert_equal(true, cols_[-3].has_spatial_constraints?)
161
164
  assert_equal(::RGeo::Feature::Geometry, cols_[-2].geometric_type)
162
165
  assert_nil(cols_[-2].srid)
@@ -179,7 +182,7 @@ module RGeo
179
182
  assert_equal(1, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
180
183
  cols_ = klass_.columns
181
184
  assert_equal(::RGeo::Feature::Geometry, cols_[-3].geometric_type)
182
- assert_equal(-1, cols_[-3].srid)
185
+ assert_equal(if(klass_.connection.postgis_lib_version >= "2") then 0 else -1 end, cols_[-3].srid)
183
186
  assert_equal(true, cols_[-3].has_spatial_constraints?)
184
187
  assert_equal(::RGeo::Feature::Point, cols_[-2].geometric_type)
185
188
  assert_equal(4326, cols_[-2].srid)
@@ -203,7 +206,7 @@ module RGeo
203
206
  cols_ = klass_.columns
204
207
  assert_equal(::RGeo::Feature::Geometry, cols_[-1].geometric_type)
205
208
  assert_equal('latlon', cols_[-1].name)
206
- assert_equal(-1, cols_[-1].srid)
209
+ assert_equal(if(klass_.connection.postgis_lib_version >= "2") then 0 else -1 end, cols_[-1].srid)
207
210
  assert_equal(false, cols_[-1].geographic?)
208
211
  end
209
212
 
@@ -238,14 +241,15 @@ module RGeo
238
241
  col_ = klass_.columns.last
239
242
  assert_equal(::RGeo::Feature::Geometry, col_.geometric_type)
240
243
  assert_equal(false, col_.geographic?)
241
- assert_equal(-1, col_.srid)
244
+ assert_equal(if(klass_.connection.postgis_lib_version >= "2") then 0 else -1 end, col_.srid)
242
245
  assert(klass_.cached_attributes.include?('latlon'))
243
246
  klass_.connection.drop_table(:spatial_test)
244
247
  assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
245
248
  end
246
249
 
247
250
 
248
- def test_create_no_constraints_geometry_using_shortcut
251
+ # no_constraints no longer supported in PostGIS 2.0
252
+ def _test_create_no_constraints_geometry_using_shortcut
249
253
  klass_ = create_ar_class
250
254
  klass_.connection.create_table(:spatial_test) do |t_|
251
255
  t_.spatial 'geom', :no_constraints => true
@@ -0,0 +1,83 @@
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 'test/unit'
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 TestNestedClass < ::Test::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
+ include AdapterTestHelper
50
+
51
+
52
+ module Foo
53
+ def self.table_name_prefix
54
+ 'foo_'
55
+ end
56
+ class Bar < ::ActiveRecord::Base
57
+ end
58
+ end
59
+
60
+
61
+ define_test_methods do
62
+
63
+
64
+ def test_nested_model
65
+ Foo::Bar.class_eval do
66
+ establish_connection(TestNestedClass::DATABASE_CONFIG)
67
+ end
68
+ Foo::Bar.connection.create_table(:foo_bars) do |t_|
69
+ t_.column 'latlon', :point, :srid => 3785
70
+ end
71
+ Foo::Bar.all
72
+ Foo::Bar.connection.drop_table(:foo_bars)
73
+ end
74
+
75
+
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+ end
82
+ end
83
+ end
@@ -45,6 +45,7 @@ module RGeo
45
45
  class TestSpatialQueries < ::Test::Unit::TestCase # :nodoc:
46
46
 
47
47
  DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database.yml'
48
+ OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database_local.yml'
48
49
  include AdapterTestHelper
49
50
 
50
51
  define_test_methods do
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.4.3
4
+ version: 0.5.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: 2012-04-13 00:00:00.000000000 Z
12
+ date: 2012-12-12 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.5
21
+ version: 0.4.6
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,23 +26,55 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 0.4.5
29
+ version: 0.4.6
30
30
  - !ruby/object:Gem::Dependency
31
- name: pg
31
+ name: appraisal
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
35
  - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: 0.11.0
38
- type: :runtime
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rdoc
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
39
71
  prerelease: false
40
72
  version_requirements: !ruby/object:Gem::Requirement
41
73
  none: false
42
74
  requirements:
43
75
  - - ! '>='
44
76
  - !ruby/object:Gem::Version
45
- version: 0.11.0
77
+ version: '0'
46
78
  description: This is an ActiveRecord connection adapter for PostGIS. It is based on
47
79
  the stock PostgreSQL adapter, but provides built-in support for the spatial extensions
48
80
  provided by PostGIS. It uses the RGeo library to represent spatial data in Ruby.
@@ -54,7 +86,9 @@ extra_rdoc_files:
54
86
  - README.rdoc
55
87
  files:
56
88
  - lib/active_record/connection_adapters/postgis_adapter/arel_tosql.rb
89
+ - lib/active_record/connection_adapters/postgis_adapter/jdbc_connection.rb
57
90
  - lib/active_record/connection_adapters/postgis_adapter/main_adapter.rb
91
+ - lib/active_record/connection_adapters/postgis_adapter/pg_connection.rb
58
92
  - lib/active_record/connection_adapters/postgis_adapter/railtie.rb
59
93
  - lib/active_record/connection_adapters/postgis_adapter/spatial_column.rb
60
94
  - lib/active_record/connection_adapters/postgis_adapter/spatial_table_definition.rb
@@ -64,11 +98,12 @@ files:
64
98
  - lib/active_record/connection_adapters/postgis_adapter/databases.rake
65
99
  - test/tc_basic.rb
66
100
  - test/tc_ddl.rb
101
+ - test/tc_nested_class.rb
67
102
  - test/tc_spatial_queries.rb
68
103
  - History.rdoc
69
104
  - README.rdoc
70
105
  - Version
71
- homepage: http://virtuoso.rubyforge.org/activerecord-postgis-adapter
106
+ homepage: http://dazuma.github.com/activerecord-postgis-adapter
72
107
  licenses: []
73
108
  post_install_message:
74
109
  rdoc_options: []
@@ -88,11 +123,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
123
  version: 1.3.1
89
124
  requirements: []
90
125
  rubyforge_project: virtuoso
91
- rubygems_version: 1.8.19
126
+ rubygems_version: 1.8.24
92
127
  signing_key:
93
128
  specification_version: 3
94
129
  summary: An ActiveRecord adapter for PostGIS, based on RGeo.
95
130
  test_files:
96
131
  - test/tc_basic.rb
97
132
  - test/tc_ddl.rb
133
+ - test/tc_nested_class.rb
98
134
  - test/tc_spatial_queries.rb