activerecord-spatial 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1670 -0
  3. data/Gemfile +12 -13
  4. data/Guardfile +7 -10
  5. data/MIT-LICENSE +1 -1
  6. data/README.rdoc +8 -19
  7. data/Rakefile +2 -1
  8. data/activerecord-spatial.gemspec +12 -13
  9. data/lib/activerecord-spatial/active_record/connection_adapters/postgresql/adapter_extensions/active_record.rb +46 -0
  10. data/lib/activerecord-spatial/active_record/connection_adapters/postgresql/adapter_extensions.rb +7 -38
  11. data/lib/activerecord-spatial/active_record/connection_adapters/postgresql/postgis.rb +6 -7
  12. data/lib/activerecord-spatial/active_record/connection_adapters/postgresql/unknown_srid.rb +4 -5
  13. data/lib/activerecord-spatial/active_record/models/geography_column.rb +1 -2
  14. data/lib/activerecord-spatial/active_record/models/geometry_column.rb +1 -2
  15. data/lib/activerecord-spatial/active_record/models/spatial_column.rb +1 -2
  16. data/lib/activerecord-spatial/active_record/models/spatial_ref_sys.rb +5 -6
  17. data/lib/activerecord-spatial/active_record.rb +0 -1
  18. data/lib/activerecord-spatial/associations/active_record.rb +62 -120
  19. data/lib/activerecord-spatial/associations/base.rb +26 -75
  20. data/lib/activerecord-spatial/associations/preloader/spatial_association.rb +57 -0
  21. data/lib/activerecord-spatial/associations/reflection/spatial_reflection.rb +41 -0
  22. data/lib/activerecord-spatial/associations.rb +26 -4
  23. data/lib/activerecord-spatial/spatial_columns.rb +85 -94
  24. data/lib/activerecord-spatial/spatial_function.rb +62 -51
  25. data/lib/activerecord-spatial/spatial_scope_constants/postgis_2_0.rb +48 -0
  26. data/lib/activerecord-spatial/spatial_scope_constants/postgis_2_2.rb +46 -0
  27. data/lib/activerecord-spatial/spatial_scope_constants/postgis_legacy.rb +30 -0
  28. data/lib/activerecord-spatial/spatial_scope_constants.rb +10 -61
  29. data/lib/activerecord-spatial/spatial_scopes.rb +47 -49
  30. data/lib/activerecord-spatial/version.rb +1 -2
  31. data/lib/activerecord-spatial.rb +2 -6
  32. data/lib/tasks/test.rake +21 -19
  33. data/test/.rubocop.yml +35 -0
  34. data/test/accessors_geographies_tests.rb +19 -19
  35. data/test/accessors_geometries_tests.rb +19 -19
  36. data/test/adapter_tests.rb +1 -2
  37. data/test/associations_tests.rb +181 -203
  38. data/test/geography_column_tests.rb +2 -3
  39. data/test/geometry_column_tests.rb +1 -2
  40. data/test/models/bar.rb +2 -3
  41. data/test/models/blort.rb +1 -2
  42. data/test/models/foo.rb +2 -3
  43. data/test/models/foo3d.rb +2 -3
  44. data/test/models/foo_geography.rb +2 -3
  45. data/test/models/zortable.rb +2 -3
  46. data/test/spatial_function_tests.rb +12 -17
  47. data/test/spatial_scopes_geographies_tests.rb +17 -20
  48. data/test/spatial_scopes_tests.rb +84 -75
  49. data/test/test_helper.rb +66 -79
  50. metadata +16 -14
  51. data/lib/activerecord-spatial/associations/active_record_3.rb +0 -123
@@ -1,5 +1,5 @@
1
1
 
2
- $: << File.dirname(__FILE__)
2
+ $LOAD_PATH << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
5
  class DefaultIntersectsRelationshipTest < ActiveRecordSpatialTestCase
@@ -12,12 +12,18 @@ class DefaultIntersectsRelationshipTest < ActiveRecordSpatialTestCase
12
12
  end
13
13
 
14
14
  def test_reflection
15
- assert_equal(:has_many, Foo.reflections[:bars].macro)
16
- assert_equal(:intersects, Foo.reflections[:bars].options[:relationship])
15
+ assert_equal(:has_many, Foo.reflections[reflection_key(:bars)].macro)
16
+ assert_equal(:intersects, Foo.reflections[reflection_key(:bars)].options[:relationship])
17
17
  end
18
18
 
