rgeo-ar 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.
data/test/tc_basic.rb ADDED
@@ -0,0 +1,109 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Tests for basic ActiveRecord extensions
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
+ require 'test_helper'
36
+
37
+ module RGeo
38
+ module ActiveRecord
39
+ module Tests # :nodoc:
40
+
41
+ class TestBasic < ::MiniTest::Test # :nodoc:
42
+
43
+
44
+ class MyTable < ::ActiveRecord::Base
45
+ end
46
+
47
+
48
+ def test_has_version
49
+ assert ::RGeo::ActiveRecord::VERSION
50
+ end
51
+
52
+
53
+ def test_default_factory_generator
54
+ MyTable.rgeo_factory_generator = nil
55
+ factory_ = MyTable.rgeo_factory_for_column(:hello).call(:has_z_coordinate => true, :srid => 4326)
56
+ assert_equal(true, factory_.property(:has_z_coordinate))
57
+ assert_equal(true, factory_.property(:is_cartesian))
58
+ assert_nil(factory_.property(:is_geographic))
59
+ assert_equal(4326, factory_.srid)
60
+ end
61
+
62
+
63
+ def test_set_factory_generator
64
+ MyTable.rgeo_factory_generator = ::RGeo::Geographic.method(:spherical_factory)
65
+ factory_ = MyTable.rgeo_factory_for_column(:hello, :has_z_coordinate => true, :srid => 4326)
66
+ assert_equal(true, factory_.property(:has_z_coordinate))
67
+ assert_equal(true, factory_.property(:is_geographic))
68
+ assert_nil(factory_.property(:is_cartesian))
69
+ assert_equal(false, factory_.has_projection?)
70
+ assert_equal(4326, factory_.srid)
71
+ end
72
+
73
+
74
+ def test_specific_factory_for_column
75
+ MyTable.rgeo_factory_generator = nil
76
+ MyTable.set_rgeo_factory_for_column(:foo, ::RGeo::Geographic.simple_mercator_factory(:has_z_coordinate => true))
77
+ factory_ = MyTable.rgeo_factory_for_column(:foo)
78
+ assert_equal(true, factory_.property(:has_z_coordinate))
79
+ assert_equal(true, factory_.property(:is_geographic))
80
+ assert_nil(factory_.property(:is_cartesian))
81
+ assert_equal(true, factory_.has_projection?)
82
+ assert_equal(4326, factory_.srid)
83
+ end
84
+
85
+
86
+ def test_default_as_json_wkt
87
+ GeometryMixin.set_json_generator(nil)
88
+ factory_ = ::RGeo::Cartesian.preferred_factory
89
+ p_ = factory_.point(1, 2)
90
+ assert_equal("POINT (1.0 2.0)", p_.as_json)
91
+ end
92
+
93
+
94
+ def test_default_as_json_geojson
95
+ GeometryMixin.set_json_generator(:geojson)
96
+ factory_ = ::RGeo::Cartesian.preferred_factory
97
+ p_ = factory_.point(1, 2)
98
+ assert_equal({'type' => 'Point', 'coordinates' => [1.0, 2.0]}, p_.as_json)
99
+ end
100
+
101
+ def test_arel_visit_SpatialConstantNode
102
+ visitor = arel_visitor
103
+ sql = visitor.accept(Arel.spatial('POINT (1.0 2.0)'))
104
+ assert_equal("ST_WKTToSQL('POINT (1.0 2.0)')", sql)
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,10 @@
1
+ require 'minitest/autorun'
2
+ require 'rgeo/active_record'
3
+ require 'support/fake_record'
4
+
5
+ Arel::Visitors::PostgreSQL.send(:include, ::RGeo::ActiveRecord::SpatialToSql)
6
+ Arel::Table.engine = Arel::Sql::Engine.new(FakeRecord::Base.new)
7
+
8
+ def arel_visitor
9
+ Arel::Visitors::PostgreSQL.new(Arel::Table.engine.connection)
10
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rgeo-ar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Azuma
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rgeo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.20
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.20
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdoc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: RGeo is a geospatial data library for Ruby. RGeo::ActiveRecord is an
84
+ optional RGeo module providing some spatial extensions to ActiveRecord, as well
85
+ as common tools used by RGeo-based spatial adapters.
86
+ email: dazuma@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files:
90
+ - History.rdoc
91
+ - README.rdoc
92
+ files:
93
+ - History.rdoc
94
+ - README.rdoc
95
+ - lib/rgeo-activerecord.rb
96
+ - lib/rgeo/active_record.rb
97
+ - lib/rgeo/active_record/adapter_test_helper.rb
98
+ - lib/rgeo/active_record/ar_factory_settings.rb
99
+ - lib/rgeo/active_record/arel_spatial_queries.rb
100
+ - lib/rgeo/active_record/common_adapter_elements.rb
101
+ - lib/rgeo/active_record/geometry_mixin.rb
102
+ - lib/rgeo/active_record/spatial_expressions.rb
103
+ - lib/rgeo/active_record/task_hacker.rb
104
+ - lib/rgeo/active_record/version.rb
105
+ - test/support/fake_record.rb
106
+ - test/tc_basic.rb
107
+ - test/test_helper.rb
108
+ homepage: http://dazuma.github.com/rgeo-activerecord
109
+ licenses: []
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 2.0.0
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.2.2
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: An RGeo module providing spatial extensions to ActiveRecord.
131
+ test_files:
132
+ - test/tc_basic.rb
133
+ has_rdoc: