activerecord-spatial 1.0.0 → 2.0.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.
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 GeographyColumnTests < ActiveRecordSpatialTestCase
@@ -22,7 +22,7 @@ class GeographyColumnTests < ActiveRecordSpatialTestCase
22
22
  end
23
23
 
24
24
  def test_coord_dimension_for
25
- assert_equal(2, FooGeography.coord_dimension_for(:the_geom))
25
+ assert_nil(FooGeography.coord_dimension_for(:the_geom))
26
26
  assert_equal(2, FooGeography.coord_dimension_for(:the_other_geom))
27
27
  end
28
28
 
@@ -37,4 +37,3 @@ class GeographyColumnTests < ActiveRecordSpatialTestCase
37
37
  assert_equal(4326, FooGeography.geography_column_by_name(:the_other_geom).spatial_ref_sys.srid)
38
38
  end
39
39
  end
40
-
@@ -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 GeometryColumnTests < ActiveRecordSpatialTestCase
@@ -37,4 +37,3 @@ class GeometryColumnTests < ActiveRecordSpatialTestCase
37
37
  assert_equal(4326, Foo.geometry_column_by_name(:the_other_geom).spatial_ref_sys.srid)
38
38
  end
39
39
  end
40
-
data/test/models/bar.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- if !ARBC.table_exists?('bars')
2
+ unless ActiveRecordSpatialTestCase.table_exists?('bars')
3
3
  ActiveRecord::Migration.create_table(:bars) do |t|
4
4
  t.text :name
5
5
  end
@@ -12,6 +12,5 @@ class Bar < ActiveRecord::Base
12
12
  include ActiveRecordSpatial::SpatialColumns
13
13
  include ActiveRecordSpatial::SpatialScopes
14
14
 
15
- self.create_spatial_column_accessors!
15
+ create_spatial_column_accessors!
16
16
  end
17
-
data/test/models/blort.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- if !ARBC.table_exists?('blorts')
2
+ unless ActiveRecordSpatialTestCase.table_exists?('blorts')
3
3
  ActiveRecord::Migration.create_table(:blorts) do |t|
4
4
  t.text :name
5
5
  t.integer :foo_id
@@ -9,4 +9,3 @@ end
9
9
  class Blort < ActiveRecord::Base
10
10
  belongs_to :foo
11
11
  end
12
-
data/test/models/foo.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- if !ARBC.table_exists?('foos')
2
+ unless ActiveRecordSpatialTestCase.table_exists?('foos')
3
3
  ActiveRecord::Migration.create_table(:foos) do |t|
4
4
  t.text :name
5
5
  end
@@ -12,6 +12,5 @@ class Foo < ActiveRecord::Base
12
12
  include ActiveRecordSpatial::SpatialColumns
13
13
  include ActiveRecordSpatial::SpatialScopes
14
14
 
15
- self.create_spatial_column_accessors!
15
+ create_spatial_column_accessors!
16
16
  end
17
-
data/test/models/foo3d.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- if !ARBC.table_exists?('foo3ds')
2
+ unless ActiveRecordSpatialTestCase.table_exists?('foo3ds')
3
3
  ActiveRecord::Migration.create_table(:foo3ds) do |t|
4
4
  t.text :name
5
5
  end
@@ -12,6 +12,5 @@ class Foo3d < ActiveRecord::Base
12
12
  include ActiveRecordSpatial::SpatialColumns
13
13
  include ActiveRecordSpatial::SpatialScopes
14
14
 
15
- self.create_spatial_column_accessors!
15
+ create_spatial_column_accessors!
16
16
  end
17
-
@@ -1,5 +1,5 @@
1
1
 
2
- if !ARBC.table_exists?('foo_geographies')
2
+ unless ActiveRecordSpatialTestCase.table_exists?('foo_geographies')
3
3
  ActiveRecord::Migration.create_table(:foo_geographies) do |t|
4
4
  t.text :name
5
5
  t.column :the_geom, :geography
@@ -11,6 +11,5 @@ class FooGeography < ActiveRecord::Base
11
11
  include ActiveRecordSpatial::SpatialColumns
12
12
  include ActiveRecordSpatial::SpatialScopes
13
13
 
14
- self.create_spatial_column_accessors!
14
+ create_spatial_column_accessors!
15
15
  end
16
-
@@ -1,5 +1,5 @@
1
1
 
2
- if !ARBC.table_exists?('zortables')
2
+ unless ActiveRecordSpatialTestCase.table_exists?('zortables')
3
3
  ActiveRecord::Migration.create_table(:zortables) do |t|
4
4
  t.text :name
5
5
  t.text :zortable_type
@@ -12,6 +12,5 @@ class Zortable < ActiveRecord::Base
12
12
  include ActiveRecordSpatial::SpatialColumns
13
13
  include ActiveRecordSpatial::SpatialScopes
14
14
 
