geokit-rails3-1beta 0.2.0.beta1 → 0.3.1.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/CONFIG.markdown +67 -0
  2. data/Gemfile +3 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.markdown +653 -0
  5. data/Rakefile +17 -0
  6. data/geokit-rails3-1beta.gemspec +31 -0
  7. data/lib/geokit-rails3-1beta.rb +10 -0
  8. data/lib/{geokit-rails3 → geokit-rails3-1beta}/acts_as_mappable.old.rb +0 -0
  9. data/lib/{geokit-rails3 → geokit-rails3-1beta}/acts_as_mappable.rb +0 -0
  10. data/lib/{geokit-rails3 → geokit-rails3-1beta}/adapters/abstract.rb +0 -0
  11. data/lib/{geokit-rails3 → geokit-rails3-1beta}/adapters/mysql.rb +0 -0
  12. data/lib/{geokit-rails3 → geokit-rails3-1beta}/adapters/mysql2.rb +0 -0
  13. data/lib/{geokit-rails3 → geokit-rails3-1beta}/adapters/postgresql.rb +0 -0
  14. data/lib/{geokit-rails3 → geokit-rails3-1beta}/adapters/sqlserver.rb +0 -0
  15. data/lib/{geokit-rails3 → geokit-rails3-1beta}/core_extensions.rb +0 -0
  16. data/lib/{geokit-rails3 → geokit-rails3-1beta}/defaults.rb +0 -0
  17. data/lib/{geokit-rails3 → geokit-rails3-1beta}/geocoder_control.rb +0 -0
  18. data/lib/{geokit-rails3 → geokit-rails3-1beta}/ip_geocode_lookup.rb +0 -0
  19. data/lib/{geokit-rails3 → geokit-rails3-1beta}/railtie.rb +3 -3
  20. data/lib/geokit-rails3-1beta/version.rb +3 -0
  21. metadata +26 -69
  22. data/lib/geokit-rails3.rb +0 -10
  23. data/lib/geokit-rails3/version.rb +0 -3
  24. data/test/acts_as_mappable_test.rb +0 -420
  25. data/test/boot.rb +0 -32
  26. data/test/database.yml +0 -20
  27. data/test/fixtures/companies.yml +0 -7
  28. data/test/fixtures/custom_locations.yml +0 -54
  29. data/test/fixtures/locations.yml +0 -54
  30. data/test/fixtures/mock_addresses.yml +0 -17
  31. data/test/fixtures/mock_families.yml +0 -2
  32. data/test/fixtures/mock_houses.yml +0 -9
  33. data/test/fixtures/mock_organizations.yml +0 -5
  34. data/test/fixtures/mock_people.yml +0 -5
  35. data/test/fixtures/stores.yml +0 -0
  36. data/test/ip_geocode_lookup_test.disabled.rb +0 -82
  37. data/test/models/company.rb +0 -3
  38. data/test/models/custom_location.rb +0 -12
  39. data/test/models/location.rb +0 -4
  40. data/test/models/mock_address.rb +0 -4
  41. data/test/models/mock_family.rb +0 -3
  42. data/test/models/mock_house.rb +0 -3
  43. data/test/models/mock_organization.rb +0 -4
  44. data/test/models/mock_person.rb +0 -4
  45. data/test/models/store.rb +0 -3
  46. data/test/schema.rb +0 -60
  47. data/test/tasks.rake +0 -38
  48. data/test/test_helper.rb +0 -23
