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,8 +1,6 @@
1
1
 
2
2
  require 'geos-extensions'
3
3
 
4
- require 'activerecord-spatial/active_record/connection_adapters/postgresql/adapter_extensions'
5
-
6
4
  module ActiveRecordSpatial
7
5
  BASE_PATH = File.dirname(__FILE__)
8
6
 
@@ -22,11 +20,9 @@ module ActiveRecordSpatial
22
20
  # Allows you to modify the default geometry column name for all of
23
21
  # ActiveRecordSpatial. This is useful when you have a common column name
24
22
  # for all of your geometry columns, such as +wkb+, +feature+, +geom+, etc.
25
- def default_column_name=(column_name)
26
- @default_column_name = column_name
27
- end
23
+ attr_writer :default_column_name
28
24
  end
29
25
  end
30
26
 
27
+ require 'activerecord-spatial/active_record/connection_adapters/postgresql/adapter_extensions'
31
28
  require 'activerecord-spatial/active_record'
32
-
data/lib/tasks/test.rake CHANGED
@@ -1,14 +1,17 @@
1
1
 
2
2
  namespace :test do
3
- desc "Dumps data from the geometry_columns and spatial_ref_sys tables."
4
- task :postgis_dump => :environment do
3
+ desc 'Dumps data from the geometry_columns and spatial_ref_sys tables.'
4
+ task postgis_dump: :environment do
5
5
  abcs = ActiveRecord::Base.configurations
6
- ENV['PGHOST'] = abcs[Rails.env]["host"] if abcs[Rails.env]["host"]
7
- ENV['PGPORT'] = abcs[Rails.env]["port"].to_s if abcs[Rails.env]["port"]
8
- ENV['PGPASSWORD'] = abcs[Rails.env]["password"].to_s if abcs[Rails.env]["password"]
9
- search_path = abcs[Rails.env]["schema_search_path"]
6
+ ENV['PGHOST'] = abcs[Rails.env]['host'] if abcs[Rails.env]['host']
7
+ ENV['PGPORT'] = abcs[Rails.env]['port'].to_s if abcs[Rails.env]['port']
8
+ ENV['PGPASSWORD'] = abcs[Rails.env]['password'].to_s if abcs[Rails.env]['password']
9
+ search_path = abcs[Rails.env]['schema_search_path']
10
+
10
11
  unless search_path.blank?
11
- search_path = search_path.split(",").map{|search_path| "--schema=#{search_path.strip}" }.join(" ")
12
+ search_path = search_path.split(',').map { |schema|
13
+ "--schema=#{schema.strip}"
14
+ }.join(' ')
12
15
  end
13
16
 
14
17
  tables = %w{ geometry_columns spatial_ref_sys }.select do |table|
@@ -18,28 +21,27 @@ namespace :test do
18
21
 
19
22
  pp tables
20
23
 
21
- unless tables.empty?
22
- `pg_dump -i -U "#{abcs[Rails.env]["username"]}" --data-only -t #{tables.join(' -t ')} -x -O -f db/#{Rails.env}_postgis_tables.sql #{search_path} #{abcs[Rails.env]["database"]}`
24
+ if !tables.empty?
25
+ `pg_dump -i -U "#{abcs[Rails.env]['username']}" --data-only -t #{tables.join(' -t ')} -x -O -f db/#{Rails.env}_postgis_tables.sql #{search_path} #{abcs[Rails.env]['database']}`
23
26
  else
24
27
  File.open("db/#{Rails.env}_postgis_tables.sql", 'w') do |fp|
25
- fp.puts "-- empty, do geometry_columns and spatial_ref_sys tables exist?"
28
+ fp.puts '-- empty, do geometry_columns and spatial_ref_sys tables exist?'
26
29
  end
27
30
  end
28
31
  end
29
32
 
30
- desc "Loads the geometry_columns and spatial_ref_sys tables."
31
- task :postgis_load => :environment do
33
+ desc 'Loads the geometry_columns and spatial_ref_sys tables.'
34
+ task postgis_load: :environment do
32
35
  abcs = ActiveRecord::Base.configurations
