gotime-postgis_adapter 0.8.2

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,238 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/spec_helper.rb'
3
+
4
+ describe "PostgisAdapter" do
5
+
6
+ describe "Point" do
7
+ it "should record a point nicely" do
8
+ pt = TablePoint.new(:data => "Test", :geom => Point.from_x_y(1.2,4.5))
9
+ pt.save.should be_true
10
+ end
11
+
12
+ it "should find a point nicely" do
13
+ find = TablePoint.find(:last)
14
+ find.should be_instance_of(TablePoint)
15
+ find.geom.should be_instance_of(Point)
16
+ end
17
+
18
+ it "should find`em all for hellsake..." do
19
+ find = TablePoint.all
20
+ find.should be_instance_of(Array)
21
+ find.last.geom.x.should eql(1.2)
22
+ end
23
+
24
+ it "should est_3dz_points" do
25
+ pt = Table3dzPoint.create!(:data => "Hello!",
26
+ :geom => Point.from_x_y_z(-1.6,2.8,-3.4))
27
+ pt = Table3dzPoint.find(:first)
28
+ pt.geom.should be_instance_of(Point)
29
+ pt.geom.z.should eql(-3.4)
30
+ end
31
+
32
+ it "should est_3dm_points" do
33
+ pt = Table3dmPoint.create!(:geom => Point.from_x_y_m(-1.6,2.8,-3.4))
34
+ pt = Table3dmPoint.find(:first)
35
+ pt.geom.should == Point.from_x_y_m(-1.6,2.8,-3.4)
36
+ pt.geom.m.should eql(-3.4)
37
+ end
38
+
39
+ it "should est_4d_points" do
40
+ pt = Table4dPoint.create!(:geom => Point.from_x_y_z_m(-1,2.8,-3.4,15))
41
+ pt = Table4dPoint.find(:first)
42
+ pt.geom.should be_instance_of(Point)
43
+ pt.geom.z.should eql(-3.4)
44
+ pt.geom.m.should eql(15.0)
45
+ end
46
+
47
+ it "should test_keyword_column_point" do
48
+ pt = TableKeywordColumnPoint.create!(:location => Point.from_x_y(1.2,4.5))
49
+ find = TableKeywordColumnPoint.find(:first)
50
+ find.location.should == Point.from_x_y(1.2,4.5)
51
+ end
52
+
53
+ it "should test multipoint" do
54
+ mp = TableMultiPoint.create!(:geom => MultiPoint.from_coordinates([[12.4,-4326.3],[-65.1,4326.4],[4326.55555555,4326]]))
55
+ find = TableMultiPoint.find(:first)
56
+ find.geom.should == MultiPoint.from_coordinates([[12.4,-4326.3],[-65.1,4326.4],[4326.55555555,4326]])
57
+ end
58
+
59
+ end
60
+
61
+ describe "LineString" do
62
+ it "should record a linestring nicely" do
63
+ @ls = TableLineString.new(:value => 3,
64
+ :geom => LineString.from_coordinates([[1.4,2.5],[1.5,6.7]]))
65
+ @ls.save.should be_true
66
+ end
67
+
68
+ it "should find" do
69
+ find = TableLineString.find(:first)
70
+ find.geom.should be_instance_of(LineString)
71
+ find.geom.points.first.y.should eql(2.5)
72
+ end
73
+
74
+ it "should test_srid_line_string" do
75
+ ls = TableSridLineString.create!(
76
+ :geom => LineString.from_coordinates([[1.4,2.5],[1.5,6.7]],4326))
77
+ ls = TableSridLineString.find(:first)
78
+ ls_e = LineString.from_coordinates([[1.4,2.5],[1.5,6.7]],4326)
79
+ ls.geom.should be_instance_of(LineString)
80
+ ls.geom.srid.should eql(4326)
81
+ end
82
+
83
+ it "hsould test_multi_line_string" do
84
+ ml = TableMultiLineString.create!(:geom => MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.432612,-0.012]]),LineString.from_coordinates([[1.5,45.2],[-54.432612,-0.012],[45.4326,4326.3]])]))
85
+ find = TableMultiLineString.find(:first)
86
+ find.geom.should == MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.432612,-0.012]]),LineString.from_coordinates([[1.5,45.2],[-54.432612,-0.012],[45.4326,4326.3]])])
87
+ end
88
+ end
89
+
90
+ describe "Polygon" do
91
+
92
+ it "should create" do
93
+ pg = TablePolygon.new(:geom => Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]]))
94
+ pg.save.should be_true
95
+ end
96
+
97
+ it "should get it back" do
98
+ pg = TablePolygon.find(:first)
99
+ pg.geom.should == Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]])
100
+ end
101
+
102
+ it "should test_multi_polygon" do
103
+ mp = TableMultiPolygon.create!( :geom => MultiPolygon.from_polygons([Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]]),Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]])]))
104
+ find = TableMultiPolygon.find(:first)
105
+ find.geom.should == MultiPolygon.from_polygons([Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]]),Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]])])
106
+ end
107
+
108
+ it "should test_srid_4d_polygon" do
109
+ pg = TableSrid4dPolygon.create(:geom => Polygon.from_coordinates([[[0,0,2,-45.1],[4,0,2,5],[4,4,2,4.67],[0,4,2,1.34],[0,0,2,-45.1]],[[1,1,2,12.3],[3,1,2,4326],[3,3,2,12.2],[1,3,2,12],[1,1,2,12.3]]],4326,true,true))
110
+ find = TableSrid4dPolygon.find(:first)
111
+ pg_e = Polygon.from_coordinates([[[0,0,2,-45.1],[4,0,2,5],[4,4,2,4.67],[0,4,2,1.34],[0,0,2,-45.1]],[[1,1,2,12.3],[3,1,2,4326],[3,3,2,12.2],[1,3,2,12],[1,1,2,12.3]]],4326,true,true)
112
+ pg.geom.should == pg_e
113
+ pg.geom.srid.should eql(4326)
114
+ end
115
+ end
116
+
117
+ describe "Geometry" do
118
+
119
+ it "should test_geometry" do
120
+ gm = TableGeometry.create!(:geom => LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]]))
121
+ find = TableGeometry.find(:first)
122
+ find.geom.should == LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]])
123
+ end
124
+
125
+ it "should test_geometry_collection" do
126
+ gc = TableGeometryCollection.create!(:geom => GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4),LineString.from_coordinates([[5.7,12.45],[67.55,54]])]))
127
+ find = TableGeometryCollection.find(:first)
128
+ find.geom.should == GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4),LineString.from_coordinates([[5.7,12.45],[67.55,54]])])
129
+ end
130
+
131
+ end
132
+
133
+ describe "Find" do
134
+
135
+ ActiveRecord::Schema.define() do
136
+ create_table :areas, :force => true do |t|
137
+ t.string :data, :limit => 100
138
+ t.integer :value
139
+ t.point :geom, :null => false, :srid => 4326
140
+ end
141
+ add_index :areas, :geom, :spatial => true, :name => "areas_spatial_index"
142
+ end
143
+
144
+ class Area < ActiveRecord::Base
145
+ end
146
+
147
+ it "should create some points" do
148
+ Area.create!(:data => "Point1", :geom => Point.from_x_y(1.2,0.75,4326))
149
+ Area.create!(:data => "Point2", :geom => Point.from_x_y(0.6,1.3,4326))
150
+ Area.create!(:data => "Point3", :geom => Point.from_x_y(2.5,2,4326))
151
+ end
152
+
153
+ it "should find by geom" do
154
+ pts = Area.find_all_by_geom(LineString.from_coordinates([[0,0],[2,2]],4326))
155
+ pts.should be_instance_of(Array)
156
+ pts.length.should eql(2)
157
+ pts[0].data.should match(/Point/)
158
+ pts[1].data.should match(/Point/)
159
+ end
160
+
161
+ it "should find by geom again" do
162
+ pts = Area.find_all_by_geom(LineString.from_coordinates([[2.49,1.99],[2.51,2.01]],4326))
163
+ pts[0].data.should eql("Point3")
164
+ end
165
+
166
+ it "should find by geom column bbox condition" do
167
+ pts = Area.find_all_by_geom([[0,0],[2,2],4326])
168
+ pts.should be_instance_of(Array)
169
+ pts.length.should eql(2)
170
+ pts[0].data.should match(/Point/)
171
+ pts[1].data.should match(/Point/)
172
+ end
173
+
174
+ it "should not mess with rails finder" do
175
+ pts = Area.find_all_by_data "Point1"
176
+ pts.should have(1).park
177
+ end
178
+
179
+ end
180
+
181
+ # Verify that a non-NULL column with a default value is handled correctly. # Additionally, if the database uses UTF8, set the binary (bytea)
182
+ # column value to an illegal UTF8 string; it should be stored as the
183
+ # specified binary string and not as a text string. (The binary data test
184
+ # cannot fail if the database uses SQL_ASCII or LATIN1 encoding.)
185
+ describe "PostgreSQL-specific types and default values" do
186
+
187
+ ActiveRecord::Schema.define() do
188
+ create_table :binary_defaults, :force => true do |t|
189
+ t.string :name, :null => false
190
+ t.string :data, :null => false, :default => ''
191
+ t.binary :value
192
+ end
193
+ end
194
+
195
+ class BinaryDefault < ActiveRecord::Base
196
+ end
197
+
198
+ it "should create some records" do
199
+ if BinaryDefault.connection.encoding == "UTF8"
200
+ # fôo as ISO-8859-1 (i.e., not valid UTF-8 data)
201
+ BinaryDefault.create!(:name => "foo", :data => "baz",
202
+ :value => "f\xf4o")
203
+ # data value not specified, should use default
204
+ # bår as ISO-8859-1 (i.e., not valid UTF-8 data)
205
+ BinaryDefault.create!(:name => "bar",
206
+ :value => "b\xe5r")
207
+ else
208
+ BinaryDefault.create!(:name => "foo", :data => "baz")
209
+ BinaryDefault.create!(:name => "bar")
210
+ end
211
+ end
212
+
213
+ it "should find the records" do
214
+ foo = BinaryDefault.find_by_name("foo")
215
+ bar = BinaryDefault.find_by_name("bar")
216
+
217
+ foo.data.should eql("baz")
218
+ bar.data.should eql("")
219
+
220
+ if BinaryDefault.connection.encoding == "UTF8"
221
+ foo.value.encode("UTF-8", "ISO-8859-1").should eql("fôo")
222
+ bar.value.encode("UTF-8", "ISO-8859-1").should eql("bår")
223
+ end
224
+ end
225
+
226
+ end
227
+
228
+ describe "Extras" do
229
+ it "should disable referencial integrity" do
230
+ lambda do
231
+ Area.connection.disable_referential_integrity do
232
+ Area.delete_all
233
+ end
234
+ end.should_not raise_error
235
+ end
236
+ end
237
+
238
+ end
@@ -0,0 +1,45 @@
1
+ SPEC_DB = {
2
+ :adapter => "postgresql",
3
+ :database => "postgis_adapter",
4
+ :username => "postgres",
5
+ :password => ""
6
+ }
7
+
8
+ require 'rubygems'
9
+ require 'pg'
10
+ $:.unshift((File.join(File.dirname(__FILE__), '..', 'lib')))
11
+
12
+ require "rspec"
13
+ require "active_record"
14
+
15
+ gem 'nofxx-georuby'
16
+ require 'postgis_adapter'
17
+ require 'logger'
18
+ # GeoRuby::SimpleFeatures::DEFAULT_SRID = -1
19
+
20
+ # Monkey patch Schema.define logger
21
+ $logger = Logger.new(StringIO.new)
22
+ def $logger.write(d); self.info(d); end
23
+ # $stdout = $logger
24
+
25
+ ActiveRecord::Base.logger = $logger
26
+
27
+ begin
28
+ ActiveRecord::Base.establish_connection(SPEC_DB)
29
+ ActiveRecord::Migration.verbose = false
30
+ PG_VERSION = ActiveRecord::Base.connection.select_value("SELECT version()").scan(/PostgreSQL ([\d\.]*)/)[0][0]
31
+
32
+ puts "Running against PostgreSQL #{PG_VERSION}"
33
+
34
+ require File.dirname(__FILE__) + '/db/schema_postgis.rb'
35
+ require File.dirname(__FILE__) + '/db/models_postgis.rb'
36
+
37
+ rescue PGError
38
+ puts "Test DB not found, creating one for you..."
39
+ `createdb -U #{SPEC_DB[:username]} #{SPEC_DB[:database]} -T template_postgis`
40
+ puts "Done. Please run spec again."
41
+ exit
42
+ end
43
+
44
+
45
+
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gotime-postgis_adapter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Marcos Piccinini
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-01 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nofxx-georuby
16
+ requirement: &2157135440 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2157135440
25
+ description: Execute PostGIS functions on Active Record
26
+ email: x@nofxx.com
27
+ executables: []
28
+ extensions: []
29
+ extra_rdoc_files:
30
+ - README.rdoc
31
+ files:
32
+ - Gemfile
33
+ - Gemfile.lock
34
+ - History.txt
35
+ - lib/postgis_adapter/acts_as_geom.rb
36
+ - lib/postgis_adapter/common_spatial_adapter.rb
37
+ - lib/postgis_adapter/functions/bbox.rb
38
+ - lib/postgis_adapter/functions/class.rb
39
+ - lib/postgis_adapter/functions/common.rb
40
+ - lib/postgis_adapter/functions.rb
41
+ - lib/postgis_adapter/railtie.rb
42
+ - lib/postgis_adapter.rb
43
+ - MIT-LICENSE
44
+ - postgis_adapter.gemspec
45
+ - rails/init.rb
46
+ - Rakefile
47
+ - README.rdoc
48
+ - spec/db/models_postgis.rb
49
+ - spec/db/schema_postgis.rb
50
+ - spec/postgis_adapter/acts_as_geom_spec.rb
51
+ - spec/postgis_adapter/common_spatial_adapter_spec.rb
52
+ - spec/postgis_adapter/functions/bbox_spec.rb
53
+ - spec/postgis_adapter/functions/class_spec.rb
54
+ - spec/postgis_adapter/functions/common_spec.rb
55
+ - spec/postgis_adapter/functions_spec.rb
56
+ - spec/postgis_adapter_spec.rb
57
+ - spec/spec_helper.rb
58
+ homepage: http://github.com/nofxx/postgis_adapter
59
+ licenses: []
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --charset=UTF-8
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project: postgis_adapter
79
+ rubygems_version: 1.8.5
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: PostGIS Adapter for Active Record
83
+ test_files:
84
+ - spec/db/models_postgis.rb
85
+ - spec/db/schema_postgis.rb
86
+ - spec/postgis_adapter/acts_as_geom_spec.rb
87
+ - spec/postgis_adapter/common_spatial_adapter_spec.rb
88
+ - spec/postgis_adapter/functions/bbox_spec.rb
89
+ - spec/postgis_adapter/functions/class_spec.rb
90
+ - spec/postgis_adapter/functions/common_spec.rb
91
+ - spec/postgis_adapter/functions_spec.rb
92
+ - spec/postgis_adapter_spec.rb
93
+ - spec/spec_helper.rb