@@ -0,0 +1,17 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/rdoctask'
5
+ Rake::RDocTask.new do |rdoc|
6
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
7
+
8
+ rdoc.rdoc_dir = 'rdoc'
9
+ rdoc.title = "geokit-rails3-1beta #{version}"
10
+ rdoc.rdoc_files.include('README*')
11
+ rdoc.rdoc_files.include('lib/**/*.rb')
12
+ end
13
+
14
+ load 'test/tasks.rake'
15
+
16
+ desc 'Default: run unit tests.'
17
+ task :default => :test
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/geokit-rails3-1beta/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "geokit-rails3-1beta"
6
+ s.version = GeokitRails31Beta::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Bruno S. Barros"]
9
+ s.email = ["bkether@gmail.com"]
10
+ s.homepage = "http://github.com/bkether/geokit-rails3-1beta"
11
+ s.summary = "Integrate Geokit with Rails 3.1.beta1"
12
+ s.description = "Port of the Rails plugin \"geokit-rails\" to Rails 3.1.beta1, as a gem"
13
+
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+ # s.rubyforge_project = "test_gem"
16
+
17
+ s.add_runtime_dependency 'rails', '~> 3.1.0.beta1'
18
+ s.add_runtime_dependency 'geokit', '~> 1.5.0'
19
+
20
+ s.add_development_dependency "bundler", "~> 1.0.0"
21
+ s.add_development_dependency "rcov", "~> 0.9.9"
22
+ s.add_development_dependency "mocha", "~> 0.9.8"
23
+ s.add_development_dependency "mysql", "~> 2.8.1"
24
+ s.add_development_dependency "mysql2", "~> 0.2.6"
25
+ s.add_development_dependency "pg", "~> 0.10.0"
26
+
27
+ s.files = `git ls-files`.split("\n")
28
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
29
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
30
+ s.require_paths = ["lib"]
31
+ end
@@ -0,0 +1,10 @@
1
+ require 'geokit'
2
+
3
+ require 'geokit-rails3-1beta/railtie'
4
+ require 'geokit-rails3-1beta/core_extensions'
5
+
6
+ require 'geokit-rails3-1beta/defaults'
7
+ require 'geokit-rails3-1beta/adapters/abstract'
8
+ require 'geokit-rails3-1beta/acts_as_mappable'
9
+ require 'geokit-rails3-1beta/geocoder_control'
10
+ require 'geokit-rails3-1beta/ip_geocode_lookup'
@@ -1,4 +1,4 @@
1
- require 'geokit-rails3'
1
+ require 'geokit-rails3-1beta'
2
2
  require 'rails'
3
3
 
4
4
  module Geokit
@@ -8,14 +8,14 @@ module Geokit
8
8
  config.geokit = ActiveSupport::OrderedOptions.new
9
9
  config.geokit.geocoders = ActiveSupport::OrderedOptions.new
10
10
 
11
- initializer 'geokit-rails3.insert_into_active_record' do
11
+ initializer 'geokit-rails3-1beta.insert_into_active_record' do
12
12
  ActiveSupport.on_load :active_record do
13
13
  ActiveRecord::Base.send(:include, Geokit::ActsAsMappable::Glue)
14
14
  Geokit::Geocoders.logger = ActiveRecord::Base.logger
15
15
  end
16
16
  end
17
17
 
18
- initializer 'geokit-rails3.insert_into_action_controller' do
18
+ initializer 'geokit-rails3-1beta.insert_into_action_controller' do
19
19
  ActiveSupport.on_load :action_controller do
20
20
  ActionController::Base.send(:include, Geokit::GeocoderControl)
21
21
  ActionController::Base.send(:include, GeoKit::IpGeocodeLookup)
@@ -0,0 +1,3 @@
1
+ module GeokitRails31Beta
2
+ VERSION = "0.3.1.beta1"
3
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: geokit-rails3-1beta
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 0.2.0.beta1
5
+ version: 0.3.1.beta1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Bruno S. Barros
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-13 00:00:00 -03:00
13
+ date: 2011-05-16 00:00:00 -03:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -101,7 +101,7 @@ dependencies:
101
101
  version: 0.10.0
102
102
  type: :development
103
103
  version_requirements: *id008
104
- description: Port of the Rails plugin "geokit-rails" to Rails 3.1, as a gem
104
+ description: Port of the Rails plugin "geokit-rails" to Rails 3.1.beta1, as a gem
105
105
  email:
106
106
  - bkether@gmail.com
107
107
  executables: []
