postgis_adapter 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,254 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "CommonSpatialAdapter" do
4
+
5
+ class Park < ActiveRecord::Base; end
6
+ class Viewpark < ActiveRecord::Base; end
7
+
8
+ describe "Migration" do
9
+
10
+ before(:all) do
11
+ @connection = ActiveRecord::Base.connection
12
+ ActiveRecord::Schema.define do
13
+ create_table "parks", :force => true do |t|
14
+ t.string "data", :limit => 100
15
+ t.integer "value"
16
+ t.polygon "geom", :null=>false, :srid => 555 , :with_z => true,:with_m => true
17
+ end
18
+ end
19
+ end
20
+
21
+ it "should test_creation_modification" do
22
+ @connection.columns("parks").length.should eql(4) # the 3 defined + id
23
+ end
24
+
25
+ it "should test columns" do
26
+ @connection.columns("parks").each do |col|
27
+ if col.name == "geom"
28
+ col.class.should eql(ActiveRecord::ConnectionAdapters::SpatialPostgreSQLColumn)
29
+ col.geometry_type.should eql(:polygon)
30
+ col.type.should eql(:geometry)
31
+ col.null.should be_false
32
+ col.srid.should eql(555)
33
+ col.with_z.should be_true
34
+ col.with_m.should be_true
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "Add" do
40
+
41
+ before(:all)do
42
+ ActiveRecord::Schema.define do
43
+ add_column "parks","geom2", :multi_point
44
+ end
45
+ end
46
+
47
+ it "should test_creation_modification" do
48
+ @connection.columns("parks").length.should eql(5) # the 3 defined + id
49
+ end
50
+
51
+ it "should test columns" do
52
+ @connection.columns("parks").each do |col|
53
+ if col.name == "geom2"
54
+ col.class.should eql(ActiveRecord::ConnectionAdapters::SpatialPostgreSQLColumn)
55
+ col.geometry_type.should eql(:multi_point)
56
+ col.type.should eql(:geometry)
57
+ col.null.should be_true
58
+ col.srid.should eql(-1)
59
+ col.with_z.should be_false
60
+ col.with_m.should be_false
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ describe "remove" do
67
+ before(:all) do
68
+ ActiveRecord::Schema.define do
69
+ remove_column "parks","geom2"
70
+ end
71
+ end
72
+
73
+ it "should test_creation_modification" do
74
+ @connection.columns("parks").length.should eql(4) # the 3 defined + id
75
+ end
76
+
77
+ it "should get rid of the right one" do
78
+ @connection.columns("parks").each do |col|
79
+ violated if col.name == "geom2"
80
+ end
81
+ end
82
+ end
83
+
84
+ describe "indexes" do
85
+
86
+ it "should have 0 indexes" do
87
+ @connection.indexes("parks").length.should eql(0)
88
+ end
89
+
90
+ it "should create one" do
91
+ ActiveRecord::Schema.define do
92
+ add_index "parks","geom",:spatial=>true
93
+ end
94
+ @connection.indexes("parks").length.should eql(1)
95
+ @connection.indexes("parks")[0].spatial.should be_true
96
+ end
97
+
98
+ it "should remove too" do
99
+ ActiveRecord::Schema.define do
100
+ remove_index "parks", "geom"
101
+ end
102
+ @connection.indexes("parks").length.should eql(0)
103
+ end
104
+
105
+ it "should work with points" do
106
+ ActiveRecord::Schema.define do
107
+ remove_column "parks","geom2"
108
+ add_column "parks","geom2", :point
109
+ add_index "parks","geom2",:spatial=>true,:name => "example_spatial_index"
110
+ end
111
+ @connection.indexes("parks").length.should eql(1)
112
+ @connection.indexes("parks")[0].spatial.should be_true
113
+ @connection.indexes("parks")[0].name.should eql("example_spatial_index")
114
+ end
115
+
116
+ end
117
+
118
+ end
119
+
120
+ describe "Keywords" do
121
+
122
+ before(:all) do
123
+ ActiveRecord::Schema.define do
124
+ create_table "parks", :force => true do |t|
125
+ t.string "data", :limit => 100
126
+ t.integer "value"
127
+ #location is a postgreSQL keyword and is surrounded by double-quotes ("") when appearing in constraint descriptions ; tests a bug corrected in version 39
128
+ t.point "location", :null=>false,:srid => 0, :with_m => true, :with_z => true
129
+ end
130
+ end
131
+
132
+ @connection = ActiveRecord::Base.connection
133
+ @columns = @connection.columns("parks")
134
+ end
135
+
136
+ it "should get the columsn length" do
137
+ @connection.indexes("parks").length.should eql(0) # the 3 defined + id
138
+ end
139
+
140
+ it "should get the columns too" do
141
+ @connection.columns("parks").each do |col|
142
+ if col.name == "geom2"
143
+ col.class.should eql(ActiveRecord::ConnectionAdapters::SpatialPostgreSQLColumn)
144
+ col.geometry_type.should eql(:point)
145
+ col.type.should eql(:geometry)
146
+ col.null.should be_true
147
+ col.srid.should eql(-1)
148
+ col.with_z.should be_false
149
+ col.with_m.should be_false
150
+ end
151
+ end
152
+ end
153
+ end
154
+
155
+ describe "Views" do
156
+
157
+ before(:all) do
158
+ ActiveRecord::Schema.define do
159
+ create_table "parks", :force => true do |t|
160
+ t.column "data" , :string, :limit => 100
161
+ t.column "value", :integer
162
+ t.column "geom", :point,:null=>false
163
+ end
164
+ end
165
+
166
+ Park.create!(:data => "Test", :geom => Point.from_x_y(1.2,4.5))
167
+
168
+ ActiveRecord::Base.connection.execute('CREATE VIEW viewparks as SELECT * from parks')
169
+ #if not ActiveRecord::Base.connection.execute("select * from geometry_columns where f_table_name = 'viewparks' and f_geometry_column = 'geom'") #do not add if already there
170
+ #mark the geom column in the view as geometric
171
+ #ActiveRecord::Base.connection.execute("insert into geometry_columns values ('','public','viewparks','geom',2,-1,'POINT')")
172
+ #end
173
+ end
174
+
175
+ it "should works" do
176
+ pt = Viewpark.find(:first)
177
+ pt.data.should eql("Test")
178
+ pt.geom.should == Point.from_x_y(1.2,4.5)
179
+ end
180
+
181
+ after(:all) do
182
+ ActiveRecord::Base.connection.execute('DROP VIEW viewparks')
183
+ end end
184
+
185
+
186
+ describe "Dump" do
187
+ before(:all) do
188
+ #Force the creation of a table
189
+ ActiveRecord::Schema.define do
190
+ create_table "parks", :force => true do |t|
191
+ t.string "data" , :limit => 100
192
+ t.integer "value"
193
+ t.multi_polygon "geom", :null=>false,:srid => 0, :with_m => true, :with_z => true
194
+ end
195
+ add_index "parks","geom",:spatial=>true,:name => "example_spatial_index"
196
+ end
197
+ #dump it : tables from other tests will be dumped too but not a problem
198
+ File.open('schema.rb', "w") do |file|
199
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
200
+ end
201
+ #load it again
202
+ load('schema.rb')
203
+ #delete the schema file
204
+ File.delete('schema.rb')
205
+ @connection = ActiveRecord::Base.connection
206
+ @columns = @connection.columns("parks")
207
+ end
208
+
209
+ it "should create" do
210
+ @columns.length.should eql(4) # the 3 defined + id
211
+ end
212
+
213
+ it "should get the same stuff bakc" do
214
+ @columns.each do |col|
215
+ if col.name == "geom"
216
+ col.class.should eql(ActiveRecord::ConnectionAdapters::SpatialPostgreSQLColumn)
217
+ col.geometry_type.should eql(:multi_polygon)
218
+ col.type.should eql(:geometry)
219
+ col.null.should be_false
220
+ col.srid.should eql(0)
221
+ col.with_z.should be_true
222
+ col.with_m.should be_true
223
+ end
224
+ end
225
+ end
226
+
227
+ it "should get the indexes back too" do
228
+ @connection.indexes("parks").length.should eql(1)
229
+ @connection.indexes("parks")[0].spatial.should be_true
230
+ @connection.indexes("parks")[0].name.should eql("example_spatial_index")
231
+ end
232
+ end
233
+
234
+
235
+ describe "Fixtures" do
236
+
237
+ it "should test_long_fixture" do
238
+ Polygon.from_coordinates([[[144.857742,13.598263],
239
+ [144.862362,13.589922],[144.865169,13.587336],[144.862927,13.587665],
240
+ [144.861292,13.587321],[144.857597,13.585299],[144.847845,13.573858],
241
+ [144.846225,13.571014],[144.843605,13.566047],[144.842157,13.563831],
242
+ [144.841202,13.561991],[144.838305,13.556465],[144.834645,13.549919],
243
+ [144.834352,13.549395],[144.833825,13.548454],[144.831839,13.544451],
244
+ [144.830845,13.54081],[144.821543,13.545695],[144.8097993,13.55186285],
245
+ [144.814753,13.55755],[144.816744,13.56176944],[144.818862,13.566258],
246
+ [144.819402,13.568565],[144.822373,13.572223],[144.8242032,13.57381149],
247
+ [144.82634,13.575666],[144.83416,13.590365],[144.83514,13.595657],
248
+ [144.834284,13.59652],[144.834024,13.598031],[144.83719,13.598061],
249
+ [144.857742,13.598263]]]).to_fixture_format.split(/\s+/).should eql(["0103000020FFFFFFFF0100000020000000FBCC599F721B62404ED026874F322B40056A3178981B6240BF61A2410A2E2B406B10E676AF1B6240E486DF4DB72C2B40BC7A15199D1B6240F701486DE22C2B40CE893DB48F1B62400E828E56B52C2B40BA84436F711B624054C37E4FAC2B2B407862D68B211B62408F183DB7D0252B40D8817346141B6240C51D6FF25B242B40BFB7E9CFFE1A624071FF91E9D0212B401EA33CF3F21A624024F1F274AE202B408EEA7420EB1A6240ED4ACB48BD1F2B4058E20165D31A6240BEBC00FBE81C2B40A3586E69B51A6240E6E5B0FB8E192B40452BF702B31A6240FE2B2B4D4A192B40CA32C4B1AE1A624084B872F6CE182B403291D26C9E1A62408B8C0E48C2162B4072E14048961A624014B35E0CE5142B403FA88B144A1A6240732EC55565172B405CBA38E0E9196240344179C48D1A2B402C2AE274121A624005C58F31771D2B40892650C4221A62406D62793EA01F2B40FDBD141E341A62405D328E91EC212B40DD088B8A381A6240EC4CA1F31A232B40A1832EE1501A6240BB09BE69FA242B4046A863DF5F1A6240F23C9F9ECA252B400D6C9560711A624099D6A6B1BD262B4034F44F70B11A6240F5673F52442E2B409B728577B91A624056444DF4F9302B406FF25B74B21A6240E1D1C6116B312B4088821953B01A624005FD851E31322B4039D1AE42CA1A6240AF06280D35322B40FBCC599F721B62404ED026874F322B40"])
250
+ end
251
+
252
+ end
253
+
254
+ end
@@ -0,0 +1,4 @@
1
+ adapter: postgresql
2
+ database: postgis_plugin_test
3
+ username: postgres
4
+ password:
@@ -0,0 +1,56 @@
1
+ class TablePoint < ActiveRecord::Base
2
+ end
3
+
4
+ class TableKeywordColumnPoint < ActiveRecord::Base
5
+ end
6
+
7
+ class TableLineString < ActiveRecord::Base
8
+ end
9
+
10
+ class TablePolygon < ActiveRecord::Base
11
+ end
12
+
13
+ class TableMultiPoint < ActiveRecord::Base
14
+ end
15
+
16
+ class TableMultiLineString < ActiveRecord::Base
17
+ end
18
+
19
+ class TableMultiPolygon < ActiveRecord::Base
20
+ end
21
+
22
+ class TableGeometry < ActiveRecord::Base
23
+ end
24
+
25
+ class TableGeometryCollection < ActiveRecord::Base
26
+ end
27
+
28
+ class Table3dzPoint < ActiveRecord::Base
29
+ end
30
+
31
+ class Table3dmPoint < ActiveRecord::Base
32
+ end
33
+
34
+ class Table4dPoint < ActiveRecord::Base
35
+ end
36
+
37
+ class TableSridLineString < ActiveRecord::Base
38
+ end
39
+
40
+ class TableSrid4dPolygon < ActiveRecord::Base
41
+ end
42
+
43
+ class City < ActiveRecord::Base
44
+ acts_as_geom :geom
45
+ end
46
+
47
+ class Position < ActiveRecord::Base
48
+ acts_as_geom :geom
49
+ end
50
+
51
+ class Street < ActiveRecord::Base
52
+ acts_as_geom :geom
53
+ end
54
+
55
+ class CommonGeo < ActiveRecord::Base
56
+ end
@@ -0,0 +1,86 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ #add some postgis specific tables
4
+ ActiveRecord::Schema.define() do
5
+
6
+ create_table "table_points", :force => true do |t|
7
+ t.string "data"
8
+ t.point "geom", :null=>false
9
+ end
10
+
11
+ create_table "table_keyword_column_points", :force => true do |t|
12
+ t.point "location", :null => false
13
+ end
14
+
15
+ create_table "table_line_strings", :force => true do |t|
16
+ t.integer "value"
17
+ t.line_string "geom", :null=>false
18
+ end
19
+
20
+ create_table "table_polygons", :force => true do |t|
21
+ t.polygon "geom", :null=>false
22
+ end
23
+
24
+ create_table "table_multi_points", :force => true do |t|
25
+ t.multi_point "geom", :null=>false
26
+ end
27
+
28
+ create_table "table_multi_line_strings", :force => true do |t|
29
+ t.multi_line_string "geom", :null=>false
30
+ end
31
+
32
+ create_table "table_multi_polygons", :force => true do |t|
33
+ t.multi_polygon "geom", :null=>false
34
+ end
35
+
36
+ create_table "table_geometries", :force => true do |t|
37
+ t.geometry "geom", :null=>false
38
+ end
39
+
40
+ create_table "table_geometry_collections", :force => true do |t|
41
+ t.geometry_collection "geom", :null=>false
42
+ end
43
+
44
+ create_table "table3dz_points", :force => true do |t|
45
+ t.column "data", :string
46
+ t.point "geom", :null => false , :with_z => true
47
+ end
48
+
49
+ create_table "table3dm_points", :force => true do |t|
50
+ t.point "geom", :null => false , :with_m => true
51
+ end
52
+
53
+ create_table "table4d_points", :force => true do |t|
54
+ t.point "geom", :null => false, :with_m => true, :with_z => true
55
+ end
56
+
57
+ create_table "table_srid_line_strings", :force => true do |t|
58
+ t.line_string "geom", :null => false , :srid => 123
59
+ end
60
+
61
+ create_table "table_srid4d_polygons", :force => true do |t|
62
+ t.polygon "geom", :with_m => true, :with_z => true, :srid => 123
63
+ end
64
+
65
+ create_table :cities do |t|
66
+ t.string :data, :limit => 100
67
+ t.integer :value
68
+ t.polygon :geom,:null=>false,:srid=>123
69
+ end
70
+
71
+ create_table :positions do |t|
72
+ t.string :data, :limit => 100
73
+ t.integer :value
74
+ t.point :geom,:null=>false,:srid=>123
75
+ end
76
+
77
+ create_table :streets do |t|
78
+ t.string :data, :limit => 100
79
+ t.integer :value
80
+ t.line_string :geom,:null=>false,:srid=>123
81
+ end
82
+
83
+
84
+
85
+
86
+ end
@@ -0,0 +1,174 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "PostgisAdapter" do
4
+
5
+ describe "Point" do
6
+ it "should record a point nicely" do
7
+ pt = TablePoint.new(:data => "Test", :geom => Point.from_x_y(1.2,4.5))
8
+ pt.save.should be_true
9
+ end
10
+
11
+ it "should find a point nicely" do
12
+ find = TablePoint.find(:last)
13
+ find.should be_instance_of(TablePoint)
14
+ find.geom.should be_instance_of(Point)
15
+ end
16
+
17
+ it "should find`em all for hellsake..." do
18
+ find = TablePoint.all
19
+ find.should be_instance_of(Array)
20
+ find.last.geom.x.should eql(1.2)
21
+ end
22
+
23
+ it "should est_3dz_points" do
24
+ pt = Table3dzPoint.create!(:data => "Hello!",:geom => Point.from_x_y_z(-1.6,2.8,-3.4))
25
+ pt = Table3dzPoint.find(:first)
26
+ pt.geom.should be_instance_of(Point)
27
+ pt.geom.z.should eql(-3.4)
28
+ end
29
+
30
+ it "should est_3dm_points" do
31
+ pt = Table3dmPoint.create!(:geom => Point.from_x_y_m(-1.6,2.8,-3.4))
32
+ pt = Table3dmPoint.find(:first)
33
+ pt.geom.should == Point.from_x_y_m(-1.6,2.8,-3.4)
34
+ pt.geom.m.should eql(-3.4)
35
+ end
36
+ it "should est_4d_points" do
37
+ pt = Table4dPoint.create!(:geom => Point.from_x_y_z_m(-1.6,2.8,-3.4,15))
38
+ pt = Table4dPoint.find(:first)
39
+ pt.geom.should be_instance_of(Point)
40
+ pt.geom.z.should eql(-3.4)
41
+ pt.geom.m.should eql(15.0)
42
+ end
43
+
44
+ it "should test_keyword_column_point" do
45
+ pt = TableKeywordColumnPoint.create!(:location => Point.from_x_y(1.2,4.5))
46
+ find = TableKeywordColumnPoint.find(:first)
47
+ find.location.should == Point.from_x_y(1.2,4.5)
48
+ end
49
+
50
+ it "should test multipoint" do
51
+ mp = TableMultiPoint.create!(:geom => MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]]))
52
+ find = TableMultiPoint.find(:first)
53
+ find.geom.should == MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]])
54
+ end
55
+
56
+ end
57
+
58
+ describe "LineString" do
59
+ it "should record a linestring nicely" do
60
+ @ls = TableLineString.new(:value => 3, :geom => LineString.from_coordinates([[1.4,2.5],[1.5,6.7]]))
61
+ @ls.save.should be_true
62
+ end
63
+
64
+ it "should find" do
65
+ find = TableLineString.find(:first)
66
+ find.geom.should be_instance_of(LineString)
67
+ find.geom.points.first.y.should eql(2.5)
68
+ end
69
+
70
+ it "should test_srid_line_string" do
71
+ ls = TableSridLineString.create!(:geom => LineString.from_coordinates([[1.4,2.5],[1.5,6.7]],123))
72
+ ls = TableSridLineString.find(:first)
73
+ ls_e = LineString.from_coordinates([[1.4,2.5],[1.5,6.7]],123)
74
+ ls.geom.should be_instance_of(LineString)
75
+ ls.geom.srid.should eql(123)
76
+ end
77
+
78
+
79
+ it "hsould test_multi_line_string" do
80
+ ml = TableMultiLineString.create!(:geom => MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]]),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]])]))
81
+ find = TableMultiLineString.find(:first)
82
+ find.geom.should == MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]]),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]])])
83
+ end
84
+ end
85
+
86
+ describe "Polygon" do
87
+
88
+ it "should create" do
89
+ 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]]]))
90
+ pg.save.should be_true
91
+ end
92
+
93
+ it "should get it back" do
94
+ pg = TablePolygon.find(:first)
95
+ pg.geom.should be_instance_of(Polygon)
96
+ #assert_equal(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]]]),pg.geom)
97
+ end
98
+
99
+ it "should test_multi_polygon" do
100
+ 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]]])]))
101
+ find = TableMultiPolygon.find(:first)
102
+ 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]]])])
103
+ end
104
+
105
+ it "should test_srid_4d_polygon" do
106
+ 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,123],[3,3,2,12.2],[1,3,2,12],[1,1,2,12.3]]],123,true,true))
107
+ find = TableSrid4dPolygon.find(:first)
108
+ 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,123],[3,3,2,12.2],[1,3,2,12],[1,1,2,12.3]]],123,true,true)
109
+ pg.geom.should == pg_e
110
+ pg.geom.srid.should eql(123)
111
+ end
112
+ end
113
+
114
+ describe "Geometry" do
115
+
116
+
117
+ it "should test_geometry" do
118
+ gm = TableGeometry.create!(:geom => LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]]))
119
+ find = TableGeometry.find(:first)
120
+ find.geom.should == LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]])
121
+ end
122
+
123
+ it "should test_geometry_collection" do
124
+ 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]])]))
125
+ find = TableGeometryCollection.find(:first)
126
+ find.geom.should == GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4),LineString.from_coordinates([[5.7,12.45],[67.55,54]])])
127
+ end
128
+
129
+ end
130
+
131
+ describe "Find" do
132
+ before(:all) do
133
+ ActiveRecord::Schema.define() do
134
+ create_table "parks", :force => true do |t|
135
+ t.column "data" , :string, :limit => 100
136
+ t.column "value", :integer
137
+ t.column "geom", :point,:null=>false,:srid=>123
138
+ end
139
+ add_index "parks","geom",:spatial=>true,:name => "example_spatial_index"
140
+ end
141
+ class Park < ActiveRecord::Base
142
+ end
143
+ end
144
+
145
+ it "should create some points" do
146
+ Park.create!(:data => "Point1", :geom => Point.from_x_y(1.2,0.75,123))
147
+ Park.create!(:data => "Point2",:geom => Point.from_x_y(0.6,1.3,123))
148
+ Park.create!(:data => "Point3", :geom => Point.from_x_y(2.5,2,123))
149
+ end
150
+
151
+ it "should find by geom" do
152
+ pts = Park.find_all_by_geom(LineString.from_coordinates([[0,0],[2,2]],123))
153
+ pts.should be_instance_of(Array)
154
+ pts.length.should eql(2)
155
+ pts[0].data.should match /Point/
156
+ pts[1].data.should match /Point/
157
+ end
158
+
159
+ it "should find by geom again" do
160
+ pts = Park.find_all_by_geom(LineString.from_coordinates([[2.49,1.99],[2.51,2.01]],123))
161
+ pts[0].data.should eql("Point3")
162
+ end
163
+
164
+ it "should find by geom column bbox condition" do
165
+ pts = Park.find_all_by_geom([[0,0],[2,2],123])
166
+ pts.should be_instance_of(Array)
167
+ pts.length.should eql(2)
168
+ pts[0].data.should match /Point/
169
+ pts[1].data.should match /Point/
170
+ end
171
+
172
+ end
173
+
174
+ end