33
- ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
34
- ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
35
- ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
36
+ ENV['PGHOST'] = abcs['test']['host'] if abcs['test']['host']
37
+ ENV['PGPORT'] = abcs['test']['port'].to_s if abcs['test']['port']
38
+ ENV['PGPASSWORD'] = abcs['test']['password'].to_s if abcs['test']['password']
36
39
 
37
- `psql -U "#{abcs["test"]["username"]}" -f #{Rails.root}/db/#{Rails.env}_postgis_tables.sql #{abcs["test"]["database"]}`
40
+ `psql -U "#{abcs['test']['username']}" -f #{Rails.root}/db/#{Rails.env}_postgis_tables.sql #{abcs['test']['database']}`
38
41
  end
39
42
 
40
- desc "Dumps and loads the geometry_columns and spatial_ref_sys tables."
41
- task :postgis_clone => [ :postgis_dump, :postgis_load ]
43
+ desc 'Dumps and loads the geometry_columns and spatial_ref_sys tables.'
44
+ task postgis_clone: [:postgis_dump, :postgis_load]
42
45
  end
43
46
 
44
47
  Rake::Task['test:prepare'].enhance(['test:postgis_clone'])
45
-
data/test/.rubocop.yml ADDED
@@ -0,0 +1,35 @@
1
+
2
+ inherit_from:
3
+ - ../.rubocop.yml
4
+
5
+ Metrics/BlockLength:
6
+ Description: 'Avoid long blocks with many lines.'
7
+ Enabled: false
8
+
9
+ Metrics/ClassLength:
10
+ Description: 'Avoid classes longer than 300 lines of code.'
11
+ Enabled: false
12
+ Max: 300
13
+
14
+ Lint/EmptyInterpolation:
15
+ Description: 'Checks for empty string interpolation.'
16
+ Enabled: false
17
+
18
+ Style/StringLiterals:
19
+ Description: 'Checks if uses of quotes match the configured preference.'
20
+ StyleGuide: '#consistent-string-literals'
21
+ Enabled: false
22
+
23
+ Style/BlockComments:
24
+ Description: 'Do not use block comments.'
25
+ StyleGuide: '#no-block-comments'
26
+ Enabled: false
27
+
28
+ Style/BlockDelimiters:
29
+ Description: >-
30
+ Avoid using {...} for multi-line blocks (multiline chaining is
31
+ always ugly).
32
+ Prefer {...} over do...end for single-line blocks.
33
+ StyleGuide: '#single-line-blocks'
34
+ Enabled: false
35
+ EnforcedStyle: braces_for_chaining
@@ -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 AccessorsGeographiesTests < ActiveRecordSpatialTestCase
@@ -62,8 +62,8 @@ class AccessorsGeographiesTests < ActiveRecordSpatialTestCase
62
62
 
63
63
  def test_geos_create
64
64
  foo = FooGeography.create!(
65
- :name => 'test_geos_create',
66
- :the_geom => Geos.read(POINT_WKT)
65
+ name: 'test_geos_create',
66
+ the_geom: Geos.read(POINT_WKT)
67
67
  )
68
68
 
69
69
  foo.reload
@@ -72,8 +72,8 @@ class AccessorsGeographiesTests < ActiveRecordSpatialTestCase
72
72
 
73
73
  def test_wkt_create
74
74
  foo = FooGeography.create!(
75
- :name => 'test_wkt_create',
76
- :the_geom => POINT_WKT
75
+ name: 'test_wkt_create',
76
+ the_geom: POINT_WKT
77
77
  )
78
78
 
79
79
  foo.reload
@@ -82,8 +82,8 @@ class AccessorsGeographiesTests < ActiveRecordSpatialTestCase
82
82
 
83
83
  def test_wkb_create
84
84
  foo = FooGeography.create!(
85
- :name => 'test_wkb_create',
86
- :the_geom => POINT_WKB
85
+ name: 'test_wkb_create',
86
+ the_geom: POINT_WKB
87
87
  )
