activerecord-postgis-adapter 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,66 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # PostGIS adapter for ActiveRecord
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
+
37
+ unless defined?(::ActiveRecord::ConnectionAdapters::PostGISAdapter::Railtie)
38
+
39
+ module ActiveRecord # :nodoc:
40
+
41
+ module ConnectionAdapters # :nodoc:
42
+
43
+ module PostGISAdapter # :nodoc:
44
+
45
+
46
+ class Railtie < ::Rails::Railtie # :nodoc:
47
+
48
+ rake_tasks do
49
+ directory_ = case ::ActiveRecord::VERSION::MAJOR
50
+ when 3 then 'rails3'
51
+ when 4 then 'rails4'
52
+ else raise "Unsupported ActiveRecord version #{::ActiveRecord::VERSION::STRING}"
53
+ end
54
+ load ::File.expand_path("../#{directory_}/databases.rake", ::File.dirname(__FILE__))
55
+ end
56
+
57
+ end
58
+
59
+
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+
66
+ end
@@ -0,0 +1,57 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # PostGIS adapter for ActiveRecord
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
+
37
+ module ActiveRecord # :nodoc:
38
+
39
+ module ConnectionAdapters # :nodoc:
40
+
41
+ module PostGISAdapter # :nodoc:
42
+
43
+
44
+ def self.initial_setup
45
+ gis_ignore_tables_ = ['geometry_columns', 'spatial_ref_sys', 'layer', 'topology']
46
+ ignore_tables_ = ::ActiveRecord::SchemaDumper.ignore_tables
47
+ gis_ignore_tables_.each do |table_|
48
+ ignore_tables_ << table_ unless ignore_tables_.include?(table_)
49
+ end
50
+ end
51
+
52
+
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -48,7 +48,7 @@ module ActiveRecord
48
48
 
49
49
 
50
50
  # Current version of PostGISAdapter as a frozen string
51
- VERSION_STRING = ::File.read(::File.dirname(__FILE__)+'/../../../../Version').strip.freeze
51
+ VERSION_STRING = ::File.read(::File.expand_path('../../../../../Version', ::File.dirname(__FILE__))).strip.freeze
52
52
 
53
53
  # Current version of PostGISAdapter as a Versionomy object, if the
54
54
  # Versionomy gem is available; otherwise equal to VERSION_STRING.
@@ -0,0 +1,37 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # PostGIS adapter for ActiveRecord
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
+
37
+ require 'active_record/connection_adapters/postgis_adapter.rb'
@@ -34,6 +34,6 @@
34
34
  ;
35
35
 
36
36
 
37
- puts "WARNING: rgeo/active_record/postgis_adapter/railtie is deprecated. Please use active_record/connection_adapters/postgis_adapter/railtie."
37
+ puts 'WARNING: requiring "rgeo/active_record/postgis_adapter/railtie" is deprecated. Generally, the normal Bundle.require will do the trick. If you need to require the railtie explicitly, require "active_record/connection_adapters/postgis_adapter/railtie"'
38
38
 
39
39
  require 'active_record/connection_adapters/postgis_adapter/railtie'
data/test/tc_basic.rb CHANGED
@@ -33,7 +33,7 @@
33
33
  # -----------------------------------------------------------------------------
34
34
  ;
35
35
 
36
- require 'test/unit'
36
+ require 'minitest/autorun'
37
37
  require 'rgeo/active_record/adapter_test_helper'
38
38
 
39
39
 
@@ -42,7 +42,7 @@ module RGeo
42
42
  module PostGISAdapter # :nodoc:
43
43
  module Tests # :nodoc:
44
44
 
45
- class TestBasic < ::Test::Unit::TestCase # :nodoc:
45
+ class TestBasic < ::MiniTest::Unit::TestCase # :nodoc:
46
46
 
47
47
  DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database.yml'
48
48
  OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database_local.yml'
@@ -72,14 +72,14 @@ module RGeo
72
72
 
73
73
 
74
74
  def test_version
75
- assert_not_nil(::ActiveRecord::ConnectionAdapters::PostGISAdapter::VERSION)
75
+ refute_nil(::ActiveRecord::ConnectionAdapters::PostGISAdapter::VERSION)
76
76
  end
77
77
 
78
78
 
79
79
  def test_postgis_available
