delayed_acts_as_geocodable 1.0.3

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.
@@ -0,0 +1,18 @@
1
+ sqlite:
2
+ :adapter: sqlite
3
+ :dbfile: acts_as_geocodable_plugin.sqlite.db
4
+ sqlite3:
5
+ :adapter: sqlite3
6
+ :dbfile: acts_as_geocodable_plugin.sqlite3.db
7
+ postgresql:
8
+ :adapter: postgresql
9
+ :username: postgres
10
+ :password: postgres
11
+ :database: acts_as_geocodable_plugin_test
12
+ :min_messages: ERROR
13
+ mysql:
14
+ :adapter: mysql
15
+ :host: localhost
16
+ :username: root
17
+ :password: for1@majed1
18
+ :database: acts_as_geocodable_plugin_test
data/test/db/schema.rb ADDED
@@ -0,0 +1,60 @@
1
+ ActiveRecord::Schema.define(:version => 1) do
2
+
3
+ create_table "geocodes", :force => true do |t|
4
+ t.column "latitude", :decimal, :precision => 15, :scale => 12
5
+ t.column "longitude", :decimal, :precision => 15, :scale => 12
6
+ t.column "query", :string
7
+ t.column "street", :string
8
+ t.column "locality", :string
9
+ t.column "region", :string
10
+ t.column "postal_code", :string
11
+ t.column "country", :string
12
+ end
13
+
14
+ add_index "geocodes", ["query"], :name => "geocodes_query_index", :unique => true
15
+ add_index "geocodes", ["latitude"], :name => "geocodes_latitude_index"
16
+ add_index "geocodes", ["longitude"], :name => "geocodes_longitude_index"
17
+
18
+ create_table "geocodings", :force => true do |t|
19
+ t.column "geocodable_id", :integer
20
+ t.column "geocode_id", :integer
21
+ t.column "geocodable_type", :string
22
+ end
23
+
24
+ add_index "geocodings", ["geocodable_id"], :name => "geocodings_geocodable_id_index"
25
+ add_index "geocodings", ["geocode_id"], :name => "geocodings_geocode_id_index"
26
+ add_index "geocodings", ["geocodable_type"], :name => "geocodings_geocodable_type_index"
27
+
28
+ create_table "vacations", :force => true do |t|
29
+ t.column "name", :string
30
+ t.column "street", :string
31
+ t.column "locality", :string
32
+ t.column "region", :string
33
+ t.column "postal_code", :string
34
+ t.column "city_id", :integer
35
+ end
36
+
37
+ create_table "validated_vacations", :force => true do |t|
38
+ t.column "name", :string
39
+ t.column "street", :string
40
+ t.column "locality", :string
41
+ t.column "region", :string
42
+ t.column "postal_code", :string
43
+ end
44
+
45
+ create_table "address_blob_vacations", :force => true do |t|
46
+ t.column "name", :string
47
+ t.column "address", :string
48
+ end
49
+
50
+ create_table "callback_locations", :force => true do |t|
51
+ t.column "name", :string
52
+ t.column "address", :string
53
+ end
54
+
55
+ create_table "cities", :force => true do |t|
56
+ t.column "name", :string
57
+ t.column "zip", :string
58
+ end
59
+
60
+ end
@@ -0,0 +1,12 @@
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: ""
@@ -0,0 +1,51 @@
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
@@ -0,0 +1,15 @@
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
@@ -0,0 +1,15 @@
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
@@ -0,0 +1,97 @@
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
@@ -0,0 +1,46 @@
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
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: delayed_acts_as_geocodable
3
+ version: !ruby/object:Gem::Version
4
+ hash: 17
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 3
10
+ version: 1.0.3
11
+ platform: ruby
12
+ authors:
13
+ - Rubem Azenha
14
+ - Daniel Morrison
15
+ - Brandon Keepers
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2010-08-26 00:00:00 -03:00
21
+ default_executable:
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ name: graticule
25
+ prerelease: false
26
+ requirement: &id001 !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ hash: -1876988175
32
+ segments:
33
+ - 1
34
+ - 0
35
+ - 0
36
+ - pre2
37
+ version: 1.0.0.pre2
38
+ type: :runtime
39
+ version_requirements: *id001
40
+ - !ruby/object:Gem::Dependency
41
+ name: delayed_job
42
+ prerelease: false
43
+ requirement: &id002 !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ hash: 9
49
+ segments:
50
+ - 2
51
+ - 0
52
+ - 3
53
+ version: 2.0.3
54
+ type: :runtime
55
+ version_requirements: *id002
56
+ description: Simple geocoding for Rails ActiveRecord models. See the README for more details.
57
+ email: rubem.azenha@gmail.com
58
+ executables: []
59
+
60
+ extensions: []
61
+
62
+ extra_rdoc_files:
63
+ - README
64
+ files:
65
+ - .gitignore
66
+ - CHANGELOG
67
+ - MIT-LICENSE
68
+ - README
69
+ - Rakefile
70
+ - VERSION
71
+ - about.yml
72
+ - acts_as_geocodable.gemspec
73
+ - generators/geocodable_migration/USAGE
74
+ - generators/geocodable_migration/geocodable_migration_generator.rb
75
+ - generators/geocodable_migration/templates/migration.rb
76
+ - install.rb
77
+ - lib/acts_as_geocodable.rb
78
+ - lib/acts_as_geocodable/geocode.rb
79
+ - lib/acts_as_geocodable/geocoding.rb
80
+ - lib/acts_as_geocodable/remote_location.rb
81
+ - lib/acts_as_geocodable/tasks/acts_as_geocodable_tasks.rake
82
+ - rails/init.rb
83
+ - test/acts_as_geocodable_test.rb
84
+ - test/db/database.yml
85
+ - test/db/schema.rb
86
+ - test/fixtures/cities.yml
87
+ - test/fixtures/geocodes.yml
88
+ - test/fixtures/geocodings.yml
89
+ - test/fixtures/vacations.yml
90
+ - test/geocode_test.rb
91
+ - test/test_helper.rb
92
+ - uninstall.rb
93
+ has_rdoc: true
94
+ homepage: http://github.com/collectiveidea/acts_as_geocodable
95
+ licenses: []
96
+
97
+ post_install_message:
98
+ rdoc_options:
99
+ - --charset=UTF-8
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ requirements: []
121
+
122
+ rubyforge_project:
123
+ rubygems_version: 1.3.7
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: Simple geocoding for Rails ActiveRecord models
127
+ test_files:
128
+ - test/acts_as_geocodable_test.rb
129
+ - test/db/schema.rb
130
+ - test/geocode_test.rb
131
+ - test/test_helper.rb