88
88
 
89
89
  foo.reload
@@ -92,8 +92,8 @@ class AccessorsGeographiesTests < ActiveRecordSpatialTestCase
92
92
 
93
93
  def test_ewkt_create_with_srid_4326
94
94
  foo = FooGeography.create!(
95
- :name => 'test_ewkt_create_with_srid_4326',
96
- :the_other_geom => POINT_EWKT
95
+ name: 'test_ewkt_create_with_srid_4326',
96
+ the_other_geom: POINT_EWKT
97
97
  )
98
98
 
99
99
  foo.reload
@@ -102,8 +102,8 @@ class AccessorsGeographiesTests < ActiveRecordSpatialTestCase
102
102
 
103
103
  def test_create_with_no_srid_converting_to_4326
104
104
  foo = FooGeography.create!(
105
- :name => 'test_ewkt_create_with_no_srid_converting_to_4326',
106
- :the_other_geom => POINT_WKT
105
+ name: 'test_ewkt_create_with_no_srid_converting_to_4326',
106
+ the_other_geom: POINT_WKT
107
107
  )
108
108
 
109
109
  foo.reload
@@ -112,8 +112,8 @@ class AccessorsGeographiesTests < ActiveRecordSpatialTestCase
112
112
 
113
113
  def test_create_with_no_srid_converting_to_minus_1
114
114
  foo = FooGeography.create!(
115
- :name => 'test_ewkt_create_with_no_srid_converting_to_minus_1',
116
- :the_geom => POINT_EWKT
115
+ name: 'test_ewkt_create_with_no_srid_converting_to_minus_1',
116
+ the_geom: POINT_EWKT
117
117
  )
118
118
 
119
119
  foo.reload
@@ -122,15 +122,15 @@ class AccessorsGeographiesTests < ActiveRecordSpatialTestCase
122
122
 
123
123
  def test_create_with_converting_from_900913_to_4326
124
124
  FooGeography.create!(
125
- :name => 'test_create_with_converting_from_900913_to_4326',
126
- :the_other_geom => "SRID=900913; #{POINT_WKT}"
125
+ name: 'test_create_with_converting_from_900913_to_4326',
126
+ the_other_geom: "SRID=900913; #{POINT_WKT}"
127
127
  )
128
128
  end
129
129
 
130
130
  def test_ewkt_create_with_srid_default
131
131
  foo = FooGeography.create!(
132
- :name => 'test_ewkt_create_with_srid_default',
133
- :the_other_geom => POINT_EWKT_WITH_DEFAULT
132
+ name: 'test_ewkt_create_with_srid_default',
133
+ the_other_geom: POINT_EWKT_WITH_DEFAULT
134
134
  )
135
135
 
136
136
  foo.reload
@@ -139,8 +139,8 @@ class AccessorsGeographiesTests < ActiveRecordSpatialTestCase
139
139
 
140
140
  def test_ewkb_create
141
141
  foo = FooGeography.create!(
142
- :name => 'test_ewkb_create',
143
- :the_other_geom => POINT_EWKB
142
+ name: 'test_ewkb_create',
143
+ the_other_geom: POINT_EWKB
144
144
  )
145
145
 
146
146
  foo.reload
@@ -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 AccessorsGeometriesTests < ActiveRecordSpatialTestCase
@@ -62,8 +62,8 @@ class AccessorsGeometriesTests < ActiveRecordSpatialTestCase
62
62
 
63
63
  def test_geos_create
64
64
  foo = Foo.create!(
65
- :name => 'test_geos_create',
66
- :the_geom => Geos.read(POINT_WKT)
65
+ name: 'test_geos_create',
66
+ the_geom: Geos.read(POINT_WKT)
67
67
  )
68
68
 
69
69
  foo.reload
@@ -72,8 +72,8 @@ class AccessorsGeometriesTests < ActiveRecordSpatialTestCase
72
72
 
73
73
  def test_wkt_create
74
74
  foo = Foo.create!(
75
- :name => 'test_wkt_create',
76
- :the_geom => POINT_WKT
75
+ name: 'test_wkt_create',
76
+ the_geom: POINT_WKT
77
77
  )