@@ -111,45 +111,26 @@ extensions: []
111
111
  extra_rdoc_files: []
112
112
 
113
113
  files:
114
- - lib/geokit-rails3/acts_as_mappable.old.rb
115
- - lib/geokit-rails3/acts_as_mappable.rb
116
- - lib/geokit-rails3/adapters/abstract.rb
117
- - lib/geokit-rails3/adapters/mysql.rb
118
- - lib/geokit-rails3/adapters/mysql2.rb
119
- - lib/geokit-rails3/adapters/postgresql.rb
120
- - lib/geokit-rails3/adapters/sqlserver.rb
121
- - lib/geokit-rails3/core_extensions.rb
122
- - lib/geokit-rails3/defaults.rb
123
- - lib/geokit-rails3/geocoder_control.rb
124
- - lib/geokit-rails3/ip_geocode_lookup.rb
125
- - lib/geokit-rails3/railtie.rb
126
- - lib/geokit-rails3/version.rb
127
- - lib/geokit-rails3.rb
128
- - test/acts_as_mappable_test.rb
129
- - test/boot.rb
130
- - test/database.yml
131
- - test/fixtures/companies.yml
132
- - test/fixtures/custom_locations.yml
133
- - test/fixtures/locations.yml
134
- - test/fixtures/mock_addresses.yml
135
- - test/fixtures/mock_families.yml
136
- - test/fixtures/mock_houses.yml
137
- - test/fixtures/mock_organizations.yml
138
- - test/fixtures/mock_people.yml
139
- - test/fixtures/stores.yml
140
- - test/ip_geocode_lookup_test.disabled.rb
141
- - test/models/company.rb
142
- - test/models/custom_location.rb
143
- - test/models/location.rb
144
- - test/models/mock_address.rb
145
- - test/models/mock_family.rb
146
- - test/models/mock_house.rb
147
- - test/models/mock_organization.rb
148
- - test/models/mock_person.rb
149
- - test/models/store.rb
150
- - test/schema.rb
151
- - test/tasks.rake
152
- - test/test_helper.rb
114
+ - CONFIG.markdown
115
+ - Gemfile
116
+ - MIT-LICENSE
117
+ - README.markdown
118
+ - Rakefile
119
+ - geokit-rails3-1beta.gemspec
120
+ - lib/geokit-rails3-1beta.rb
121
+ - lib/geokit-rails3-1beta/acts_as_mappable.old.rb
122
+ - lib/geokit-rails3-1beta/acts_as_mappable.rb
123
+ - lib/geokit-rails3-1beta/adapters/abstract.rb
124
+ - lib/geokit-rails3-1beta/adapters/mysql.rb
125
+ - lib/geokit-rails3-1beta/adapters/mysql2.rb
126
+ - lib/geokit-rails3-1beta/adapters/postgresql.rb
127
+ - lib/geokit-rails3-1beta/adapters/sqlserver.rb
128
+ - lib/geokit-rails3-1beta/core_extensions.rb
129
+ - lib/geokit-rails3-1beta/defaults.rb
130
+ - lib/geokit-rails3-1beta/geocoder_control.rb
131
+ - lib/geokit-rails3-1beta/ip_geocode_lookup.rb
132
+ - lib/geokit-rails3-1beta/railtie.rb
133
+ - lib/geokit-rails3-1beta/version.rb
153
134
  has_rdoc: true
154
135
  homepage: http://github.com/bkether/geokit-rails3-1beta
155
136
  licenses: []
@@ -177,30 +158,6 @@ rubyforge_project:
177
158
  rubygems_version: 1.5.0
178
159
  signing_key:
179
160
  specification_version: 3