19
19
  def test_association
20
- assert_equal([ 3 ], Foo.first.bars.collect(&:id).sort)
20
+ values = nil
21
+
22
+ assert_sql(/ST_intersects\('#{REGEXP_WKB_HEX}'::geometry, "bars"\."the_geom"/) do
23
+ values = Foo.first.bars.collect(&:id).sort
24
+ end
25
+
26
+ assert_equal([3], values)
21
27
  end
22
28
  end
23
29
 
@@ -27,19 +33,19 @@ class RelationshipsTest < ActiveRecordSpatialTestCase
27
33
  end
28
34
 
29
35
  {
30
- :contains => [],
31
- :containsproperly => [],
32
- :covers => [],
33
- :coveredby => [ 3 ],
34
- :crosses => [],
35
- :disjoint => [ 1, 2 ],
36
- :equals => [],
37
- :intersects => [ 3 ],
38
- :orderingequals => [],
39
- :overlaps => [],
40
- :touches => [],
41
- :within => [ 3 ],
42
- :'3dintersects' => [ 3 ]
36
+ contains: [],
37
+ containsproperly: [],
38
+ covers: [],
39
+ coveredby: [3],
40
+ crosses: [],
41
+ disjoint: [1, 2],
42
+ equals: [],
43
+ intersects: [3],
44
+ orderingequals: [],
45
+ overlaps: [],
46
+ touches: [],
47
+ within: [3],
48
+ :'3dintersects' => [3]
43
49
  }.each do |relationship, ids|
44
50
  define_method("test_#{relationship}") do
45
51
  skip("ST_#{relationship} is unavailable") unless Foo.respond_to?("st_#{relationship}")
@@ -47,11 +53,11 @@ class RelationshipsTest < ActiveRecordSpatialTestCase
47
53
  Foo.reflections.delete(:bars)
48
54
 
49
55
  Foo.class_eval do
50
- has_many_spatially :bars, :relationship => relationship
56
+ has_many_spatially :bars, relationship: relationship
51
57
  end
52
58
 
53
- assert_equal(:has_many, Foo.reflections[:bars].macro)
54
- assert_equal(relationship, Foo.reflections[:bars].options[:relationship])
59
+ assert_equal(:has_many, Foo.reflections[reflection_key(:bars)].macro)
60
+ assert_equal(relationship, Foo.reflections[reflection_key(:bars)].options[:relationship])
55
61
  assert_equal(ids, Foo.first.bars.collect(&:id).sort)
56
62
  end
57
63
  end
@@ -63,19 +69,19 @@ class RelationshipsWithSelfTest < ActiveRecordSpatialTestCase
63
69
  end
64
70
 
65
71
  {
66
- :contains => [ 1 ],
67
- :containsproperly => [ 1 ],
68
- :covers => [ 1 ],
69
- :coveredby => [ 1, 3 ],
70
- :crosses => [],
71
- :disjoint => [ 2 ],
72
- :equals => [ 1 ],
73
- :intersects => [ 1, 3 ],
74
- :orderingequals => [ 1 ],
75
- :overlaps => [],
76
- :touches => [],
77
- :within => [ 1, 3 ],
78
- :'3dintersects' => [ 1, 3 ]
72
+ contains: [1],
73
+ containsproperly: [1],
74
+ covers: [1],
75
+ coveredby: [1, 3],
76
+ crosses: [],
77
+ disjoint: [2],
78
+ equals: [1],
79
+ intersects: [1, 3],
80
+ orderingequals: [1],
81
+ overlaps: [],
82
+ touches: [],
83
+ within: [1, 3],
84
+ :'3dintersects' => [1, 3]
79
85
  }.each do |relationship, ids|
80
86
  define_method("test_#{relationship}") do
81
87
  skip("ST_#{relationship} is unavailable") unless Foo.respond_to?("st_#{relationship}")
@@ -83,11 +89,11 @@ class RelationshipsWithSelfTest < ActiveRecordSpatialTestCase
83
89
  Foo.reflections.delete(:foos)
84
90
 
85
91
  Foo.class_eval do
86
- has_many_spatially :foos, :relationship => relationship
92
+ has_many_spatially :foos, relationship: relationship
87
93
  end
88
94
 
89
- assert_equal(:has_many, Foo.reflections[:foos].macro)
90
- assert_equal(relationship, Foo.reflections[:foos].options[:relationship])
95
+ assert_equal(:has_many, Foo.reflections[reflection_key(:foos)].macro)
96
+ assert_equal(relationship, Foo.reflections[reflection_key(:foos)].options[:relationship])
91
97
  assert_equal(ids, Foo.first.foos.collect(&:id).sort)
92
98
  end
93
99
  end
@@ -99,19 +105,19 @@ class RelationshipsWithForeignGeomTest < ActiveRecordSpatialTestCase
99
105
  end
100
106
 
101
107
  {
102
- :contains => [],
103
- :containsproperly => [],
104
- :covers => [],
105
- :coveredby => [ 3 ],
106
- :crosses => [],
107
- :disjoint => [ 1, 2 ],
108
- :equals => [],
109
- :intersects => [ 3 ],
110
- :orderingequals => [],
111
- :overlaps => [],
112
- :touches => [],
113
- :within => [ 3 ],
114
- :'3dintersects' => [ 3 ]
108
+ contains: [],
109
+ containsproperly: [],
110
+ covers: [],
111
+ coveredby: [3],
112
+ crosses: [],
113
+ disjoint: [1, 2],
114
+ equals: [],
115
+ intersects: [3],
116
+ orderingequals: [],
117
+ overlaps: [],
118
+ touches: [],
119
+ within: [3],
120
+ :'3dintersects' => [3]
115
121
  }.each do |relationship, ids|
116
122
  define_method("test_#{relationship}") do
117
123
  skip("ST_#{relationship} is unavailable") unless Foo.respond_to?("st_#{relationship}")
@@ -120,14 +126,14 @@ class RelationshipsWithForeignGeomTest < ActiveRecordSpatialTestCase
120
126
 
121
127
  Foo.class_eval do
122
128
  has_many_spatially :bars,
123
- :relationship => relationship,
124
- :foreign_geom => :the_other_geom
129
+ relationship: relationship,
130
+ foreign_geom: :the_other_geom
125
131
  end
126
132
 
127
- assert_equal(:has_many, Foo.reflections[:bars].macro)
128
- assert_equal(relationship, Foo.reflections[:bars].options[:relationship])
129
- assert_equal(:the_geom, Foo.reflections[:bars].options[:geom])
130
- assert_equal(:the_other_geom, Foo.reflections[:bars].options[:foreign_geom])
133
+ assert_equal(:has_many, Foo.reflections[reflection_key(:bars)].macro)
134
+ assert_equal(relationship, Foo.reflections[reflection_key(:bars)].options[:relationship])
135
+ assert_equal(:the_geom, Foo.reflections[reflection_key(:bars)].options[:geom])
136
+ assert_equal(:the_other_geom, Foo.reflections[reflection_key(:bars)].options[:foreign_geom])
131
137
  assert_equal(ids, Foo.first.bars.collect(&:id).sort)
132
138
  end
133
139
  end
@@ -139,19 +145,19 @@ class RelationshipsWithGeomTest < ActiveRecordSpatialTestCase
139
145
  end
140
146
 
141
147
  {
142
- :contains => [],
143
- :containsproperly => [],
144
- :covers => [],
145
- :coveredby => [ 3 ],
146
- :crosses => [],
147
- :disjoint => [ 1, 2 ],
148
- :equals => [],
149
- :intersects => [ 3 ],
150
- :orderingequals => [],
151
- :overlaps => [],
152
- :touches => [ 3 ],
153
- :within => [],
154
- :'3dintersects' => [ 3 ]
148
+ contains: [],
149
+ containsproperly: [],
150
+ covers: [],
151
+ coveredby: [3],
152
+ crosses: [],
153
+ disjoint: [1, 2],
154
+ equals: [],
155
+ intersects: [3],
156
+ orderingequals: [],
157
+ overlaps: [],
158
+ touches: [3],
159
+ within: [],
160
+ :'3dintersects' => [3]
155
161
  }.each do |relationship, ids|
156
162
  define_method("test_#{relationship}") do
157
163
  skip("ST_#{relationship} is unavailable") unless Foo.respond_to?("st_#{relationship}")
@@ -160,14 +166,14 @@ class RelationshipsWithGeomTest < ActiveRecordSpatialTestCase
160
166
 
161
167
  Foo.class_eval do
162
168
  has_many_spatially :bars,
163
- :relationship => relationship,
164
- :geom => :the_other_geom
169
+ relationship: relationship,
170
+ geom: :the_other_geom
165
171
  end
166
172
 
167
- assert_equal(:has_many, Foo.reflections[:bars].macro)
168
- assert_equal(relationship, Foo.reflections[:bars].options[:relationship])
169
- assert_equal(:the_other_geom, Foo.reflections[:bars].options[:geom])
170
- assert_equal(:the_geom, Foo.reflections[:bars].options[:foreign_geom])
173
+ assert_equal(:has_many, Foo.reflections[reflection_key(:bars)].macro)
174
+ assert_equal(relationship, Foo.reflections[reflection_key(:bars)].options[:relationship])
175
+ assert_equal(:the_other_geom, Foo.reflections[reflection_key(:bars)].options[:geom])
176
+ assert_equal(:the_geom, Foo.reflections[reflection_key(:bars)].options[:foreign_geom])
171
177
  assert_equal(ids, Foo.first.bars.collect(&:id).sort)
172
178
  end
173
179
  end
@@ -193,8 +199,8 @@ class WithCounterSqlTest < ActiveRecordSpatialTestCase
193
199
  assert_raise(ArgumentError) do
194
200
  Foo.class_eval do
195
201
  has_many_spatially :bars,
196
- :class_name => 'Bar',
197
- :counter_sql => "SELECT COUNT(*) bars.* FROM bars"
202
+ class_name: 'Bar',
203
+ counter_sql: 'SELECT COUNT(*) bars.* FROM bars'
198
204
  end
199
205
  end
200
206
  end
@@ -206,9 +212,9 @@ class ScopeOptionsTest < ActiveRecordSpatialTestCase
206
212
 
207
213
  Foo.class_eval do
208
214
  has_many_spatially :bars,
209
- :class_name => 'Bar',
210
- :scope_options => {
211
- :use_index => false
215
+ class_name: 'Bar',
216
+ scope_options: {
217
+ use_index: false
212
218
  }
213
219
  end
214
220
  end
@@ -235,7 +241,7 @@ class PreloadTest < ActiveRecordSpatialTestCase
235
241
  end
236
242
  end
237
243
 
238
- assert_equal([ 1, 1, 2], values)
244
+ assert_equal([1, 1, 2], values)
239
245
  end
240
246
 
241
247
  def test_with_eager_loading
@@ -248,7 +254,7 @@ class PreloadTest < ActiveRecordSpatialTestCase
248
254
  end
249
255
  end
250
256
 
251
- assert_equal([ 1, 1, 2 ], values)
257
+ assert_equal([1, 1, 2], values)
252
258
  end
253
259
  end
254
260
 
@@ -258,8 +264,8 @@ class PreloadWithOtherGeomTest < ActiveRecordSpatialTestCase
258
264
 
259
265
  Foo.class_eval do
260
266
  has_many_spatially :bars,
261
- :class_name => 'Bar',
262
- :geom => :the_other_geom
267
+ class_name: 'Bar',
268
+ geom: :the_other_geom
263
269
  end
264
270
  end
265
271
 
@@ -273,7 +279,7 @@ class PreloadWithOtherGeomTest < ActiveRecordSpatialTestCase
273
279
  end
274
280
  end
275
281
 
276
- assert_equal([ 1, 0, 2 ], values)
282
+ assert_equal([1, 0, 2], values)
277
283
  end
278
284
 
279
285
  def test_with_eager_loading
@@ -286,27 +292,7 @@ class PreloadWithOtherGeomTest < ActiveRecordSpatialTestCase
286
292
  end
287
293
  end
288
294
 
289
- assert_equal([ 1, 0, 2 ], values)
290
- end
291
- end
292
-
293
- class OrderingTest < ActiveRecordSpatialTestCase
294
- def self.before_suite
295
- load_models(:foo, :bar)
296
-
297
- Foo.class_eval do
298
- has_many_spatially :bars,
299
- :relationship => :disjoint,
300
- :order => 'ST_area(the_geom)'
301
- end
302
- end
303
-
304
- def test_ordering
305
- assert_equal([ 1, 2 ], Foo.first.bars.collect(&:id))
306
- end
307
-
308
- def test_reordering
309
- assert_equal([ 2, 1 ], Foo.first.bars.reorder('bars.id DESC').collect(&:id))
295
+ assert_equal([1, 0, 2], values)
310
296
  end
311
297
  end
312
298
 
@@ -316,13 +302,13 @@ class PolymorphicAssociationsTest < ActiveRecordSpatialTestCase
316
302
 
317
303
  Foo.class_eval do
318
304
  has_many_spatially :zortables,
319
- :as => :zortable
305
+ as: :zortable
320
306
  end
321
307
 
322
308
  Bar.class_eval do
323
309
  has_many_spatially :zortables,
324
- :as => :zortable,
325
- :geom => :the_other_geom
310
+ as: :zortable,
311
+ geom: :the_other_geom
326
312
  end
327
313
  end
328
314
 
@@ -334,7 +320,7 @@ class PolymorphicAssociationsTest < ActiveRecordSpatialTestCase
334
320
  end
335
321
  end
336
322
 
337
- assert_equal([ 1, 7 ], values)
323
+ assert_equal([1, 7], values)
338
324
  end
339
325
 
340
326
  def test_without_eager_loading_and_geom
@@ -345,29 +331,35 @@ class PolymorphicAssociationsTest < ActiveRecordSpatialTestCase
345
331
  end
346
332
  end
347
333
 
348
- assert_equal([ 6 ], values)
334
+ assert_equal([6], values)
349
335
  end
350
336
 
351
337
  def test_with_eager_loading
352
338
  values = nil
353
- assert_queries(2) do
354
- assert_sql(/SELECT "zortables"\.\*, array_to_string\(array_agg\("__spatial_ids_join__"."id"\), ','\) AS "__spatial_ids__" FROM "zortables" INNER JOIN "foos" AS "__spatial_ids_join__" ON \(ST_intersects\("__spatial_ids_join__"."the_geom", "zortables"."zortable_geom"\)\) WHERE "zortables"."zortable_type" = 'Foo' AND "__spatial_ids_join__"\."id" IN \(.+\) GROUP BY "zortables"\."id"/) do
355
- values = Foo.includes(:zortables).first.zortables.collect(&:id).sort
339
+
340
+ Foo.connection.unprepared_statement do
341
+ assert_queries(2) do
342
+ assert_sql(/SELECT "zortables"\.\*, array_to_string\(array_agg\("__spatial_ids_join__"."id"\), ','\) AS "__spatial_ids__" FROM "zortables" INNER JOIN "foos" AS "__spatial_ids_join__" ON \(ST_intersects\("__spatial_ids_join__"."the_geom", "zortables"."zortable_geom"\)\) WHERE "zortables"."zortable_type" = 'Foo' AND "__spatial_ids_join__"\."id" IN \(.+\) GROUP BY "zortables"\."id"/) do
343
+ values = Foo.includes(:zortables).first.zortables.collect(&:id).sort
344
+ end
356
345
  end
357
346
  end
358
347
 
359
- assert_equal([ 1, 7 ], values)
348
+ assert_equal([1, 7], values)
360
349
  end
361
350
 
362
351
  def test_with_eager_loading_and_geom
363
352
  values = nil
364
- assert_queries(2) do
365
- assert_sql(/SELECT "zortables"\.\*, array_to_string\(array_agg\("__spatial_ids_join__"."id"\), ','\) AS "__spatial_ids__" FROM "zortables" INNER JOIN "bars" AS "__spatial_ids_join__" ON \(ST_intersects\(ST_SetSRID\("__spatial_ids_join__"."the_other_geom", #{ActiveRecordSpatial::UNKNOWN_SRID}\), "zortables"."zortable_geom"\)\) WHERE "zortables"."zortable_type" = 'Bar' AND "__spatial_ids_join__"\."id" IN \(.+\) GROUP BY "zortables"\."id"/) do
366
- values = Bar.includes(:zortables).first.zortables.collect(&:id).sort
353
+
354
+ Bar.connection.unprepared_statement do
355
+ assert_queries(2) do
356
+ assert_sql(/SELECT "zortables"\.\*, array_to_string\(array_agg\("__spatial_ids_join__"."id"\), ','\) AS "__spatial_ids__" FROM "zortables" INNER JOIN "bars" AS "__spatial_ids_join__" ON \(ST_intersects\(ST_SetSRID\("__spatial_ids_join__"."the_other_geom", #{ActiveRecordSpatial::UNKNOWN_SRID}\), "zortables"."zortable_geom"\)\) WHERE "zortables"."zortable_type" = 'Bar' AND "__spatial_ids_join__"\."id" IN \(.+\) GROUP BY "zortables"\."id"/) do
357
+ values = Bar.includes(:zortables).first.zortables.collect(&:id).sort
358
+ end
367
359
  end
368
360
  end
369
361
 
370
- assert_equal([ 6 ], values)
362
+ assert_equal([6], values)
371
363
  end
372
364
  end
373
365
 
@@ -377,19 +369,19 @@ class PolymorphicAssociationsWithRelationshipsTest < ActiveRecordSpatialTestCase
377
369
  end
378
370
 
379
371
  {
380
- :contains => [ 1 ],
381
- :containsproperly => [ 1 ],
382
- :covers => [ 1 ],
383
- :coveredby => [ 1, 7 ],
384
- :crosses => [],
385
- :disjoint => [ 2, 3 ],
386
- :equals => [ 1 ],
387
- :intersects => [ 1, 7 ],
388
- :orderingequals => [ 1 ],
389
- :overlaps => [],
390
- :touches => [],
391
- :within => [ 1, 7 ],
392
- :'3dintersects' => [ 1, 7 ]
372
+ contains: [1],
373
+ containsproperly: [1],
374
+ covers: [1],
375
+ coveredby: [1, 7],
376
+ crosses: [],
377
+ disjoint: [2, 3],
378
+ equals: [1],
379
+ intersects: [1, 7],
380
+ orderingequals: [1],
381
+ overlaps: [],
382
+ touches: [],
383
+ within: [1, 7],
384
+ :'3dintersects' => [1, 7]
393
385
  }.each do |relationship, ids|
394
386
  define_method("test_#{relationship}") do
395
387
  skip("ST_#{relationship} is unavailable") unless Foo.respond_to?("st_#{relationship}")
@@ -398,8 +390,8 @@ class PolymorphicAssociationsWithRelationshipsTest < ActiveRecordSpatialTestCase
398
390
 
399
391
  Foo.class_eval do
400
392
  has_many_spatially :zortables,
401
- :as => :zortable,
402
- :relationship => relationship
393
+ as: :zortable,
394
+ relationship: relationship
403
395
  end
404
396
 
405
397
  assert_equal(ids, Foo.first.zortables.collect(&:id).sort)
@@ -414,62 +406,49 @@ class ClassNameOptionTest < ActiveRecordSpatialTestCase
414
406
 
415
407
  Foo.class_eval do
416
408
  has_many_spatially :blops,
417
- :class_name => 'Bar'
409
+ class_name: 'Bar'
418
410
  end
419
411
  end
420
412
 
421
413
  def test_class_name
422
- assert_equal([ 3 ], Foo.first.blops.collect(&:id))
423
- assert_equal([ 3 ], Foo.includes(:blops).first.blops.collect(&:id))
414
+ assert_equal([3], Foo.first.blops.collect(&:id))
415
+ assert_equal([3], Foo.includes(:blops).first.blops.collect(&:id))
424
416
  end
425
417
  end
426
418
 
427
- class ConditionsOptionTest < ActiveRecordSpatialTestCase
419
+ class ScopesTest < ActiveRecordSpatialTestCase
428
420
  def self.before_suite
429
421
  load_models(:foo, :bar)
430
422
 
431
423
  Foo.class_eval do
432
- has_many_spatially :bars,
433
- :relationship => :disjoint,
434
- :conditions => {
435
- :bars => {
436
- :id => 3
437
- }
438
- }
424
+ has_many_spatially :bars, -> {
425
+ where(bars: { id: 3 })
426
+ }, relationship: :disjoint
439
427
  end
440
428
  end
441
429
 
442
- def test_conditions
443
- assert_equal([], Foo.first.bars.collect(&:id))
444
- assert_equal([], Foo.includes(:bars).first.bars.collect(&:id))
445
- end
446
- end
447
-
448
- class IncludeOptionTest < ActiveRecordSpatialTestCase
449
- def self.before_suite
450
- load_models(:blort, :foo, :bar)
430
+ def test_scopes_without_eager_loading
431
+ values = nil
451
432
 
452
- Foo.class_eval do
453
- has_many :blorts
433
+ Foo.connection.unprepared_statement do
434
+ assert_sql(/SELECT "bars".* FROM "bars"\s+WHERE \(ST_disjoint\('#{REGEXP_WKB_HEX}'::geometry, "bars"."the_geom"\)\) AND "bars"."id" = 3/) do
435
+ values = Foo.first.bars.collect(&:id)
436
+ end
454
437
  end
455
438
 
456
- Bar.class_eval do
457
- has_many_spatially :foos,
458
- :include => :blorts
459
- end
439
+ assert_equal([], values)
460
440
  end
461
441
 
462
- def test_includes
463
- skip("Removed from AR 4") if ActiveRecord::VERSION::MAJOR >= 4
464
-
442
+ def test_scopes_with_eager_loading
465
443
  values = nil
466
- assert_queries(3) do
467
- assert_sql(/SELECT\s+"blorts"\.\*\s+FROM\s+"blorts"\s+WHERE\s+"blorts"\."foo_id"\s+IN\s+\(.+\)/) do
468
- values = Bar.first.foos.collect(&:id)
444
+
445
+ Foo.connection.unprepared_statement do
446
+ assert_sql(/SELECT "bars"\.\*, array_to_string\(array_agg\("__spatial_ids_join__"."id"\), ','\) AS "__spatial_ids__" FROM "bars" INNER JOIN "foos" AS "__spatial_ids_join__" ON \(ST_disjoint\("__spatial_ids_join__"."the_geom", "bars"."the_geom"\)\) WHERE "bars"."id" = 3 AND "__spatial_ids_join__"\."id" IN \(.+\) GROUP BY "bars"\."id"/) do
447
+ values = Foo.includes(:bars).first.bars.collect(&:id)
469
448
  end
470
449
  end
471
450
 
472
- assert_equal([ 3 ], values)
451
+ assert_equal([], values)
473
452
  end
474
453
  end
475
454
 
@@ -479,9 +458,9 @@ class GeomWrapperTest < ActiveRecordSpatialTestCase
479
458
 
480
459
  Foo.class_eval do
481
460
  has_many_spatially :bars,
482
- :class_name => 'Bar',
483
- :geom => {
484
- :wrapper => :envelope
461
+ class_name: 'Bar',
462
+ geom: {
463
+ wrapper: :envelope
485
464
  }
486
465
  end
487
466
  end
@@ -493,7 +472,7 @@ class GeomWrapperTest < ActiveRecordSpatialTestCase
493
472
  values = Foo.first.bars.collect(&:id).sort
494
473
  end
495
474
 
496
- assert_equal([ 3 ], values)
475
+ assert_equal([3], values)
497
476
  end
498
477
 
499
478
  def test_with_eager_loading
@@ -503,7 +482,7 @@ class GeomWrapperTest < ActiveRecordSpatialTestCase
503
482
  values = Foo.includes(:bars).first.bars.collect(&:id).sort
504
483
  end
505
484
 
506
- assert_equal([ 3 ], values)
485
+ assert_equal([3], values)
507
486
  end
508
487
  end
509
488
 
@@ -513,9 +492,9 @@ class ForeignGeomWrapperTest < ActiveRecordSpatialTestCase
513
492
 
514
493
  Foo.class_eval do
515
494
  has_many_spatially :bars,
516
- :class_name => 'Bar',
517
- :foreign_geom => {
518
- :wrapper => :envelope
495
+ class_name: 'Bar',
496
+ foreign_geom: {
497
+ wrapper: :envelope
519
498
  }
520
499
  end
521
500
  end
@@ -527,7 +506,7 @@ class ForeignGeomWrapperTest < ActiveRecordSpatialTestCase
527
506
  values = Foo.first.bars.collect(&:id).sort
528
507
  end
529
508
 
530
- assert_equal([ 3 ], values)
509
+ assert_equal([3], values)
531
510
  end
532
511
 
533
512
  def test_with_eager_loading
@@ -537,7 +516,7 @@ class ForeignGeomWrapperTest < ActiveRecordSpatialTestCase
537
516
  values = Foo.includes(:bars).first.bars.collect(&:id).sort
538
517
  end
539
518
 
540
- assert_equal([ 3 ], values)
519
+ assert_equal([3], values)
541
520
  end
542
521
  end
543
522
 
@@ -547,12 +526,12 @@ class BothGeomWrapperTest < ActiveRecordSpatialTestCase
547
526
 
548
527
  Foo.class_eval do
549
528
  has_many_spatially :bars,
550
- :class_name => 'Bar',
551
- :geom => {
552
- :wrapper => :convexhull
529
+ class_name: 'Bar',
530
+ geom: {
531
+ wrapper: :convexhull
553
532
  },
554
- :foreign_geom => {
555
- :wrapper => :envelope
533
+ foreign_geom: {
534
+ wrapper: :envelope
556
535
  }
557
536
  end
558
537
  end
@@ -564,7 +543,7 @@ class BothGeomWrapperTest < ActiveRecordSpatialTestCase
564
543
  values = Foo.first.bars.collect(&:id).sort
565
544
  end
566
545
 
567
- assert_equal([ 3 ], values)
546
+ assert_equal([3], values)
568
547
  end
569
548
 
570
549
  def test_with_eager_loading
@@ -574,7 +553,7 @@ class BothGeomWrapperTest < ActiveRecordSpatialTestCase
574
553
  values = Foo.includes(:bars).first.bars.collect(&:id).sort
575
554
  end
576
555
 
577
- assert_equal([ 3 ], values)
556
+ assert_equal([3], values)
578
557
  end
579
558
  end
580
559
 
@@ -584,13 +563,13 @@ class BothGeomWrapperWithMixedSRIDsTest < ActiveRecordSpatialTestCase
584
563
 
585
564
  Foo.class_eval do
586
565
  has_many_spatially :bars,
587
- :class_name => 'Bar',
588
- :geom => {
589
- :wrapper => :convexhull
566
+ class_name: 'Bar',
567
+ geom: {
568
+ wrapper: :convexhull
590
569
  },
591
- :foreign_geom => {
592
- :wrapper => :centroid,
593
- :name => :the_other_geom
570
+ foreign_geom: {
571
+ wrapper: :centroid,
572
+ name: :the_other_geom
594
573
  }
595
574
  end
596
575
  end
@@ -602,7 +581,7 @@ class BothGeomWrapperWithMixedSRIDsTest < ActiveRecordSpatialTestCase
602
581
  values = Foo.first.bars.collect(&:id).sort
603
582
  end
604
583
 
605
- assert_equal([ 3 ], values)
584
+ assert_equal([3], values)
606
585
  end
607
586
 
608
587
  def test_with_eager_loading
@@ -612,7 +591,7 @@ class BothGeomWrapperWithMixedSRIDsTest < ActiveRecordSpatialTestCase
612
591
  values = Foo.includes(:bars).first.bars.collect(&:id).sort
613
592
  end
614
593
 
615
- assert_equal([ 3 ], values)
594
+ assert_equal([3], values)
616
595
  end
617
596
  end
618
597
 
@@ -622,15 +601,15 @@ class BothGeomWrapperAndOptionsWithMixedSRIDsTest < ActiveRecordSpatialTestCase
622
601
 
623
602
  Foo.class_eval do
624
603
  has_many_spatially :bars,
625
- :class_name => 'Bar',
626
- :geom => {
627
- :wrapper => :convexhull
604
+ class_name: 'Bar',
605
+ geom: {
606
+ wrapper: :convexhull
628
607
  },
629
- :foreign_geom => {
630
- :wrapper => {
631
- :buffer => 100
608
+ foreign_geom: {
609
+ wrapper: {
610
+ buffer: 100
632
611
  },
633
- :name => :the_other_geom
612
+ name: :the_other_geom
634
613
  }
635
614
  end
636
615
  end
@@ -642,7 +621,7 @@ class BothGeomWrapperAndOptionsWithMixedSRIDsTest < ActiveRecordSpatialTestCase
642
621
  values = Foo.first.bars.collect(&:id).sort
643
622
  end
644
623
 
645
- assert_equal([ 1, 2, 3 ], values)
624
+ assert_equal([1, 2, 3], values)
646
625
  end
647
626
 
648
627
  def test_with_eager_loading
@@ -652,7 +631,7 @@ class BothGeomWrapperAndOptionsWithMixedSRIDsTest < ActiveRecordSpatialTestCase
652
631
  values = Foo.includes(:bars).first.bars.collect(&:id).sort
653
632
  end
654
633
 
655
- assert_equal([ 1, 2, 3 ], values)
634
+ assert_equal([1, 2, 3], values)
656
635
  end
657
636
 
658
637
  class ScopeArgumentTest < ActiveRecordSpatialTestCase
@@ -663,7 +642,7 @@ class BothGeomWrapperAndOptionsWithMixedSRIDsTest < ActiveRecordSpatialTestCase
663
642
  def test_foo
664
643
  Foo.class_eval do
665
644
  has_many_spatially :bars, proc {
666
- self.order(:id)
645
+ order(:id)
667
646
  }
668
647
  end
669
648
 
@@ -671,6 +650,5 @@ class BothGeomWrapperAndOptionsWithMixedSRIDsTest < ActiveRecordSpatialTestCase
671
650
  Foo.first.bars.to_a
672
651
  end
673
652
  end
674
- end if ActiveRecord::VERSION::MAJOR >= 4
653
+ end
675
654
  end
676
-