15
- self.create_spatial_column_accessors!
15
+ create_spatial_column_accessors!
16
16
  end
17
-
@@ -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 SpatialFunctionTests < ActiveRecordSpatialTestCase
@@ -11,7 +11,7 @@ class SpatialFunctionTests < ActiveRecordSpatialTestCase
11
11
  def test_geom_arg_option
12
12
  assert_equal(
13
13
  %{ST_distance("foos"."the_geom", '010100000000000000000000000000000000000000'::geometry)},
14
- Foo.spatial_function(:distance, :geom_arg => 'POINT(0 0)').to_sql
14
+ Foo.spatial_function(:distance, geom_arg: 'POINT(0 0)').to_sql
15
15
  )
16
16
  end
17
17
 
@@ -25,7 +25,7 @@ class SpatialFunctionTests < ActiveRecordSpatialTestCase
25
25
  def test_column_option
26
26
  assert_equal(
27
27
  %{ST_distance("foos"."the_other_geom", ST_SetSRID('010100000000000000000000000000000000000000'::geometry, 4326))},
28
- Foo.spatial_function(:distance, 'POINT(0 0)', :column => 'the_other_geom').to_sql
28
+ Foo.spatial_function(:distance, 'POINT(0 0)', column: 'the_other_geom').to_sql
29
29
  )
30
30
  end
31
31
 
@@ -33,11 +33,9 @@ class SpatialFunctionTests < ActiveRecordSpatialTestCase
33
33
  assert_equal(
34
34
  %{ST_distance("foos"."the_other_geom", ST_SetSRID('010100000000000000000000000000000000000000'::geometry, 4326))},
35
35
  Foo.spatial_function(:distance, {
36
- :class => Blort,
37
- :value => 'POINT(0 0)'
38
- }, {
39
- :column => 'the_other_geom'
40
- }).to_sql
36
+ class: Blort,
37
+ value: 'POINT(0 0)'
38
+ }, column: 'the_other_geom').to_sql
41
39
  )
42
40
  end
43
41
 
@@ -45,33 +43,30 @@ class SpatialFunctionTests < ActiveRecordSpatialTestCase
45
43
  assert_equal(
46
44
  %{ST_distance("foos"."the_other_geom", ST_SetSRID('010100000000000000000000000000000000000000'::geometry, 4326))},
47
45
  Foo.spatial_function(:distance, {
48
- :class => 'Blort',
49
- :value => 'POINT(0 0)'
50
- }, {
51
- :column => 'the_other_geom'
52
- }).to_sql
46
+ class: 'Blort',
47
+ value: 'POINT(0 0)'
48
+ }, column: 'the_other_geom').to_sql
53
49
  )
54
50
  end
55
51
 
56
52
  def test_invert_option
57
53
  assert_equal(
58
54
  %{ST_distance('010100000000000000000000000000000000000000'::geometry, "foos"."the_geom")},
59
- Foo.spatial_function(:distance, 'POINT(0 0)', :invert => true).to_sql
55
+ Foo.spatial_function(:distance, 'POINT(0 0)', invert: true).to_sql
60
56
  )
61
57
  end
62
58
 
63
59
  def test_use_index_option
64
60
  assert_equal(
65
61
  %{_ST_distance("foos"."the_geom", '010100000000000000000000000000000000000000'::geometry)},
66
- Foo.spatial_function(:distance, 'POINT(0 0)', :use_index => false).to_sql
62
+ Foo.spatial_function(:distance, 'POINT(0 0)', use_index: false).to_sql
67
63
  )
68
64
  end
69
65
 
70
66
  def test_allow_null_option
71
67
  assert_equal(
72
68
  %{(ST_distance("foos"."the_geom", '010100000000000000000000000000000000000000'::geometry) OR "foos"."the_geom" IS NULL)},
73
- Foo.spatial_function(:distance, 'POINT(0 0)', :allow_null => true).to_sql
69
+ Foo.spatial_function(:distance, 'POINT(0 0)', allow_null: true).to_sql
74
70
  )
75
71
  end
76
72
  end
77
-
@@ -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 SpatialScopesGeographiesTests < ActiveRecordSpatialTestCase
@@ -13,36 +13,34 @@ class SpatialScopesGeographiesTests < ActiveRecordSpatialTestCase
13
13
  end
14
14
 
15
15
  def test_covers