80
80
  connection_ = create_ar_class.connection
81
81
  assert_equal('PostGIS', connection_.adapter_name)
82
- assert_not_nil(connection_.postgis_lib_version)
82
+ refute_nil(connection_.postgis_lib_version)
83
83
  end
84
84
 
85
85
 
@@ -87,8 +87,8 @@ module RGeo
87
87
  klass_ = populate_ar_class(:mercator_point)
88
88
  obj_ = klass_.new
89
89
  assert_nil(obj_.latlon)
90
- obj_.latlon = @factory.point(1, 2)
91
- assert_equal(@factory.point(1, 2), obj_.latlon)
90
+ obj_.latlon = @factory.point(1.0, 2.0)
91
+ assert_equal(@factory.point(1.0, 2.0), obj_.latlon)
92
92
  assert_equal(3785, obj_.latlon.srid)
93
93
  end
94
94
 
@@ -98,7 +98,7 @@ module RGeo
98
98
  obj_ = klass_.new
99
99
  assert_nil(obj_.latlon)
100
100
  obj_.latlon = 'POINT(1 2)'
101
- assert_equal(@factory.point(1, 2), obj_.latlon)
101
+ assert_equal(@factory.point(1.0, 2.0), obj_.latlon)
102
102
  assert_equal(3785, obj_.latlon.srid)
103
103
  end
104
104
 
@@ -106,7 +106,7 @@ module RGeo
106
106
  def test_save_and_load_point
107
107
  klass_ = populate_ar_class(:mercator_point)
108
108
  obj_ = klass_.new
109
- obj_.latlon = @factory.point(1, 2)
109
+ obj_.latlon = @factory.point(1.0, 2.0)
110
110
  obj_.save!
111
111
  id_ = obj_.id
112
112
  obj2_ = klass_.find(id_)
@@ -119,7 +119,7 @@ module RGeo
119
119
  def test_save_and_load_geographic_point
120
120
  klass_ = populate_ar_class(:latlon_point_geographic)
121
121
  obj_ = klass_.new
122
- obj_.latlon = @factory.point(1, 2)
122
+ obj_.latlon = @factory.point(1.0, 2.0)
123
123
  obj_.save!
124
124
  id_ = obj_.id
125
125
  obj2_ = klass_.find(id_)
@@ -136,7 +136,7 @@ module RGeo
136
136
  obj_.save!
137
137
  id_ = obj_.id
138
138
  obj2_ = klass_.find(id_)
139
- assert_equal(@factory.point(1, 2), obj2_.latlon)
139
+ assert_equal(@factory.point(1.0, 2.0), obj2_.latlon)
140
140
  assert_equal(3785, obj2_.latlon.srid)
141
141
  end
142
142
 
@@ -148,6 +148,33 @@ module RGeo
148
148
  end
149
149
 
150
150
 
151
+ def test_set_point_wkt_wrong_type
152
+ klass_ = populate_ar_class(:mercator_point)
153
+ assert_raises(::ActiveRecord::StatementInvalid) do
154
+ klass_.create(:latlon => 'LINESTRING(1 2, 3 4, 5 6)')
155
+ end
156
+ end
157
+
158
+
159
+ def test_custom_factory
160
+ klass_ = create_ar_class
161
+ klass_.connection.create_table(:spatial_test) do |t_|
162
+ t_.point(:latlon, :srid => 4326)
163
+ end
164
+ factory_ = ::RGeo::Geographic.simple_mercator_factory
165
+ klass_.class_eval do
166
+ set_rgeo_factory_for_column(:latlon, factory_)
167
+ end
168
+ rec_ = klass_.new
169
+ rec_.latlon = 'POINT(-122 47)'
170
+ assert_equal(factory_, rec_.latlon.factory)
171
+ rec_.save!
172
+ assert_equal(factory_, rec_.latlon.factory)
173
+ rec2_ = klass_.find(rec_.id)
174
+ assert_equal(factory_, rec2_.latlon.factory)
175
+ end
176
+
177
+
151
178
  def test_readme_example
152
179
  klass_ = create_ar_class
153
180
  klass_.connection.create_table(:spatial_test) do |t_|
@@ -177,16 +204,16 @@ module RGeo
177
204
  factory1_ = ::RGeo::Cartesian.preferred_factory(:srid => 3785)
