activerecord-spatialite-adapter 0.2.3 → 0.3.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.
@@ -0,0 +1,165 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Tests for the MysqlSpatial 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 SpatiaLiteAdapter # :nodoc:
43
+ module Tests # :nodoc:
44
+
45
+ class TestSpatialQueries < ::Test::Unit::TestCase # :nodoc:
46
+
47
+
48
+ DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database.yml'
49
+
50
+ def self.before_open_database(params_)
51
+ database_ = params_[:config][:database]
52
+ dir_ = ::File.dirname(database_)
53
+ ::FileUtils.mkdir_p(dir_) unless dir_ == '.'
54
+ ::FileUtils.rm_f(database_)
55
+ end
56
+
57
+ def self.initialize_database(params_)
58
+ params_[:connection].execute('SELECT InitSpatialMetaData()')
59
+ end
60
+
61
+ include AdapterTestHelper
62
+
63
+
64
+ define_test_methods do
65
+
66
+
67
+ def populate_ar_class(content_)
68
+ klass_ = create_ar_class
69
+ case content_
70
+ when :latlon_point
71
+ klass_.connection.create_table(:spatial_test) do |t_|
72
+ t_.column 'latlon', :point, :srid => 4326
73
+ end
74
+ when :path_linestring
75
+ klass_.connection.create_table(:spatial_test) do |t_|
76
+ t_.column 'path', :line_string, :srid => 4326
77
+ end
78
+ end
79
+ klass_
80
+ end
81
+
82
+
83
+ def test_query_point
84
+ klass_ = populate_ar_class(:latlon_point)
85
+ obj_ = klass_.new
86
+ obj_.latlon = @factory.point(1, 2)
87
+ obj_.save!
88
+ id_ = obj_.id
89
+ obj2_ = klass_.where(:latlon => @factory.multi_point([@factory.point(1, 2)])).first
90
+ assert_equal(id_, obj2_.id)
91
+ obj3_ = klass_.where(:latlon => @factory.multi_point([@factory.point(2, 2)])).first
92
+ assert_nil(obj3_)
93
+ end
94
+
95
+
96
+ def test_query_point_wkt
97
+ klass_ = populate_ar_class(:latlon_point)
98
+ obj_ = klass_.new
99
+ obj_.latlon = @factory.point(1, 2)
100
+ obj_.save!
101
+ id_ = obj_.id
102
+ obj2_ = klass_.where(:latlon => 'POINT(1 2)').first
103
+ assert_equal(id_, obj2_.id)
104
+ obj3_ = klass_.where(:latlon => 'POINT(2 2)').first
105
+ assert_nil(obj3_)
106
+ end
107
+
108
+
109
+ if ::RGeo::ActiveRecord.spatial_expressions_supported?
110
+
111
+
112
+ def test_query_st_distance
113
+ klass_ = populate_ar_class(:latlon_point)
114
+ obj_ = klass_.new
115
+ obj_.latlon = @factory.point(1, 2)
116
+ obj_.save!
117
+ id_ = obj_.id
118
+ obj2_ = klass_.where(klass_.arel_table[:latlon].st_distance('POINT(2 3)').lt(2)).first
119
+ assert_equal(id_, obj2_.id)
120
+ obj3_ = klass_.where(klass_.arel_table[:latlon].st_distance('POINT(2 3)').gt(2)).first
121
+ assert_nil(obj3_)
122
+ end
123
+
124
+
125
+ def test_query_st_distance_from_constant
126
+ klass_ = populate_ar_class(:latlon_point)
127
+ obj_ = klass_.new
128
+ obj_.latlon = @factory.point(1, 2)
129
+ obj_.save!
130
+ id_ = obj_.id
131
+ obj2_ = klass_.where(::Arel.spatial('POINT(2 3)').st_distance(klass_.arel_table[:latlon]).lt(2)).first
132
+ assert_equal(id_, obj2_.id)
133
+ obj3_ = klass_.where(::Arel.spatial('POINT(2 3)').st_distance(klass_.arel_table[:latlon]).gt(2)).first
134
+ assert_nil(obj3_)
135
+ end
136
+
137
+
138
+ def test_query_st_length
139
+ klass_ = populate_ar_class(:path_linestring)
140
+ obj_ = klass_.new
141
+ obj_.path = @factory.line(@factory.point(1, 2), @factory.point(3, 2))
142
+ obj_.save!
143
+ id_ = obj_.id
144
+ obj2_ = klass_.where(klass_.arel_table[:path].st_length.eq(2)).first
145
+ assert_equal(id_, obj2_.id)
146
+ obj3_ = klass_.where(klass_.arel_table[:path].st_length.gt(3)).first
147
+ assert_nil(obj3_)
148
+ end
149
+
150
+
151
+ else
152
+
153
+ puts "WARNING: The current Arel does not support named functions. Spatial expression tests skipped."
154
+
155
+ end
156
+
157
+
158
+ end
159
+
160
+ end
161
+
162
+ end
163
+ end
164
+ end
165
+ 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
- version: 0.2.3
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-06 00:00:00 -08:00
17
+ date: 2011-01-26 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -23,17 +23,17 @@ 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
- - 2
31
- - 2
32
- version: 0.2.2
30
+ - 3
31
+ - 0
32
+ version: 0.3.0
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- name: sqlite3-ruby
36
+ name: sqlite3
37
37
  prerelease: false
38
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
@@ -43,8 +43,8 @@ dependencies:
43
43
  segments:
44
44
  - 1
45
45
  - 3
46
- - 2
47
- version: 1.3.2
46
+ - 3
47
+ version: 1.3.3
48
48
  type: :runtime
49
49
  version_requirements: *id002
50
50
  description: This is an ActiveRecord connection adapter for the SpatiaLite extension to the Sqlite3 database. It is based on the stock sqlite3 adapter, but provides built-in support for spatial databases using SpatiaLite. It uses the RGeo library to represent spatial data in Ruby.
@@ -57,12 +57,20 @@ extra_rdoc_files:
57
57
  - History.rdoc
58
58
  - README.rdoc
59
59
  files:
60
+ - lib/active_record/connection_adapters/spatialite_adapter/arel_tosql.rb
61
+ - lib/active_record/connection_adapters/spatialite_adapter/main_adapter.rb
62
+ - lib/active_record/connection_adapters/spatialite_adapter/native_format_parser.rb
63
+ - lib/active_record/connection_adapters/spatialite_adapter/railtie.rb
64
+ - lib/active_record/connection_adapters/spatialite_adapter/spatial_column.rb
65
+ - lib/active_record/connection_adapters/spatialite_adapter/spatial_table_definition.rb
66
+ - lib/active_record/connection_adapters/spatialite_adapter/version.rb
60
67
  - lib/active_record/connection_adapters/spatialite_adapter.rb
61
68
  - lib/rgeo/active_record/spatialite_adapter/railtie.rb
62
- - lib/rgeo/active_record/spatialite_adapter/databases.rake
69
+ - lib/active_record/connection_adapters/spatialite_adapter/databases.rake
63
70
  - History.rdoc
64
71
  - README.rdoc
65
72
  - test/tc_basic.rb
73
+ - test/tc_spatial_queries.rb
66
74
  - Version
67
75
  has_rdoc: true
68
76
  homepage: http://virtuoso.rubyforge.org/activerecord-spatialite-adapter
@@ -100,3 +108,4 @@ specification_version: 3
100
108
  summary: An ActiveRecord adapter for SpatiaLite, based on RGeo.
101
109
  test_files:
102
110
  - test/tc_basic.rb
111
+ - test/tc_spatial_queries.rb