activerecord-postgis-adapter 1.0.0 → 1.1.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.
@@ -1,19 +1,15 @@
1
- require 'minitest/autorun'
2
- require 'rgeo/active_record/adapter_test_helper'
3
-
1
+ require 'test_helper'
4
2
 
5
3
  module RGeo
6
4
  module ActiveRecord # :nodoc:
7
5
  module PostGISAdapter # :nodoc:
8
6
  module Tests # :nodoc:
7
+ class NestedClassTest < BASE_TEST_CLASS # :nodoc:
8
+ DATABASE_CONFIG_PATH = ::File.dirname(__FILE__) + '/database.yml'
9
+ OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__) + '/database_local.yml'
9
10
 
10
- class TestNestedClass < ::MiniTest::Test # :nodoc:
11
-
12
- DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database.yml'
13
- OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database_local.yml'
14
11
  include AdapterTestHelper
15
12
 
16
-
17
13
  module Foo
18
14
  def self.table_name_prefix
19
15
  'foo_'
@@ -22,26 +18,22 @@ module RGeo
22
18
  end
23
19
  end
24
20
 
25
-
26
21
  define_test_methods do
27
22
 
28
-
29
23
  def test_nested_model
30
24
  Foo::Bar.class_eval do
31
- establish_connection(TestNestedClass::DATABASE_CONFIG)
25
+ establish_connection(DATABASE_CONFIG)
32
26
  end
33
- Foo::Bar.connection.create_table(:foo_bars) do |t_|
34
- t_.column 'latlon', :point, :srid => 3785
27
+ Foo::Bar.connection.create_table(:foo_bars) do |t|
28
+ t.column 'latlon', :point, :srid => 3785
35
29
  end
36
30
  Foo::Bar.all
37
31
  Foo::Bar.connection.drop_table(:foo_bars)
38
32
  end
39
33
 
40
-
41
34
  end
42
35
 
43
36
  end
44
-
45
37
  end
46
38
  end