178
205
  factory2_ = ::RGeo::Cartesian.preferred_factory(:srid => 2000)
179
206
  obj_ = klass_.new
180
- obj_.geo = factory1_.point(1, 2)
207
+ obj_.geo = factory1_.point(1.0, 2.0)
181
208
  obj_.save!
182
209
  id_ = obj_.id
183
210
  obj2_ = klass_.find(id_)
184
- assert_equal(factory1_.point(1, 2), obj2_.geo)
211
+ assert_equal(factory1_.point(1.0, 2.0), obj2_.geo)
185
212
  assert_equal(3785, obj2_.geo.srid)
186
- obj2_.geo = factory2_.point(3, 4)
213
+ obj2_.geo = factory2_.point(3.0, 4.0)
187
214
  obj2_.save!
188
215
  obj3_ = klass_.find(id_)
189
- assert_equal(factory2_.point(3,4), obj3_.geo)
216
+ assert_equal(factory2_.point(3.0, 4.0), obj3_.geo)
190
217
  assert_equal(2000, obj3_.geo.srid)
191
218
  end
192
219
 
@@ -195,7 +222,7 @@ module RGeo
195
222
  klass_ = populate_ar_class(:mercator_point)
196
223
  obj_ = klass_.new
197
224
  assert_match(/"latlon":null/, obj_.to_json)
198
- obj_.latlon = @factory.point(1, 2)
225
+ obj_.latlon = @factory.point(1.0, 2.0)
199
226
  assert_match(/"latlon":"POINT\s\(1\.0\s2\.0\)"/, obj_.to_json)
200
227
  end
201
228
 
@@ -205,7 +232,7 @@ module RGeo
205
232
  rec_ = klass_.new
206
233
  rec_.latlon = 'POINT(0 0)'
207
234
  rec_.save
208
- assert_not_nil(klass_.select("CURRENT_TIMESTAMP as ts").first.ts)
235
+ refute_nil(klass_.select("CURRENT_TIMESTAMP as ts").first.ts)
209
236
  end
210
237
 
211
238
 
data/test/tc_ddl.rb CHANGED
@@ -33,7 +33,7 @@
33
33
  # -----------------------------------------------------------------------------
34
34
  ;
35
35
 
36
- require 'test/unit'
36
+ require 'minitest/autorun'
37
37
  require 'rgeo/active_record/adapter_test_helper'
38
38
 
39
39
 
@@ -42,7 +42,7 @@ module RGeo
42
42
  module PostGISAdapter # :nodoc:
43
43
  module Tests # :nodoc:
44
44
 
45
- class TestDDL < ::Test::Unit::TestCase # :nodoc:
45
+ class TestDDL < ::MiniTest::Unit::TestCase # :nodoc:
46
46
 
47
47
  DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database.yml'
48
48
  OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database_local.yml'
@@ -33,7 +33,7 @@
33
33
  # -----------------------------------------------------------------------------
34
34
  ;
35
35
 
36
- require 'test/unit'
36
+ require 'minitest/autorun'
37
37
  require 'rgeo/active_record/adapter_test_helper'
38
38
 
39
39
 
@@ -42,7 +42,7 @@ module RGeo
42
42
  module PostGISAdapter # :nodoc:
43
43
  module Tests # :nodoc:
44
44
 
45
- class TestNestedClass < ::Test::Unit::TestCase # :nodoc:
45
+ class TestNestedClass < ::MiniTest::Unit::TestCase # :nodoc:
46
46
 
47
47
  DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database.yml'
48
48
  OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database_local.yml'
@@ -33,7 +33,7 @@
33
33
  # -----------------------------------------------------------------------------
34
34
  ;
35
35
 
36
- require 'test/unit'
36
+ require 'minitest/autorun'
37
37
  require 'rgeo/active_record/adapter_test_helper'
38
38
 
39
39
 
@@ -42,7 +42,7 @@ module RGeo
42
42
  module PostGISAdapter # :nodoc:
43
43
  module Tests # :nodoc:
44
44
 
45
- class TestSpatialQueries < ::Test::Unit::TestCase # :nodoc:
45
+ class TestSpatialQueries < ::MiniTest::Unit::TestCase # :nodoc:
46
46
 
47
47
  DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database.yml'
48
48
  OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database_local.yml'