180
- summary: Integrate Geokit with Rails 3.1
181
- test_files:
182
- - test/acts_as_mappable_test.rb
183
- - test/boot.rb
184
- - test/database.yml
185
- - test/fixtures/companies.yml
186
- - test/fixtures/custom_locations.yml
187
- - test/fixtures/locations.yml
188
- - test/fixtures/mock_addresses.yml
189
- - test/fixtures/mock_families.yml
190
- - test/fixtures/mock_houses.yml
191
- - test/fixtures/mock_organizations.yml
192
- - test/fixtures/mock_people.yml
193
- - test/fixtures/stores.yml
194
- - test/ip_geocode_lookup_test.disabled.rb
195
- - test/models/company.rb
196
- - test/models/custom_location.rb
197
- - test/models/location.rb
198
- - test/models/mock_address.rb
199
- - test/models/mock_family.rb
200
- - test/models/mock_house.rb
201
- - test/models/mock_organization.rb
202
- - test/models/mock_person.rb
203
- - test/models/store.rb
204
- - test/schema.rb
205
- - test/tasks.rake
206
- - test/test_helper.rb
161
+ summary: Integrate Geokit with Rails 3.1.beta1
162
+ test_files: []
163
+
@@ -1,10 +0,0 @@
1
- require 'geokit'
2
-
3
- require 'geokit-rails3/railtie'
4
- require 'geokit-rails3/core_extensions'
5
-
6
- require 'geokit-rails3/defaults'
7
- require 'geokit-rails3/adapters/abstract'
8
- require 'geokit-rails3/acts_as_mappable'
9
- require 'geokit-rails3/geocoder_control'
10
- require 'geokit-rails3/ip_geocode_lookup'
@@ -1,3 +0,0 @@
1
- module GeokitRails3
2
- VERSION = "0.2.0.beta1"
3
- end
@@ -1,420 +0,0 @@
1
- require 'test_helper'
2
-
3
- Geokit::Geocoders::provider_order = [:google, :us]
4
-
5
- class ActsAsMappableTest < GeokitTestCase
6
-
7
- LOCATION_A_IP = "217.10.83.5"
8
-
9
- def setup
10
- @location_a = GeoKit::GeoLoc.new
11
- @location_a.lat = 32.918593
12
- @location_a.lng = -96.958444
13
- @location_a.city = "Irving"
14
- @location_a.state = "TX"
15
- @location_a.country_code = "US"
16
- @location_a.success = true
17
-
18
- @sw = GeoKit::LatLng.new(32.91663,-96.982841)
19
- @ne = GeoKit::LatLng.new(32.96302,-96.919495)
20
- @bounds_center=GeoKit::LatLng.new((@sw.lat+@ne.lat)/2,(@sw.lng+@ne.lng)/2)
21
-
22
- @starbucks = companies(:starbucks)
23
- @loc_a = locations(:a)
24
- @custom_loc_a = custom_locations(:a)
25
- @loc_e = locations(:e)
26
- @custom_loc_e = custom_locations(:e)
27
-
28
- @barnes_and_noble = mock_organizations(:barnes_and_noble)
29
- @address = mock_addresses(:address_barnes_and_noble)
30
- end
31
-
32
- def test_override_default_units_the_hard_way
33
- Location.default_units = :kms
34
- locations = Location.geo_scope(:origin => @loc_a).where("distance < 3.97")
35
- assert_equal 5, locations.all.size
36
- assert_equal 5, locations.count
37
- Location.default_units = :miles
38
- end
39
-
40
- def test_include
41
- locations = Location.geo_scope(:origin => @loc_a).includes(:company).where("company_id = 1").all
42
- assert !locations.empty?
43
- assert_equal 1, locations[0].company.id
44
- assert_equal 'Starbucks', locations[0].company.name
45
- end
46
-
47
- def test_distance_between_geocoded
48
- GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with("Irving, TX").returns(@location_a)
49
- GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with("San Francisco, CA").returns(@location_a)
50
- assert_equal 0, Location.distance_between("Irving, TX", "San Francisco, CA")
51
- end
52
-
53
- def test_distance_to_geocoded
54
- GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with("Irving, TX").returns(@location_a)
55
- assert_equal 0, @custom_loc_a.distance_to("Irving, TX")
56
- end
57
-
58
- def test_distance_to_geocoded_error
59
- GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with("Irving, TX").returns(GeoKit::GeoLoc.new)
60
- assert_raise(GeoKit::Geocoders::GeocodeError) { @custom_loc_a.distance_to("Irving, TX") }
61
- end
62
-
63
- def test_custom_attributes_distance_calculations
64
- assert_equal 0, @custom_loc_a.distance_to(@loc_a)
65
- assert_equal 0, CustomLocation.distance_between(@custom_loc_a, @loc_a)
66
- end
67
-
68
- def test_distance_column_in_select
69
- locations = Location.geo_scope(:origin => @loc_a).order("distance ASC")
70
- assert_equal 6, locations.all.size
71
- assert_equal 0, @loc_a.distance_to(locations.first)
72
- assert_in_delta 3.97, @loc_a.distance_to(locations.last, :units => :miles, :formula => :sphere), 0.01
73
- end
74
-
75
- def test_find_with_distance_condition
76
- locations = Location.geo_scope(:origin => @loc_a, :within => 3.97)
77
- assert_equal 5, locations.all.size
78
- assert_equal 5, locations.count
79
- end
80
-
81
- def test_find_with_distance_condition_with_units_override
82
- locations = Location.geo_scope(:origin => @loc_a, :units => :kms, :within => 6.387)
83
- assert_equal 5, locations.all.size
84
- assert_equal 5, locations.count
85
- end
86
-
87
- def test_find_with_distance_condition_with_formula_override
88
- locations = Location.geo_scope(:origin => @loc_a, :formula => :flat, :within => 6.387)
89
- assert_equal 6, locations.all.size
90
- assert_equal 6, locations.count
91
- end
92
-
93
- def test_find_within
94
- locations = Location.within(3.97, :origin => @loc_a)
95
- assert_equal 5, locations.all.size
96
- assert_equal 5, locations.count
97
- end
98
-
99
- def test_find_within_with_coordinates
100
- locations = Location.within(3.97, :origin =>[@loc_a.lat,@loc_a.lng])
101
- assert_equal 5, locations.all.size
102
- assert_equal 5, locations.count
103
- end
104
-
105
- def test_find_with_compound_condition
106
- locations = Location.geo_scope(:origin => @loc_a).where("distance < 5 and city = 'Coppell'")
107
- assert_equal 2, locations.all.size
108
- assert_equal 2, locations.count
109
- end
110
-
111
- def test_find_with_secure_compound_condition
112
- locations = Location.geo_scope(:origin => @loc_a).where(["distance < ? and city = ?", 5, 'Coppell'])
113
- assert_equal 2, locations.all.size
114
- assert_equal 2, locations.count
115
- end
116
-
117
- def test_find_beyond
118
- locations = Location.beyond(3.95, :origin => @loc_a)
119
- assert_equal 1, locations.all.size
120
- assert_equal 1, locations.count
121
- end
122
-
123
- def test_find_beyond_with_token
124
- # locations = Location.find(:all, :beyond => 3.95, :origin => @loc_a)
125
- locations = Location.geo_scope(:beyond => 3.95, :origin => @loc_a)
126
- assert_equal 1, locations.all.size
127
- assert_equal 1, locations.count
128
- end
129
-
130
- def test_find_beyond_with_coordinates
131
- locations = Location.beyond(3.95, :origin =>[@loc_a.lat, @loc_a.lng])
132
- assert_equal 1, locations.all.size
133
- assert_equal 1, locations.count
134
- end
135
-
136
- def test_find_range_with_token
137
- locations = Location.geo_scope(:range => 0..10, :origin => @loc_a)
138
- assert_equal 6, locations.all.size
139
- assert_equal 6, locations.count
140
- end
141
-
142
- def test_find_range_with_token_with_conditions
143
- locations = Location.geo_scope(:origin => @loc_a, :range => 0..10).where(["city = ?", 'Coppell'])
144
- assert_equal 2, locations.all.size
145
- assert_equal 2, locations.count
146
- end
147
-
148
- def test_find_range_with_token_with_hash_conditions
149
- locations = Location.geo_scope(:origin => @loc_a, :range => 0..10).where(:city => 'Coppell')
150
- assert_equal 2, locations.all.size
151
- assert_equal 2, locations.count
152
- end
153
-
154
- def test_find_range_with_token_excluding_end
155
- locations = Location.geo_scope(:range => 0...10, :origin => @loc_a)
156
- assert_equal 6, locations.all.size
157
- assert_equal 6, locations.count
158
- end
159
-
160
- def test_find_nearest
161
- assert_equal @loc_a, Location.nearest(:origin => @loc_a).first
162
- end
163
-
164
- def test_find_nearest_with_coordinates
165
- assert_equal @loc_a, Location.nearest(:origin =>[@loc_a.lat, @loc_a.lng]).first
166
- end
167
-
168
- def test_find_farthest
169
- assert_equal @loc_e, Location.farthest(:origin => @loc_a).first
170
- end
171
-
172
- def test_find_farthest_with_coordinates
173
- assert_equal @loc_e, Location.farthest(:origin =>[@loc_a.lat, @loc_a.lng]).first
174
- end
175
-
176
- def test_scoped_distance_column_in_select
177
- locations = @starbucks.locations.geo_scope(:origin => @loc_a).order("distance ASC")
178
- assert_equal 5, locations.all.size
179
- assert_equal 0, @loc_a.distance_to(locations.first)
180
- assert_in_delta 3.97, @loc_a.distance_to(locations.last, :units => :miles, :formula => :sphere), 0.01
181
- end
182
-
183
- def test_scoped_find_with_distance_condition
184
- locations = @starbucks.locations.geo_scope(:origin => @loc_a).where("distance < 3.97")
185
- assert_equal 4, locations.all.size
186
- assert_equal 4, locations.count
187
- end
188
-
189
- def test_scoped_find_within
190
- locations = @starbucks.locations.within(3.97, :origin => @loc_a)
191
- assert_equal 4, locations.all.size
192
- assert_equal 4, locations.count
193
- end
194
-
195
- def test_scoped_find_with_compound_condition
196
- locations = @starbucks.locations.geo_scope(:origin => @loc_a).where("distance < 5 and city = 'Coppell'")
197
- assert_equal 2, locations.all.size
198
- assert_equal 2, locations.count
199
- end
200
-
201
- def test_scoped_find_beyond
202
- locations = @starbucks.locations.beyond(3.95, :origin => @loc_a)
203
- assert_equal 1, locations.all.size
204
- assert_equal 1, locations.count
205
- end
206
-
207
- def test_scoped_find_nearest
208
- assert_equal @loc_a, @starbucks.locations.nearest(:origin => @loc_a).first
209
- end
210
-
211
- def test_scoped_find_farthest
212
- assert_equal @loc_e, @starbucks.locations.farthest(:origin => @loc_a).first
213
- end
214
-
215
- def test_ip_geocoded_distance_column_in_select
216
- GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
217
- locations = Location.geo_scope(:origin => LOCATION_A_IP).order("distance ASC")
218
- assert_equal 6, locations.all.size
219
- assert_equal 0, @loc_a.distance_to(locations.first)
220
- assert_in_delta 3.97, @loc_a.distance_to(locations.last, :units => :miles, :formula => :sphere), 0.01
221
- end
222
-
223
- def test_ip_geocoded_find_with_distance_condition
224
- GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
225
- locations = Location.geo_scope(:origin => LOCATION_A_IP).where2("distance < 3.97")
226
- assert_equal 5, locations.all.size
227
- assert_equal 5, locations.count
228
- end
229
-
230
- def test_ip_geocoded_find_within
231
- GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
232
- locations = Location.within(3.97, :origin => LOCATION_A_IP)
233
- assert_equal 5, locations.all.size
234
- assert_equal 5, locations.count
235
- end
236
-
237
- def test_ip_geocoded_find_with_compound_condition
238
- GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
239
- locations = Location.geo_scope(:origin => LOCATION_A_IP).where("distance < 5 and city = 'Coppell'")
240
- assert_equal 2, locations.all.size
241
- assert_equal 2, locations.count
242
- end
243
-
244
- def test_ip_geocoded_find_with_secure_compound_condition
245
- GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
246
- locations = Location.geo_scope(:origin => LOCATION_A_IP).where(["distance < ? and city = ?", 5, 'Coppell'])
247
- assert_equal 2, locations.all.size
248
- assert_equal 2, locations.count
249
- end
250
-
251
- def test_ip_geocoded_find_beyond
252
- GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
253
- locations = Location.beyond(3.95, :origin => LOCATION_A_IP)
254
- assert_equal 1, locations.all.size
255
- assert_equal 1, locations.count
256
- end
257
-
258
- def test_ip_geocoded_find_nearest
259
- GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
260
- assert_equal @loc_a, Location.nearest(:origin => LOCATION_A_IP).first
261
- end
262
-
263
- def test_ip_geocoded_find_farthest
264
- GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
265
- assert_equal @loc_e, Location.farthest(:origin => LOCATION_A_IP).first
266
- end
267
-
268
- def test_ip_geocoder_exception
269
- GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with('127.0.0.1').returns(GeoKit::GeoLoc.new)
270
- assert_raises GeoKit::Geocoders::GeocodeError do
271
- Location.farthest(:origin => '127.0.0.1').first
272
- end
273
- end
274
-
275
- def test_address_geocode
276
- GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with('Irving, TX').returns(@location_a)
277
- locations = Location.geo_scope(:origin => 'Irving, TX').where(["distance < ? and city = ?", 5, 'Coppell'])
278
- assert_equal 2, locations.all.size
279
- assert_equal 2, locations.count
280
- end
281
-
282
- def test_find_with_custom_distance_condition
283
- locations = CustomLocation.geo_scope(:origin => @loc_a).where("dist < 3.97")
284
- assert_equal 5, locations.all.size
285
- assert_equal 5, locations.count
286
- end
287
-
288
- def test_find_with_custom_distance_condition_using_custom_origin
289
- locations = CustomLocation.geo_scope(:origin => @custom_loc_a).where("dist < 3.97")
290
- assert_equal 5, locations.all.size
291
- locations = CustomLocation.count(:origin => @custom_loc_a).where("dist < 3.97")
292
- assert_equal 5, locations.count
293
- end
294
-
295
- def test_find_within_with_custom
296
- locations = CustomLocation.within(3.97, :origin => @loc_a)
297
- assert_equal 5, locations.all.size
298
- assert_equal 5, locations.count
299
- end
300
-
301
- def test_find_within_with_coordinates_with_custom
302
- locations = CustomLocation.within(3.97, :origin =>[@loc_a.lat, @loc_a.lng])
303
- assert_equal 5, locations.all.size
304
- assert_equal 5, locations.count
305
- end
306
-
307
- def test_find_with_compound_condition_with_custom
308
- locations = CustomLocation.geo_scope(:origin => @loc_a).where("dist < 5 and city = 'Coppell'")
309
- assert_equal 1, locations.all.size
310
- assert_equal 1, locations.count
311
- end
312
-
313
- def test_find_with_secure_compound_condition_with_custom
314
- locations = CustomLocation.geo_scope(:origin => @loc_a).where(["dist < ? and city = ?", 5, 'Coppell'])
315
- assert_equal 1, locations.all.size
316
- assert_equal 1, locations.count
317
- end
318
-
319
- def test_find_beyond_with_custom
320
- locations = CustomLocation.beyond(3.95, :origin => @loc_a)
321
- assert_equal 1, locations.all.size
322
- assert_equal 1, locations.count
323
- end
324
-
325
- def test_find_beyond_with_coordinates_with_custom
326
- locations = CustomLocation.beyond(3.95, :origin =>[@loc_a.lat, @loc_a.lng])
327
- assert_equal 1, locations.all.size
328
- assert_equal 1, locations.count
329
- end
330
-
331
- def test_find_nearest_with_custom
332
- assert_equal @custom_loc_a, CustomLocation.nearest(:origin => @loc_a).first
333
- end
334
-
335
- def test_find_nearest_with_coordinates_with_custom
336
- assert_equal @custom_loc_a, CustomLocation.nearest(:origin =>[@loc_a.lat, @loc_a.lng]).first
337
- end
338
-
339
- def test_find_farthest_with_custom
340
- assert_equal @custom_loc_e, CustomLocation.farthest(:origin => @loc_a).first
341
- end
342
-
343
- def test_find_farthest_with_coordinates_with_custom
344
- assert_equal @custom_loc_e, CustomLocation.farthest(:origin =>[@loc_a.lat, @loc_a.lng]).first
345
- end
346
-
347
- def test_find_with_array_origin
348
- locations = Location.geo_scope(:origin =>[@loc_a.lat,@loc_a.lng]).where("distance < 3.97")
349
- assert_equal 5, locations.all.size
350
- assert_equal 5, locations.count
351
- end
352
-
353
-
354
- # Bounding box tests
355
-
356
- def test_find_within_bounds
357
- locations = Location.in_bounds([@sw,@ne])
358
- assert_equal 2, locations.all.size
359
- assert_equal 2, locations.count
360
- end
361
-
362
- def test_find_within_bounds_ordered_by_distance
363
- locations = Location.in_bounds([@sw,@ne], :origin=>@bounds_center).order('distance asc')
364
- assert_equal locations[0], locations(:d)
365
- assert_equal locations[1], locations(:a)
366
- end
367
-
368
- def test_find_within_bounds_with_token
369
- locations = Location.geo_scope(:bounds=>[@sw,@ne])
370
- assert_equal 2, locations.all.size
371
- assert_equal 2, locations.count
372
- end
373
-
374
- def test_find_within_bounds_with_string_conditions
375
- locations = Location.geo_scope(:bounds=>[@sw,@ne]).where("id !=#{locations(:a).id}")
376
- assert_equal 1, locations.all.size
377
- end
378
-
379
- def test_find_within_bounds_with_array_conditions
380
- locations = Location.geo_scope(:bounds=>[@sw,@ne]).where(["id != ?", locations(:a).id])
381
- assert_equal 1, locations.all.size
382
- end
383
-
384
- def test_find_within_bounds_with_hash_conditions
385
- locations = Location.geo_scope(:bounds=>[@sw,@ne]).where({:id => locations(:a).id})
386
- assert_equal 1, locations.all.size
387
- end
388
-
389
- def test_auto_geocode
390
- GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with("Irving, TX").returns(@location_a)
391
- store=Store.new(:address=>'Irving, TX')
392
- store.save
393
- assert_equal store.lat,@location_a.lat
394
- assert_equal store.lng,@location_a.lng
395
- assert_equal 0, store.errors.size
396
- end
397
-
398
- def test_auto_geocode_failure
399
- GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with("BOGUS").returns(GeoKit::GeoLoc.new)
400
- store=Store.new(:address=>'BOGUS')
401
- store.save
402
- assert store.new_record?
403
- assert_equal 1, store.errors.size
404
- end
405
-
406
- # Test :through
407
-
408
- def test_find_with_through
409
- organizations = MockOrganization.geo_scope(:origin => @location_a).order('distance ASC')
410
- assert_equal 2, organizations.all.size
411
- organizations = MockOrganization.geo_scope(:origin => @location_a).where("distance < 3.97")
412
- assert_equal 1, organizations.count
413
- end
414
-
415
- def test_find_with_through_with_hash
416
- people = MockPerson.geo_scope(:origin => @location_a).order('distance ASC')
417
- assert_equal 2, people.size
418
- assert_equal 2, people
419
- end
420
- end