47
39
  end
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ module RGeo
4
+ module ActiveRecord # :nodoc:
5
+ module PostGISAdapter # :nodoc:
6
+ module Tests # :nodoc:
7
+ class SpatialQueriesTest < BASE_TEST_CLASS # :nodoc:
8
+
9
+ def test_ignore_tables
10
+ assert_equal %w(geometry_columns spatial_ref_sys layer topology), ::ActiveRecord::SchemaDumper.ignore_tables
11
+ end
12
+
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,105 @@
1
+ require 'test_helper'
2
+
3
+ module RGeo
4
+ module ActiveRecord # :nodoc:
5
+ module PostGISAdapter # :nodoc:
6
+ module Tests # :nodoc:
7
+ class SpatialQueriesTest < BASE_TEST_CLASS # :nodoc:
8
+
9
+ DATABASE_CONFIG_PATH = ::File.dirname(__FILE__) + '/database.yml'
10
+ OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__) + '/database_local.yml'
11
+
12
+ include AdapterTestHelper
13
+
14
+ define_test_methods do
15
+
16
+ def populate_ar_class(content)
17
+ klass = create_ar_class
18
+ case content
19
+ when :mercator_point
20
+ klass.connection.create_table(:spatial_test) do |t|
21
+ t.column 'latlon', :point, :srid => 3785
22
+ end
23
+ when :latlon_point_geographic
24
+ klass.connection.create_table(:spatial_test) do |t|
25
+ t.column 'latlon', :point, :srid => 4326, :geographic => true
26
+ end
27
+ when :path_linestring
28
+ klass.connection.create_table(:spatial_test) do |t|
29
+ t.column 'path', :line_string, :srid => 3785
30
+ end
31
+ end
32
+ klass
33
+ end
34
+
35
+ def test_query_point
36
+ klass = populate_ar_class(:mercator_point)
37
+ obj = klass.new
38
+ obj.latlon = @factory.point(1.0, 2.0)
39
+ obj.save!
40
+ id = obj.id
41
+ obj2 = klass.where(:latlon => @factory.multi_point([@factory.point(1.0, 2.0)])).first
42
+ refute_nil(obj2)
43
+ assert_equal(id, obj2.id)
44
+ obj3 = klass.where(:latlon => @factory.point(2.0, 2.0)).first
45
+ assert_nil(obj3)
46
+ end
47
+
48
+ def test_query_point_wkt
49
+ klass = populate_ar_class(:mercator_point)
50
+ obj = klass.new
51
+ obj.latlon = @factory.point(1.0, 2.0)
52
+ obj.save!
53
+ id = obj.id
54
+ obj2 = klass.where(:latlon => 'SRID=3785;POINT(1 2)').first
55
+ refute_nil(obj2)
56
+ assert_equal(id, obj2.id)
57
+ obj3 = klass.where(:latlon => 'SRID=3785;POINT(2 2)').first
58
+ assert_nil(obj3)
59
+ end
60
+
61
+ def test_query_st_distance
62
+ klass = populate_ar_class(:mercator_point)
63
+ obj = klass.new
64
+ obj.latlon = @factory.point(1.0, 2.0)
65
+ obj.save!
66
+ id = obj.id
67
+ obj2 = klass.where(klass.arel_table[:latlon].st_distance('SRID=3785;POINT(2 3)').lt(2)).first
68
+ refute_nil(obj2)
69
+ assert_equal(id, obj2.id)
70
+ obj3 = klass.where(klass.arel_table[:latlon].st_distance('SRID=3785;POINT(2 3)').gt(2)).first
71
+ assert_nil(obj3)
72
+ end
73
+
74
+ def test_query_st_distance_from_constant
75
+ klass = populate_ar_class(:mercator_point)
76
+ obj = klass.new
77
+ obj.latlon = @factory.point(1.0, 2.0)
78
+ obj.save!
79
+ id = obj.id
80
+ obj2 = klass.where(::Arel.spatial('SRID=3785;POINT(2 3)').st_distance(klass.arel_table[:latlon]).lt(2)).first
81
+ refute_nil(obj2)
82
+ assert_equal(id, obj2.id)
83
+ obj3 = klass.where(::Arel.spatial('SRID=3785;POINT(2 3)').st_distance(klass.arel_table[:latlon]).gt(2)).first
84
+ assert_nil(obj3)
85
+ end
86
+
87
+ def test_query_st_length
88
+ klass = populate_ar_class(:path_linestring)
89
+ obj = klass.new
90
+ obj.path = @factory.line(@factory.point(1.0, 2.0), @factory.point(3.0, 2.0))
91
+ obj.save!
92
+ id = obj.id
93
+ obj2 = klass.where(klass.arel_table[:path].st_length.eq(2)).first
94
+ refute_nil(obj2)
95
+ assert_equal(id, obj2.id)
96
+ obj3 = klass.where(klass.arel_table[:path].st_length.gt(3)).first
97
+ assert_nil(obj3)
98
+ end
99
+
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,8 @@
1
+ require 'minitest/autorun'
2
+ require 'rgeo/active_record/adapter_test_helper'
3
+
4
+ BASE_TEST_CLASS = if ActiveRecord::VERSION::STRING > '4.1'
5
+ Minitest::Test
6
+ else
7
+ MiniTest::Unit::TestCase
8
+ end
@@ -0,0 +1,111 @@
1
+ require 'test_helper'
2
+
3
+ module RGeo
4
+ module ActiveRecord # :nodoc:
5
+ module PostGISAdapter # :nodoc:
6
+ module Tests # :nodoc:
7
+ class TestTasks < BASE_TEST_CLASS # :nodoc:
8
+ DATABASE_CONFIG_PATH = ::File.dirname(__FILE__) + '/database.yml'
9
+ OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__) + '/database_local.yml'
10
+
11
+ class << self
12
+ def before_open_database(args)
13
+ @new_database_config = args[:config].merge('database' => 'postgis_adapter_test2')
14
+ @new_database_config.stringify_keys!
15
+ end
16
+ attr_reader :new_database_config
17
+ end
18
+
19
+ include AdapterTestHelper
20
+
21
+ def cleanup_tables
22
+ ::ActiveRecord::Base.remove_connection
23
+ ::ActiveRecord::Base.clear_active_connections!
24
+ TestTasks::DEFAULT_AR_CLASS.connection.execute("DROP DATABASE IF EXISTS \"postgis_adapter_test2\"")
25
+ end
26
+
27
+ define_test_methods do
28
+ def test_create_database_from_extension_in_public_schema
29
+ ::ActiveRecord::Tasks::DatabaseTasks.create(TestTasks.new_database_config)
30
+ ::ActiveRecord::Base.connection.select_values("SELECT * from public.spatial_ref_sys")
31
+ end
32
+
33
+ def test_empty_sql_dump
34
+ filename = ::File.expand_path('../tmp/tmp.sql', ::File.dirname(__FILE__))
35
+ ::FileUtils.rm_f(filename)
36
+ ::FileUtils.mkdir_p(::File.dirname(filename))
37
+ ::ActiveRecord::Tasks::DatabaseTasks.create(TestTasks.new_database_config.merge('schema_search_path' => 'public,postgis'))
38
+ ::ActiveRecord::Tasks::DatabaseTasks.structure_dump(TestTasks.new_database_config, filename)
39
+ sql = ::File.read(filename)
40
+ assert(sql !~ /CREATE/)
41
+ end
42
+
43
+ def test_basic_geography_sql_dump
44
+ filename = ::File.expand_path('../tmp/tmp.sql', ::File.dirname(__FILE__))
45
+ ::FileUtils.rm_f(filename)
46
+ ::FileUtils.mkdir_p(::File.dirname(filename))
47
+ ::ActiveRecord::Tasks::DatabaseTasks.create(TestTasks.new_database_config.merge('schema_search_path' => 'public,postgis'))
48
+ ::ActiveRecord::Base.connection.create_table(:spatial_test) do |t|
49
+ t.point "latlon", :geographic => true
50
+ end
51
+ ::ActiveRecord::Tasks::DatabaseTasks.structure_dump(TestTasks.new_database_config, filename)
52
+ data = ::File.read(filename)
53
+ assert(data.index('latlon geography(Point,4326)'))
54
+ end
55
+
56
+ def test_empty_schema_dump
57
+ filename = ::File.expand_path('../tmp/tmp.rb', ::File.dirname(__FILE__))
58
+ ::FileUtils.rm_f(filename)
59
+ ::FileUtils.mkdir_p(::File.dirname(filename))
60
+ ::ActiveRecord::Tasks::DatabaseTasks.create(TestTasks.new_database_config.merge('schema_search_path' => 'public,postgis'))
61
+ require 'active_record/schema_dumper'
62
+ ::File.open(filename, "w:utf-8") do |file|
63
+ ::ActiveRecord::SchemaDumper.dump(::ActiveRecord::Base.connection, file)
64
+ end
65
+ data = ::File.read(filename)
66
+ assert(data.index('ActiveRecord::Schema'))
67
+ end
68
+
69
+ def test_basic_geometry_schema_dump
70
+ filename = ::File.expand_path('../tmp/tmp.rb', ::File.dirname(__FILE__))
71
+ ::FileUtils.rm_f(filename)
72
+ ::FileUtils.mkdir_p(::File.dirname(filename))
73
+ ::ActiveRecord::Tasks::DatabaseTasks.create(TestTasks.new_database_config.merge('schema_search_path' => 'public,postgis'))
74
+ conn = ::ActiveRecord::Base.connection
75
+ conn.create_table(:spatial_test) do |t|
76
+ t.geometry 'object1'
77
+ t.spatial "object2", :limit => {:srid=>conn.default_srid, :type=>"geometry"}
78
+ end
79
+ require 'active_record/schema_dumper'
80
+ ::File.open(filename, "w:utf-8") do |file|
81
+ ::ActiveRecord::SchemaDumper.dump(conn, file)
82
+ end
83
+ data = ::File.read(filename)
84
+ assert(data.index("t.spatial \"object1\", limit: {:srid=>#{conn.default_srid}, :type=>\"geometry\"}"))
85
+ assert(data.index("t.spatial \"object2\", limit: {:srid=>#{conn.default_srid}, :type=>\"geometry\"}"))
86
+ end
87
+
88
+ def test_basic_geography_schema_dump
89
+ filename = ::File.expand_path('../tmp/tmp.rb', ::File.dirname(__FILE__))
90
+ ::FileUtils.rm_f(filename)
91
+ ::FileUtils.mkdir_p(::File.dirname(filename))
92
+ ::ActiveRecord::Tasks::DatabaseTasks.create(TestTasks.new_database_config.merge('schema_search_path' => 'public,postgis'))
93
+ conn = ::ActiveRecord::Base.connection
94
+ conn.create_table(:spatial_test) do |t|
95
+ t.point "latlon1", :geographic => true
96
+ t.spatial "latlon2", :limit => {:srid=>4326, :type=>"point", :geographic=>true}
97
+ end
98
+ require 'active_record/schema_dumper'
99
+ ::File.open(filename, "w:utf-8") do |file|
100
+ ::ActiveRecord::SchemaDumper.dump(conn, file)
101
+ end
102
+ data = ::File.read(filename)
103
+ assert(data.index('t.spatial "latlon1", limit: {:srid=>4326, :type=>"point", :geographic=>true}'))
104
+ assert(data.index('t.spatial "latlon2", limit: {:srid=>4326, :type=>"point", :geographic=>true}'))
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgis-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - Daniel Azuma
7
+ - Daniel Azuma, Tee Parham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-06 00:00:00.000000000 Z
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 4.1.0
19
+ version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 4.1.0
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rgeo-activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,37 +53,23 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.2'
55
55
  - !ruby/object:Gem::Dependency