@@ -74,12 +74,13 @@ module RGeo
74
74
  def test_query_point
75
75
  klass_ = populate_ar_class(:mercator_point)
76
76
  obj_ = klass_.new
77
- obj_.latlon = @factory.point(1, 2)
77
+ obj_.latlon = @factory.point(1.0, 2.0)
78
78
  obj_.save!
79
79
  id_ = obj_.id
80
- obj2_ = klass_.where(:latlon => @factory.multi_point([@factory.point(1, 2)])).first
80
+ obj2_ = klass_.where(:latlon => @factory.multi_point([@factory.point(1.0, 2.0)])).first
81
+ refute_nil(obj2_)
81
82
  assert_equal(id_, obj2_.id)
82
- obj3_ = klass_.where(:latlon => @factory.point(2, 2)).first
83
+ obj3_ = klass_.where(:latlon => @factory.point(2.0, 2.0)).first
83
84
  assert_nil(obj3_)
84
85
  end
85
86
 
@@ -87,10 +88,11 @@ module RGeo
87
88
  def test_query_point_wkt
88
89
  klass_ = populate_ar_class(:mercator_point)
89
90
  obj_ = klass_.new
90
- obj_.latlon = @factory.point(1, 2)
91
+ obj_.latlon = @factory.point(1.0, 2.0)
91
92
  obj_.save!
92
93
  id_ = obj_.id
93
94
  obj2_ = klass_.where(:latlon => 'SRID=3785;POINT(1 2)').first
95
+ refute_nil(obj2_)
94
96
  assert_equal(id_, obj2_.id)
95
97
  obj3_ = klass_.where(:latlon => 'SRID=3785;POINT(2 2)').first
96
98
  assert_nil(obj3_)
@@ -103,10 +105,11 @@ module RGeo
103
105
  def test_query_st_distance
104
106
  klass_ = populate_ar_class(:mercator_point)
105
107
  obj_ = klass_.new
106
- obj_.latlon = @factory.point(1, 2)
108
+ obj_.latlon = @factory.point(1.0, 2.0)
107
109
  obj_.save!
108
110
  id_ = obj_.id
109
111
  obj2_ = klass_.where(klass_.arel_table[:latlon].st_distance('SRID=3785;POINT(2 3)').lt(2)).first
112
+ refute_nil(obj2_)
110
113
  assert_equal(id_, obj2_.id)
111
114
  obj3_ = klass_.where(klass_.arel_table[:latlon].st_distance('SRID=3785;POINT(2 3)').gt(2)).first
112
115
  assert_nil(obj3_)
@@ -116,10 +119,11 @@ module RGeo
116
119
  def test_query_st_distance_from_constant
117
120
  klass_ = populate_ar_class(:mercator_point)
118
121
  obj_ = klass_.new
119
- obj_.latlon = @factory.point(1, 2)
122
+ obj_.latlon = @factory.point(1.0, 2.0)
120
123
  obj_.save!
121
124
  id_ = obj_.id
122
125
  obj2_ = klass_.where(::Arel.spatial('SRID=3785;POINT(2 3)').st_distance(klass_.arel_table[:latlon]).lt(2)).first
126
+ refute_nil(obj2_)
123
127
  assert_equal(id_, obj2_.id)
124
128
  obj3_ = klass_.where(::Arel.spatial('SRID=3785;POINT(2 3)').st_distance(klass_.arel_table[:latlon]).gt(2)).first
125
129
  assert_nil(obj3_)
@@ -129,10 +133,11 @@ module RGeo
129
133
  def test_query_st_length
130
134
  klass_ = populate_ar_class(:path_linestring)
131
135
  obj_ = klass_.new
132
- obj_.path = @factory.line(@factory.point(1, 2), @factory.point(3, 2))
136
+ obj_.path = @factory.line(@factory.point(1.0, 2.0), @factory.point(3.0, 2.0))
133
137
  obj_.save!
134
138
  id_ = obj_.id
135
139
  obj2_ = klass_.where(klass_.arel_table[:path].st_length.eq(2)).first
140
+ refute_nil(obj2_)
136
141
  assert_equal(id_, obj2_.id)
137
142
  obj3_ = klass_.where(klass_.arel_table[:path].st_length.gt(3)).first
138
143
  assert_nil(obj3_)