activerecord-postgis-adapter 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +8 -0
- data/README.rdoc +126 -71
- data/Version +1 -1
- data/lib/active_record/connection_adapters/postgis_adapter.rb +13 -379
- data/lib/active_record/connection_adapters/postgis_adapter/arel_tosql.rb +63 -0
- data/lib/{rgeo/active_record → active_record/connection_adapters}/postgis_adapter/databases.rake +1 -1
- data/lib/active_record/connection_adapters/postgis_adapter/main_adapter.rb +280 -0
- data/lib/active_record/connection_adapters/postgis_adapter/railtie.rb +64 -0
- data/lib/active_record/connection_adapters/postgis_adapter/spatial_column.rb +168 -0
- data/lib/active_record/connection_adapters/postgis_adapter/spatial_table_definition.rb +136 -0
- data/lib/active_record/connection_adapters/postgis_adapter/version.rb +62 -0
- data/lib/rgeo/active_record/postgis_adapter/railtie.rb +2 -21
- data/test/tc_basic.rb +8 -159
- data/test/tc_ddl.rb +270 -0
- data/test/tc_spatial_queries.rb +155 -0
- metadata +18 -8
@@ -0,0 +1,155 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Tests for the PostGIS ActiveRecord adapter
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
# Copyright 2010 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 TestSpatialQueries < ::Test::Unit::TestCase # :nodoc:
|
46
|
+
|
47
|
+
DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database.yml'
|
48
|
+
include AdapterTestHelper
|
49
|
+
|
50
|
+
define_test_methods do
|
51
|
+
|
52
|
+
|
53
|
+
def populate_ar_class(content_)
|
54
|
+
klass_ = create_ar_class
|
55
|
+
case content_
|
56
|
+
when :latlon_point
|
57
|
+
klass_.connection.create_table(:spatial_test) do |t_|
|
58
|
+
t_.column 'latlon', :point, :srid => 4326
|
59
|
+
end
|
60
|
+
when :latlon_point_geographic
|
61
|
+
klass_.connection.create_table(:spatial_test) do |t_|
|
62
|
+
t_.column 'latlon', :point, :srid => 4326, :geographic => true
|
63
|
+
end
|
64
|
+
when :path_linestring
|
65
|
+
klass_.connection.create_table(:spatial_test) do |t_|
|
66
|
+
t_.column 'path', :line_string, :srid => 4326
|
67
|
+
end
|
68
|
+
end
|
69
|
+
klass_
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def test_query_point
|
74
|
+
klass_ = populate_ar_class(:latlon_point)
|
75
|
+
obj_ = klass_.new
|
76
|
+
obj_.latlon = @factory.point(1, 2)
|
77
|
+
obj_.save!
|
78
|
+
id_ = obj_.id
|
79
|
+
obj2_ = klass_.where(:latlon => @factory.multi_point([@factory.point(1, 2)])).first
|
80
|
+
assert_equal(id_, obj2_.id)
|
81
|
+
obj3_ = klass_.where(:latlon => @factory.point(2, 2)).first
|
82
|
+
assert_nil(obj3_)
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
def test_query_point_wkt
|
87
|
+
klass_ = populate_ar_class(:latlon_point)
|
88
|
+
obj_ = klass_.new
|
89
|
+
obj_.latlon = @factory.point(1, 2)
|
90
|
+
obj_.save!
|
91
|
+
id_ = obj_.id
|
92
|
+
obj2_ = klass_.where(:latlon => 'SRID=4326;POINT(1 2)').first
|
93
|
+
assert_equal(id_, obj2_.id)
|
94
|
+
obj3_ = klass_.where(:latlon => 'SRID=4326;POINT(2 2)').first
|
95
|
+
assert_nil(obj3_)
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
if ::RGeo::ActiveRecord.spatial_expressions_supported?
|
100
|
+
|
101
|
+
|
102
|
+
def test_query_st_distance
|
103
|
+
klass_ = populate_ar_class(:latlon_point)
|
104
|
+
obj_ = klass_.new
|
105
|
+
obj_.latlon = @factory.point(1, 2)
|
106
|
+
obj_.save!
|
107
|
+
id_ = obj_.id
|
108
|
+
obj2_ = klass_.where(klass_.arel_table[:latlon].st_distance('SRID=4326;POINT(2 3)').lt(2)).first
|
109
|
+
assert_equal(id_, obj2_.id)
|
110
|
+
obj3_ = klass_.where(klass_.arel_table[:latlon].st_distance('SRID=4326;POINT(2 3)').gt(2)).first
|
111
|
+
assert_nil(obj3_)
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
def test_query_st_distance_from_constant
|
116
|
+
klass_ = populate_ar_class(:latlon_point)
|
117
|
+
obj_ = klass_.new
|
118
|
+
obj_.latlon = @factory.point(1, 2)
|
119
|
+
obj_.save!
|
120
|
+
id_ = obj_.id
|
121
|
+
obj2_ = klass_.where(::Arel.spatial('SRID=4326;POINT(2 3)').st_distance(klass_.arel_table[:latlon]).lt(2)).first
|
122
|
+
assert_equal(id_, obj2_.id)
|
123
|
+
obj3_ = klass_.where(::Arel.spatial('SRID=4326;POINT(2 3)').st_distance(klass_.arel_table[:latlon]).gt(2)).first
|
124
|
+
assert_nil(obj3_)
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
def test_query_st_length
|
129
|
+
klass_ = populate_ar_class(:path_linestring)
|
130
|
+
obj_ = klass_.new
|
131
|
+
obj_.path = @factory.line(@factory.point(1, 2), @factory.point(3, 2))
|
132
|
+
obj_.save!
|
133
|
+
id_ = obj_.id
|
134
|
+
obj2_ = klass_.where(klass_.arel_table[:path].st_length.eq(2)).first
|
135
|
+
assert_equal(id_, obj2_.id)
|
136
|
+
obj3_ = klass_.where(klass_.arel_table[:path].st_length.gt(3)).first
|
137
|
+
assert_nil(obj3_)
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
else
|
142
|
+
|
143
|
+
puts "WARNING: The current Arel does not support named functions. Spatial expression tests skipped."
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
- 2
|
8
7
|
- 3
|
9
|
-
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Daniel Azuma
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-26 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -23,13 +23,13 @@ dependencies:
|
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ~>
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
segments:
|
29
29
|
- 0
|
30
|
-
-
|
31
|
-
-
|
32
|
-
version: 0.
|
30
|
+
- 3
|
31
|
+
- 0
|
32
|
+
version: 0.3.0
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
@@ -57,12 +57,20 @@ extra_rdoc_files:
|
|
57
57
|
- History.rdoc
|
58
58
|
- README.rdoc
|
59
59
|
files:
|
60
|
+
- lib/active_record/connection_adapters/postgis_adapter/arel_tosql.rb
|
61
|
+
- lib/active_record/connection_adapters/postgis_adapter/main_adapter.rb
|
62
|
+
- lib/active_record/connection_adapters/postgis_adapter/railtie.rb
|
63
|
+
- lib/active_record/connection_adapters/postgis_adapter/spatial_column.rb
|
64
|
+
- lib/active_record/connection_adapters/postgis_adapter/spatial_table_definition.rb
|
65
|
+
- lib/active_record/connection_adapters/postgis_adapter/version.rb
|
60
66
|
- lib/active_record/connection_adapters/postgis_adapter.rb
|
61
67
|
- lib/rgeo/active_record/postgis_adapter/railtie.rb
|
62
|
-
- lib/
|
68
|
+
- lib/active_record/connection_adapters/postgis_adapter/databases.rake
|
63
69
|
- History.rdoc
|
64
70
|
- README.rdoc
|
65
71
|
- test/tc_basic.rb
|
72
|
+
- test/tc_ddl.rb
|
73
|
+
- test/tc_spatial_queries.rb
|
66
74
|
- Version
|
67
75
|
has_rdoc: true
|
68
76
|
homepage: http://virtuoso.rubyforge.org/activerecord-postgis-adapter
|
@@ -100,3 +108,5 @@ specification_version: 3
|
|
100
108
|
summary: An ActiveRecord adapter for PostGIS, based on RGeo.
|
101
109
|
test_files:
|
102
110
|
- test/tc_basic.rb
|
111
|
+
- test/tc_ddl.rb
|
112
|
+
- test/tc_spatial_queries.rb
|