16
- ids_tester(:st_covers, 'POINT(0 0)', [ 3 ], :conditions => {
17
- :id => [ 3 ]
16
+ ids_tester(:st_covers, 'POINT(0 0)', [3], conditions: {
17
+ id: [3]
18
18
  })
19
19
  end
20
20
 
21
21
  def test_coveredby
22
- ids_tester(:st_coveredby, 'POLYGON((-6 -6, -6 6, 6 6, 6 -6, -6 -6))', [ 1 ], :conditions => {
23
- :id => [ 1, 2 ]
22
+ ids_tester(:st_coveredby, 'POLYGON((-6 -6, -6 6, 6 6, 6 -6, -6 -6))', [1], conditions: {
23
+ id: [1, 2]
24
24
  })
25
25
  end
26
26
 
27
27
  def test_intersects
28
- ids_tester(:st_intersects, 'LINESTRING(-5 -5, 10 10)', [ 2, 3 ])
28
+ ids_tester(:st_intersects, 'LINESTRING(-5 -5, 10 10)', [2, 3])
29
29
  end
30
30
 
31
31
  def test_dwithin
32
- ids_tester(:st_dwithin, [ 'POINT(5 5)', 10 ], [ 3 ])
32
+ ids_tester(:st_dwithin, ['POINT(5 5)', 10], [3])
33
33
  end
34
34
 
35
35
  def test_allow_null
36
- begin
37
- foo = FooGeography.create(:name => 'four')
38
- ids_tester(:st_covers, [ 'POINT(3 3)', { :allow_null => true } ], [ 3, foo.id ])
39
- ensure
40
- FooGeography.find_by_name('four').destroy
41
- end
36
+ foo = FooGeography.create(name: 'four')
37
+ ids_tester(:st_covers, ['POINT(3 3)', { allow_null: true }], [3, foo.id])
38
+ ensure
39
+ FooGeography.find_by_name('four').destroy
42
40
  end
43
41
 
44
42
  def test_with_column
45
- assert_equal([3], FooGeography.st_covers('POINT(7 7)', :column => :the_other_geom).to_a.collect(&:id).sort)
43
+ assert_equal([3], FooGeography.st_covers('POINT(7 7)', column: :the_other_geom).to_a.collect(&:id).sort)
46
44
  end
47
45
 
48
46
  def test_with_srid_switching
@@ -54,7 +52,7 @@ class SpatialScopesGeographiesTests < ActiveRecordSpatialTestCase
54
52
  end
55
53
 
56
54
  def test_with_srid_transform
57
- assert_equal([3], FooGeography.st_covers('SRID=4269; POINT(7 7)', :column => :the_other_geom).to_a.collect(&:id).sort)
55
+ assert_equal([3], FooGeography.st_covers('SRID=4269; POINT(7 7)', column: :the_other_geom).to_a.collect(&:id).sort)
58
56
  end
59
57
 
60
58
  def test_order_by_st_distance
@@ -62,7 +60,7 @@ class SpatialScopesGeographiesTests < ActiveRecordSpatialTestCase
62
60
  end
63
61
 
64
62
  def test_order_by_st_distance_desc
65
- assert_equal([2, 1, 3], FooGeography.order_by_st_distance('POINT(1 1)', :desc => true).to_a.collect(&:id))
63
+ assert_equal([2, 1, 3], FooGeography.order_by_st_distance('POINT(1 1)', desc: true).to_a.collect(&:id))
66
64
  end
67
65
 
68
66
  def test_order_by_st_area
@@ -70,7 +68,7 @@ class SpatialScopesGeographiesTests < ActiveRecordSpatialTestCase
70
68
  end
71
69
 
72
70
  def test_order_by_st_area_desc
73
- assert_equal([3, 1, 2], FooGeography.order_by_st_area(:desc => true).to_a.collect(&:id))
71
+ assert_equal([3, 1, 2], FooGeography.order_by_st_area(desc: true).to_a.collect(&:id))
74
72
  end
75
73
 
76
74
  def test_order_by_st_length
@@ -84,7 +82,7 @@ class SpatialScopesGeographiesTests < ActiveRecordSpatialTestCase
84
82
  [3, 1, 2]
85
83
  end
86
84
 
87
- assert_equal(expected, FooGeography.order_by_st_length(:desc => true).where('true = true').to_a.collect(&:id))
85
+ assert_equal(expected, FooGeography.order_by_st_length(desc: true).where('true = true').to_a.collect(&:id))
88
86
  end
89
87
 
90
88
  def test_order_by_st_perimeter
@@ -96,11 +94,10 @@ class SpatialScopesGeographiesTests < ActiveRecordSpatialTestCase
96
94
  def test_order_by_st_perimeter_desc
97
95
  skip('requires PostGIS 2+') unless FooGeography.respond_to?(:order_by_st_perimeter)
98
96
 
99
- assert_equal([3, 1, 2], FooGeography.order_by_st_perimeter(:desc => true).to_a.collect(&:id))
97
+ assert_equal([3, 1, 2], FooGeography.order_by_st_perimeter(desc: true).to_a.collect(&:id))
100
98
  end
101
99
 
102
100
  def test_order_by_st_area_with_desc_symbol
103
101
  assert_equal([3, 1, 2], FooGeography.order_by_st_area(:desc).to_a.collect(&:id))
104
102
  end
105
103
  end
106
-