78
78
 
79
79
  foo.reload
@@ -82,8 +82,8 @@ class AccessorsGeometriesTests < ActiveRecordSpatialTestCase
82
82
 
83
83
  def test_wkb_create
84
84
  foo = Foo.create!(
85
- :name => 'test_wkb_create',
86
- :the_geom => POINT_WKB
85
+ name: 'test_wkb_create',
86
+ the_geom: POINT_WKB
87
87
  )
88
88
 
89
89
  foo.reload
@@ -92,8 +92,8 @@ class AccessorsGeometriesTests < ActiveRecordSpatialTestCase
92
92
 
93
93
  def test_ewkt_create_with_srid_4326
94
94
  foo = Foo.create!(
95
- :name => 'test_ewkt_create_with_srid_4326',
96
- :the_other_geom => POINT_EWKT
95
+ name: 'test_ewkt_create_with_srid_4326',
96
+ the_other_geom: POINT_EWKT
97
97
  )
98
98
 
99
99
  foo.reload
@@ -102,8 +102,8 @@ class AccessorsGeometriesTests < ActiveRecordSpatialTestCase
102
102
 
103
103
  def test_create_with_no_srid_converting_to_4326
104
104
  foo = Foo.create!(
105
- :name => 'test_ewkt_create_with_no_srid_converting_to_4326',
106
- :the_other_geom => POINT_WKT
105
+ name: 'test_ewkt_create_with_no_srid_converting_to_4326',
106
+ the_other_geom: POINT_WKT
107
107
  )
108
108
 
109
109
  foo.reload
@@ -112,8 +112,8 @@ class AccessorsGeometriesTests < ActiveRecordSpatialTestCase
112
112
 
113
113
  def test_create_with_no_srid_converting_to_minus_1
114
114
  foo = Foo.create!(
115
- :name => 'test_ewkt_create_with_no_srid_converting_to_minus_1',
116
- :the_geom => POINT_EWKT
115
+ name: 'test_ewkt_create_with_no_srid_converting_to_minus_1',
116
+ the_geom: POINT_EWKT
117
117
  )
118
118
 
119
119
  foo.reload
@@ -123,16 +123,16 @@ class AccessorsGeometriesTests < ActiveRecordSpatialTestCase
123
123
  def test_create_with_converting_from_900913_to_4326
124
124
  assert_raise(ActiveRecordSpatial::GeometryColumns::CantConvertSRID) do
125
125
  Foo.create!(
126
- :name => 'test_create_with_converting_from_900913_to_4326',
127
- :the_other_geom => "SRID=900913; #{POINT_WKT}"
126
+ name: 'test_create_with_converting_from_900913_to_4326',
127
+ the_other_geom: "SRID=900913; #{POINT_WKT}"
128
128
  )
129
129
  end
130
130
  end
131
131
 
132
132
  def test_ewkt_create_with_srid_default
133
133
  foo = Foo.create!(
134
- :name => 'test_ewkt_create_with_srid_default',
135
- :the_other_geom => POINT_EWKT_WITH_DEFAULT
134
+ name: 'test_ewkt_create_with_srid_default',
135
+ the_other_geom: POINT_EWKT_WITH_DEFAULT
136
136
  )
137
137
 
138
138
  foo.reload
@@ -141,8 +141,8 @@ class AccessorsGeometriesTests < ActiveRecordSpatialTestCase
141
141
 
142
142
  def test_ewkb_create
143
143
  foo = Foo.create!(
144
- :name => 'test_ewkb_create',
145
- :the_other_geom => POINT_EWKB
144
+ name: 'test_ewkb_create',
145
+ the_other_geom: POINT_EWKB
146
146
  )
147
147
 
148
148
  foo.reload
@@ -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 AdapterTests < ActiveRecordSpatialTestCase
@@ -41,4 +41,3 @@ if ActiveRecordSpatial.geography_columns?
41
41
  end
42
42
  end
43
43
  end
44
-