56
- name: minitest
56
+ name: rdoc
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '5.3'
61
+ version: '4.1'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '5.3'
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'
68
+ version: '4.1'
83
69
  description: This is an ActiveRecord connection adapter for PostGIS. It is based on
84
70
  the stock PostgreSQL adapter, but provides built-in support for the spatial extensions
85
71
  provided by PostGIS. It uses the RGeo library to represent spatial data in Ruby.
86
- email: dazuma@gmail.com
72
+ email: dazuma@gmail.com, parhameter@gmail.com
87
73
  executables: []
88
74
  extensions: []
89
75
  extra_rdoc_files:
@@ -110,13 +96,15 @@ files:
110
96
  - lib/active_record/connection_adapters/postgis_adapter/version.rb
111
97
  - lib/activerecord-postgis-adapter.rb
112
98
  - lib/activerecord/postgis/adapter.rb
99
+ - test/basic_test.rb
113
100
  - test/database.yml
114
- - test/tc_basic.rb
115
- - test/tc_ddl.rb
116
- - test/tc_nested_class.rb
117
- - test/tc_spatial_queries.rb
118
- - test/tc_tasks.rb
119
- homepage: http://dazuma.github.com/activerecord-postgis-adapter
101
+ - test/ddl_test.rb
102
+ - test/nested_class_test.rb
103
+ - test/setup_test.rb
104
+ - test/spatial_queries_test.rb
105
+ - test/test_helper.rb
106
+ - test/test_tasks.rb
107
+ homepage: http://github.com/rgeo/activerecord-postgis-adapter
120
108
  licenses:
121
109
  - BSD
122
110
  metadata: {}
@@ -141,10 +129,12 @@ signing_key:
141
129
  specification_version: 4
142
130
  summary: An ActiveRecord adapter for PostGIS, based on RGeo.
143
131
  test_files:
132
+ - test/basic_test.rb
144
133
  - test/database.yml
145
- - test/tc_basic.rb
146
- - test/tc_ddl.rb
147
- - test/tc_nested_class.rb
148
- - test/tc_spatial_queries.rb
149
- - test/tc_tasks.rb
134
+ - test/ddl_test.rb
135
+ - test/nested_class_test.rb
136
+ - test/setup_test.rb
137
+ - test/spatial_queries_test.rb
138
+ - test/test_helper.rb
139
+ - test/test_tasks.rb
150
140
  has_rdoc:
data/test/tc_basic.rb DELETED
@@ -1,212 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'rgeo/active_record/adapter_test_helper'
3
-
4
-
5
- module RGeo
6
- module ActiveRecord # :nodoc:
7
- module PostGISAdapter # :nodoc:
8
- module Tests # :nodoc:
9
-
10
- class TestBasic < ::MiniTest::Test # :nodoc:
11
-
12
- DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database.yml'
13
- OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database_local.yml'
14
-
15
- include AdapterTestHelper
16
-
17
- define_test_methods do
18
-
19
-
20
- def populate_ar_class(content_)
21
- klass_ = create_ar_class
22
- case content_
23
- when :mercator_point
24
- klass_.connection.create_table(:spatial_test) do |t_|
25
- t_.column 'latlon', :point, :srid => 3785
26
- end
27
- when :latlon_point_geographic
28
- klass_.connection.create_table(:spatial_test) do |t_|
29
- t_.column 'latlon', :point, :srid => 4326, :geographic => true
30
- end
31
- when :no_constraints
32
- klass_.connection.create_table(:spatial_test) do |t_|
33
- t_.column 'geo', :geometry, :no_constraints => true
34
- end
35
- end
36
- klass_
37
- end
38
-
39
-
40
- def test_version
41
- refute_nil(::ActiveRecord::ConnectionAdapters::PostGISAdapter::VERSION)
42
- end
43
-
44
-
45
- def test_postgis_available
46
- connection_ = create_ar_class.connection
47
- assert_equal('PostGIS', connection_.adapter_name)
48
- refute_nil(connection_.postgis_lib_version)
49
- end
50
-
51
-
52
- def test_set_and_get_point
53
- klass_ = populate_ar_class(:mercator_point)
54
- obj_ = klass_.new
55
- assert_nil(obj_.latlon)
56
- obj_.latlon = @factory.point(1.0, 2.0)
57
- assert_equal(@factory.point(1.0, 2.0), obj_.latlon)
58
- assert_equal(3785, obj_.latlon.srid)
59
- end
60
-
61
-
62
- def test_set_and_get_point_from_wkt
63
- klass_ = populate_ar_class(:mercator_point)
64
- obj_ = klass_.new
65
- assert_nil(obj_.latlon)
66
- obj_.latlon = 'POINT(1 2)'
67
- assert_equal(@factory.point(1.0, 2.0), obj_.latlon)
68
- assert_equal(3785, obj_.latlon.srid)
69
- end
70
-
71
-
72
- def test_save_and_load_point
73
- klass_ = populate_ar_class(:mercator_point)
74
- obj_ = klass_.new
75
- obj_.latlon = @factory.point(1.0, 2.0)
76
- obj_.save!
77
- id_ = obj_.id
78
- obj2_ = klass_.find(id_)
79
- assert_equal(@factory.point(1.0, 2.0), obj2_.latlon)
80
- assert_equal(3785, obj2_.latlon.srid)
81
- assert_equal(true, ::RGeo::Geos.is_geos?(obj2_.latlon))
82
- end
83
-
84
-
85
- def test_save_and_load_geographic_point
86
- klass_ = populate_ar_class(:latlon_point_geographic)
87
- obj_ = klass_.new
88
- obj_.latlon = @factory.point(1.0, 2.0)
89
- obj_.save!
90
- id_ = obj_.id
91
- obj2_ = klass_.find(id_)
92
- assert_equal(@geographic_factory.point(1.0, 2.0), obj2_.latlon)
93
- assert_equal(4326, obj2_.latlon.srid)
94
- assert_equal(false, ::RGeo::Geos.is_geos?(obj2_.latlon))
95
- end
96
-
97
-
98
- def test_save_and_load_point_from_wkt
99
- klass_ = populate_ar_class(:mercator_point)
100
- obj_ = klass_.new
101
- obj_.latlon = 'POINT(1 2)'
102
- obj_.save!
103
- id_ = obj_.id
104
- obj2_ = klass_.find(id_)
105
- assert_equal(@factory.point(1.0, 2.0), obj2_.latlon)
106
- assert_equal(3785, obj2_.latlon.srid)
107
- end
108
-
109
-
110
- def test_set_point_bad_wkt
111
- klass_ = populate_ar_class(:mercator_point)
112
- obj_ = klass_.create(:latlon => 'POINT (x)')
113
- assert_nil(obj_.latlon)
114
- end
115
-
116
-
117
- def test_set_point_wkt_wrong_type
118
- klass_ = populate_ar_class(:mercator_point)
119
- assert_raises(::ActiveRecord::StatementInvalid) do
120
- klass_.create(:latlon => 'LINESTRING(1 2, 3 4, 5 6)')
121
- end
122
- end
123
-
124
-
125
- def test_custom_factory
126
- klass_ = create_ar_class
127
- klass_.connection.create_table(:spatial_test) do |t_|
128
- t_.point(:latlon, :srid => 4326)
129
- end
130
- factory_ = ::RGeo::Geographic.simple_mercator_factory
131
- klass_.class_eval do
132
- set_rgeo_factory_for_column(:latlon, factory_)
133
- end
134
- rec_ = klass_.new
135
- rec_.latlon = 'POINT(-122 47)'
136
- assert_equal(factory_, rec_.latlon.factory)
137
- rec_.save!
138
- assert_equal(factory_, rec_.latlon.factory)
139
- rec2_ = klass_.find(rec_.id)
140
- assert_equal(factory_, rec2_.latlon.factory)
141
- end
142
-
143
-
144
- def test_readme_example
145
- klass_ = create_ar_class
146
- klass_.connection.create_table(:spatial_test) do |t_|
147
- t_.column(:shape, :geometry)
148
- t_.line_string(:path, :srid => 3785)
149
- t_.point(:latlon, :geographic => true)
150
- end
151
- klass_.connection.change_table(:spatial_test) do |t_|
152
- t_.index(:latlon, :spatial => true)
153
- end
154
- klass_.class_eval do
155
- self.rgeo_factory_generator = ::RGeo::Geos.method(:factory)
156
- set_rgeo_factory_for_column(:latlon, ::RGeo::Geographic.spherical_factory)
157
- end
158
- rec_ = klass_.new
159
- rec_.latlon = 'POINT(-122 47)'
160
- loc_ = rec_.latlon
161
- assert_equal(47, loc_.latitude)
162
- rec_.shape = loc_
163
- assert_equal(true, ::RGeo::Geos.is_geos?(rec_.shape))
164
- end
165
-
166
-
167
- # no_constraints no longer supported in PostGIS 2.0
168
- def _test_save_and_load_no_constraints
169
- klass_ = populate_ar_class(:no_constraints)
170
- factory1_ = ::RGeo::Cartesian.preferred_factory(:srid => 3785)
171
- factory2_ = ::RGeo::Cartesian.preferred_factory(:srid => 2000)
172
- obj_ = klass_.new
173
- obj_.geo = factory1_.point(1.0, 2.0)
174
- obj_.save!
175
- id_ = obj_.id
176
- obj2_ = klass_.find(id_)
177
- assert_equal(factory1_.point(1.0, 2.0), obj2_.geo)
178
- assert_equal(3785, obj2_.geo.srid)
179
- obj2_.geo = factory2_.point(3.0, 4.0)
180
- obj2_.save!
181
- obj3_ = klass_.find(id_)
182
- assert_equal(factory2_.point(3.0, 4.0), obj3_.geo)
183
- assert_equal(2000, obj3_.geo.srid)
184
- end
185
-
186
-
187
- def test_point_to_json
188
- klass_ = populate_ar_class(:mercator_point)
189
- obj_ = klass_.new
190
- assert_match(/"latlon":null/, obj_.to_json)
191
- obj_.latlon = @factory.point(1.0, 2.0)
192
- assert_match(/"latlon":"POINT\s\(1\.0\s2\.0\)"/, obj_.to_json)
193
- end
194
-
195
-
196
- def test_custom_column
197
- klass_ = populate_ar_class(:mercator_point)
198
- rec_ = klass_.new
199
- rec_.latlon = 'POINT(0 0)'
200
- rec_.save
201
- refute_nil(klass_.select("CURRENT_TIMESTAMP as ts").first.ts)
202
- end
203
-
204
-
205
- end
206
-
207
- end
208
-
209
- end
210
- end
211
- end
212
- end