acts_as_geocodable 1.0.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +0,0 @@
1
- holland:
2
- id: 1
3
- name: Holland
4
- zip: 49423
5
- chicago:
6
- id: 2
7
- name: Chicago
8
- zip:
9
- nowhere:
10
- id: 3
11
- name: Nowhere
12
- zip: ""
@@ -1,51 +0,0 @@
1
- saugatuck_geocode:
2
- id: 1
3
- latitude: 42.654781
4
- longitude: -86.200722
5
- query: "Saugatuck, MI"
6
- locality: Saugatuck
7
- region: MI
8
- white_house_geocode:
9
- id: 2
10
- latitude: 38.898748
11
- longitude: -77.037684
12
- query: "1600 Pennsylvania Ave NW\nWashington, DC 20502"
13
- street: 1600 Pennsylvania Ave NW
14
- locality: Washington
15
- region: DC
16
- postal_code: 20502
17
- chicago_geocode:
18
- id: 3
19
- latitude: 41.85
20
- longitude: -87.65
21
- query: Chicago, IL
22
- locality: Chicago
23
- region: IL
24
- postal_code:
25
- douglas:
26
- id: 4
27
- query: "49406"
28
- longitude: -86.2005
29
- latitude: 42.6433
30
- locality: Douglas
31
- region: MI
32
- postal_code: 49406
33
- country: US
34
- holland:
35
- id: 5
36
- query: Holland, MI
37
- longitude: -86.109039
38
- latitude: 42.787567
39
- locality: Holland
40
- postal_code:
41
- region: MI
42
- country: US
43
- beverly_hills:
44
- id: 6
45
- query: Beverly Hills, 90210
46
- latitude: 34.092400000000
47
- longitude: -118.409800000000
48
- locality: Beverly Hills
49
- region: CA
50
- country: US
51
- postal_code: 90210
@@ -1,15 +0,0 @@
1
- saugatuck_geocoding:
2
- id: 1
3
- geocodable_id: 1
4
- geocode_id: 1
5
- geocodable_type: Vacation
6
- white_house_geocoding:
7
- id: 2
8
- geocodable_id: 2
9
- geocode_id: 2
10
- geocodable_type: Vacation
11
- chicago_geocoding:
12
- id: 3
13
- geocodable_id: 1
14
- geocode_id: 3
15
- geocodable_type: City
@@ -1,15 +0,0 @@
1
- saugatuck:
2
- id: 1
3
- name: Saugatuck, Michigan
4
- whitehouse:
5
- id: 2
6
- name: The White House
7
- street: 1600 Pennsylvania Ave NW
8
- locality: Washington
9
- region: DC
10
- postal_code: 20502
11
- mystery_spot:
12
- id: 3
13
- name: The Mystery Spot
14
- street: 150 Martin Lake Rd.
15
- postal_code: 49781
@@ -1,97 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper')
2
-
3
- class GeocodeTest < ActiveSupport::TestCase
4
- fixtures :geocodes
5
-
6
- context 'distance_to' do
7
- setup do
8
- @washington_dc = geocodes(:white_house_geocode)
9
- @chicago = geocodes(:chicago_geocode)
10
- end
11
-
12
- should 'properly calculate distance in default units' do
13
- @washington_dc.distance_to(@chicago).should be_close(594.820, 1.0)
14
- end
15
-
16
- should 'properly calculate distance in default miles' do
17
- @washington_dc.distance_to(@chicago, :miles).should be_close(594.820, 1.0)
18
- end
19
-
20
- should 'properly calculate distance in default kilometers' do
21
- @washington_dc.distance_to(@chicago, :kilometers).should be_close(957.275, 1.0)
22
- end
23
-
24
- should 'return nil with invalid geocode' do
25
- @chicago.distance_to(Geocode.new).should be(nil)
26
- @chicago.distance_to(nil).should be(nil)
27
- end
28
- end
29
-
30
- context 'find_or_create_by_query' do
31
- should 'finds existing geocode' do
32
- Geocode.find_or_create_by_query('Holland, MI').should == geocodes(:holland)
33
- end
34
- end
35
-
36
- context "find_or_create_by_location" do
37
- should "find existing location" do
38
- location = Graticule::Location.new(:postal_code => "20502",
39
- :street => "1600 Pennsylvania Ave NW",
40
- :locality => "Washington",
41
- :region => "DC")
42
- Geocode.find_or_create_by_location(location).should == geocodes(:white_house_geocode)
43
- end
44
-
45
- should "return nil when location can't be geocoded" do
46
- Geocode.geocoder.expects(:locate).raises(Graticule::Error)
47
- assert_no_difference 'Geocode.count' do
48
- Geocode.find_or_create_by_location(Graticule::Location.new(:street => 'FAIL!')).should be(nil)
49
- end
50
- end
51
-
52
- end
53
-
54
- context 'coordinates' do
55
- should 'return longitude and latitude' do
56
- geocodes(:saugatuck_geocode).coordinates.should == "-86.200722,42.654781"
57
- end
58
- end
59
-
60
- context 'to_s' do
61
- should 'return the coordinates' do
62
- geocodes(:saugatuck_geocode).to_s.should == geocodes(:saugatuck_geocode).coordinates
63
- end
64
- end
65
-
66
- context 'geocoded?' do
67
- should 'be true with both a latitude and a longitude' do
68
- assert Geocode.new(:latitude => 1, :longitude => 1).geocoded?
69
- end
70
-
71
- should 'be false when missing coordinates' do
72
- assert !Geocode.new.geocoded?
73
- end
74
-
75
- should 'be false when missing a latitude' do
76
- assert !Geocode.new(:longitude => 1).geocoded?
77
- end
78
-
79
- should 'be false when missing a longitude' do
80
- assert !Geocode.new(:latitude => 1).geocoded?
81
- end
82
- end
83
-
84
- end
85
-
86
- __END__
87
-
88
-
89
-
90
- def test_to_location
91
- location = geocodes(:white_house_geocode).to_location
92
-
93
- assert_kind_of Graticule::Location, location
94
- [:street, :locality, :region, :postal_code, :latitude, :longitude].each do |attr|
95
- assert_not_nil location.send(attr)
96
- end
97
- end
@@ -1,46 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__) + '/../lib')
2
- plugin_test_dir = File.dirname(__FILE__)
3
-
4
- require 'rubygems'
5
- require 'test/unit'
6
- require 'multi_rails_init'
7
- require 'active_support'
8
- require 'active_record'
9
- require 'action_controller'
10
- require 'active_record/fixtures'
11
- require 'shoulda'
12
- require 'matchy'
13
- require 'mocha'
14
-
15
- require plugin_test_dir + '/../rails/init.rb'
16
-
17
- ActiveRecord::Base.logger = Logger.new(plugin_test_dir + "/debug.log")
18
-
19
- ActiveRecord::Base.configurations = YAML::load(IO.read(plugin_test_dir + "/db/database.yml"))
20
- ActiveRecord::Base.establish_connection(ENV["DB"] || "mysql")
21
- ActiveRecord::Migration.verbose = false
22
- load(File.join(plugin_test_dir, "db", "schema.rb"))
23
-
24
- Geocode.geocoder ||= Graticule.service(:bogus).new
25
-
26
- class ActiveSupport::TestCase #:nodoc:
27
- include ActiveRecord::TestFixtures if ActiveRecord.const_defined?(:TestFixtures)
28
-
29
- self.fixture_path = File.dirname(__FILE__) + "/fixtures/"
30
-
31
- # Turn off transactional fixtures if you're working with MyISAM tables in MySQL
32
- self.use_transactional_fixtures = true
33
-
34
- # Instantiated fixtures are slow, but give you @david where you otherwise would need people(:david)
35
- self.use_instantiated_fixtures = false
36
-
37
- def assert_geocode_result(result)
38
- assert_not_nil result
39
- assert result.latitude.is_a?(BigDecimal) || result.latitude.is_a?(Float), "latitude is a #{result.latitude.class.name}"
40
- assert result.longitude.is_a?(BigDecimal) || result.longitude.is_a?(Float)
41
-
42
- # Depending on the geocoder, we'll get slightly different results
43
- assert_in_delta 42.787567, result.latitude, 0.001
44
- assert_in_delta -86.109039, result.longitude, 0.001
45
- end
46
- end
@@ -1 +0,0 @@
1
- # Uninstall hook code here