geokit-rails3 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +30 -0
  2. data/CHANGELOG.rdoc +46 -0
  3. data/CONFIG.markdown +67 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +89 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.markdown +554 -0
  8. data/Rakefile +17 -0
  9. data/geokit-rails3.gemspec +29 -0
  10. data/lib/geokit-rails.rb +10 -0
  11. data/lib/geokit-rails3/acts_as_mappable.rb +433 -0
  12. data/lib/geokit-rails3/adapters/abstract.rb +31 -0
  13. data/lib/geokit-rails3/adapters/mysql.rb +22 -0
  14. data/lib/geokit-rails3/adapters/postgresql.rb +22 -0
  15. data/lib/geokit-rails3/adapters/sqlserver.rb +43 -0
  16. data/lib/geokit-rails3/core_extensions.rb +14 -0
  17. data/lib/geokit-rails3/defaults.rb +21 -0
  18. data/lib/geokit-rails3/geocoder_control.rb +18 -0
  19. data/lib/geokit-rails3/ip_geocode_lookup.rb +44 -0
  20. data/lib/geokit-rails3/railtie.rb +38 -0
  21. data/lib/geokit-rails3/version.rb +3 -0
  22. data/test/acts_as_mappable_test.rb +473 -0
  23. data/test/boot.rb +32 -0
  24. data/test/database.yml +20 -0
  25. data/test/fixtures/companies.yml +7 -0
  26. data/test/fixtures/custom_locations.yml +54 -0
  27. data/test/fixtures/locations.yml +54 -0
  28. data/test/fixtures/mock_addresses.yml +17 -0
  29. data/test/fixtures/mock_families.yml +2 -0
  30. data/test/fixtures/mock_houses.yml +9 -0
  31. data/test/fixtures/mock_organizations.yml +5 -0
  32. data/test/fixtures/mock_people.yml +5 -0
  33. data/test/fixtures/stores.yml +0 -0
  34. data/test/models/company.rb +3 -0
  35. data/test/models/custom_location.rb +12 -0
  36. data/test/models/location.rb +4 -0
  37. data/test/models/mock_address.rb +4 -0
  38. data/test/models/mock_family.rb +3 -0
  39. data/test/models/mock_house.rb +3 -0
  40. data/test/models/mock_organization.rb +4 -0
  41. data/test/models/mock_person.rb +4 -0
  42. data/test/models/store.rb +3 -0
  43. data/test/schema.rb +60 -0
  44. data/test/tasks.rake +38 -0
  45. data/test/test_helper.rb +23 -0
  46. metadata +236 -0
data/test/boot.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'pathname'
2
+
3
+ require 'test/unit'
4
+ require 'active_support/test_case'
5
+
6
+ require 'active_record'
7
+ require 'active_record/test_case'
8
+ require 'active_record/fixtures'
9
+
10
+ # require 'action_controller'
11
+ # require 'action_dispatch'
12
+ # require 'action_dispatch/testing/test_process'
13
+
14
+ pwd = Pathname.new(File.dirname(__FILE__)).expand_path
15
+
16
+ PLUGIN_ROOT = pwd + '..'
17
+ ADAPTER = ENV['DB'] || 'mysql'
18
+
19
+ $LOAD_PATH << (PLUGIN_ROOT + 'lib')
20
+ $LOAD_PATH << (PLUGIN_ROOT + 'test/models')
21
+
22
+ config_file = PLUGIN_ROOT + 'test/database.yml'
23
+ db_config = YAML::load(IO.read(config_file))
24
+ logger_file = PLUGIN_ROOT + "test/#{ADAPTER}-debug.log"
25
+ schema_file = PLUGIN_ROOT + 'test/schema.rb'
26
+
27
+ ActiveRecord::Base.configurations = db_config
28
+ ActiveRecord::Base.logger = Logger.new(logger_file)
29
+ ActiveRecord::Base.establish_connection(db_config[ADAPTER])
30
+
31
+ ActiveRecord::Migration.verbose = false
32
+ load schema_file
data/test/database.yml ADDED
@@ -0,0 +1,20 @@
1
+ baes: &base
2
+ host: localhost
3
+ username: tests
4
+ password:
5
+
6
+ mysql:
7
+ adapter: mysql
8
+ database: geokit_rails_tests
9
+ <<: *base
10
+
11
+ postgresql:
12
+ adapter: postgresql
13
+ database: geokit_rails_tests
14
+ <<: *base
15
+
16
+ sqlserver:
17
+ adapter: sqlserver
18
+ mode: ODBC
19
+ dsn: geokit_rails_tests
20
+ username: tests
@@ -0,0 +1,7 @@
1
+ starbucks:
2
+ id: 1
3
+ name: Starbucks
4
+
5
+ barnes_and_noble:
6
+ id: 2
7
+ name: Barnes & Noble
@@ -0,0 +1,54 @@
1
+ a:
2
+ id: 1
3
+ company_id: 1
4
+ street: 7979 N MacArthur Blvd
5
+ city: Irving
6
+ state: TX
7
+ postal_code: 75063
8
+ latitude: 32.918593
9
+ longitude: -96.958444
10
+ b:
11
+ id: 2
12
+ company_id: 1
13
+ street: 7750 N Macarthur Blvd # 160
14
+ city: Irving
15
+ state: TX
16
+ postal_code: 75063
17
+ latitude: 32.914144
18
+ longitude: -96.958444
19
+ c:
20
+ id: 3
21
+ company_id: 1
22
+ street: 5904 N Macarthur Blvd # 160
23
+ city: Irving
24
+ state: TX
25
+ postal_code: 75039
26
+ latitude: 32.895155
27
+ longitude: -96.958444
28
+ d:
29
+ id: 4
30
+ company_id: 1
31
+ street: 817 S Macarthur Blvd # 145
32
+ city: Coppell
33
+ state: TX
34
+ postal_code: 75019
35
+ latitude: 32.951613
36
+ longitude: -96.958444
37
+ e:
38
+ id: 5
39
+ company_id: 1
40
+ street: 106 N Denton Tap Rd # 350
41
+ city: Coppell
42
+ state: TX
43
+ postal_code: 75019
44
+ latitude: 32.969527
45
+ longitude: -96.990159
46
+ f:
47
+ id: 6
48
+ company_id: 2
49
+ street: 5904 N Macarthur Blvd # 160
50
+ city: Irving
51
+ state: TX
52
+ postal_code: 75039
53
+ latitude: 32.895155
54
+ longitude: -96.958444
@@ -0,0 +1,54 @@
1
+ a:
2
+ id: 1
3
+ company_id: 1
4
+ street: 7979 N MacArthur Blvd
5
+ city: Irving
6
+ state: TX
7
+ postal_code: 75063
8
+ lat: 32.918593
9
+ lng: -96.958444
10
+ b:
11
+ id: 2
12
+ company_id: 1
13
+ street: 7750 N Macarthur Blvd # 160
14
+ city: Irving
15
+ state: TX
16
+ postal_code: 75063
17
+ lat: 32.914144
18
+ lng: -96.958444
19
+ c:
20
+ id: 3
21
+ company_id: 1
22
+ street: 5904 N Macarthur Blvd # 160
23
+ city: Irving
24
+ state: TX
25
+ postal_code: 75039
26
+ lat: 32.895155
27
+ lng: -96.958444
28
+ d:
29
+ id: 4
30
+ company_id: 1
31
+ street: 817 S Macarthur Blvd # 145
32
+ city: Coppell
33
+ state: TX
34
+ postal_code: 75019
35
+ lat: 32.951613
36
+ lng: -96.958444
37
+ e:
38
+ id: 5
39
+ company_id: 1
40
+ street: 106 N Denton Tap Rd # 350
41
+ city: Coppell
42
+ state: TX
43
+ postal_code: 75019
44
+ lat: 32.969527
45
+ lng: -96.990159
46
+ f:
47
+ id: 6
48
+ company_id: 2
49
+ street: 5904 N Macarthur Blvd # 160
50
+ city: Irving
51
+ state: TX
52
+ postal_code: 75039
53
+ lat: 32.895155
54
+ lng: -96.958444
@@ -0,0 +1,17 @@
1
+ address_starbucks:
2
+ addressable: starbucks (MockOrganization)
3
+ street: 106 N Denton Tap Rd # 350
4
+ city: Coppell
5
+ state: TX
6
+ postal_code: 75019
7
+ lat: 32.969527
8
+ lng: -96.990159
9
+
10
+ address_barnes_and_noble:
11
+ addressable: barnes_and_noble (MockOrganization)
12
+ street: 5904 N Macarthur Blvd # 160
13
+ city: Irving
14
+ state: TX
15
+ postal_code: 75039
16
+ lat: 32.895155
17
+ lng: -96.958444
@@ -0,0 +1,2 @@
1
+ my_family:
2
+ mock_house: my_house
@@ -0,0 +1,9 @@
1
+ another_house:
2
+ address: 106 N Denton Tap Rd # 350
3
+ lat: 32.969527
4
+ lng: -96.990159
5
+
6
+ my_house:
7
+ address: 5904 N Macarthur Blvd # 160
8
+ lat: 32.895155
9
+ lng: -96.958444
@@ -0,0 +1,5 @@
1
+ starbucks:
2
+ name: Starbucks
3
+
4
+ barnes_and_noble:
5
+ name: Barnes & Noble
@@ -0,0 +1,5 @@
1
+ father:
2
+ mock_family: my_family
3
+
4
+ mother:
5
+ mock_family: my_family
File without changes
@@ -0,0 +1,3 @@
1
+ class Company < ActiveRecord::Base
2
+ has_many :locations
3
+ end
@@ -0,0 +1,12 @@
1
+ class CustomLocation < ActiveRecord::Base
2
+ belongs_to :company
3
+ acts_as_mappable :distance_column_name => 'dist',
4
+ :default_units => :kms,
5
+ :default_formula => :flat,
6
+ :lat_column_name => 'latitude',
7
+ :lng_column_name => 'longitude'
8
+
9
+ def to_s
10
+ "lat: #{latitude} lng: #{longitude} dist: #{dist}"
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ class Location < ActiveRecord::Base
2
+ belongs_to :company
3
+ acts_as_mappable
4
+ end
@@ -0,0 +1,4 @@
1
+ class MockAddress < ActiveRecord::Base
2
+ belongs_to :addressable, :polymorphic => true
3
+ acts_as_mappable
4
+ end
@@ -0,0 +1,3 @@
1
+ class MockFamily < ActiveRecord::Base
2
+ belongs_to :mock_house
3
+ end
@@ -0,0 +1,3 @@
1
+ class MockHouse < ActiveRecord::Base
2
+ acts_as_mappable
3
+ end
@@ -0,0 +1,4 @@
1
+ class MockOrganization < ActiveRecord::Base
2
+ has_one :mock_address, :as => :addressable
3
+ acts_as_mappable :through => :mock_address
4
+ end
@@ -0,0 +1,4 @@
1
+ class MockPerson < ActiveRecord::Base
2
+ belongs_to :mock_family
3
+ acts_as_mappable :through => { :mock_family => :mock_house }
4
+ end
@@ -0,0 +1,3 @@
1
+ class Store < ActiveRecord::Base
2
+ acts_as_mappable :auto_geocode => true
3
+ end
data/test/schema.rb ADDED
@@ -0,0 +1,60 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+ create_table :companies, :force => true do |t|
3
+ t.column :name, :string
4
+ end
5
+
6
+ create_table :locations, :force => true do |t|
7
+ t.column :company_id, :integer, :default => 0, :null => false
8
+ t.column :street, :string, :limit => 60
9
+ t.column :city, :string, :limit => 60
10
+ t.column :state, :string, :limit => 2
11
+ t.column :postal_code, :string, :limit => 16
12
+ t.column :lat, :decimal, :precision => 15, :scale => 10
13
+ t.column :lng, :decimal, :precision => 15, :scale => 10
14
+ end
15
+
16
+ create_table :custom_locations, :force => true do |t|
17
+ t.column :company_id, :integer, :default => 0, :null => false
18
+ t.column :street, :string, :limit => 60
19
+ t.column :city, :string, :limit => 60
20
+ t.column :state, :string, :limit => 2
21
+ t.column :postal_code, :string, :limit => 16
22
+ t.column :latitude, :decimal, :precision => 15, :scale => 10
23
+ t.column :longitude, :decimal, :precision => 15, :scale => 10
24
+ end
25
+
26
+ create_table :stores, :force=> true do |t|
27
+ t.column :address, :string
28
+ t.column :lat, :decimal, :precision => 15, :scale => 10
29
+ t.column :lng, :decimal, :precision => 15, :scale => 10
30
+ end
31
+
32
+ create_table :mock_organizations, :force => true do |t|
33
+ t.column :name, :string
34
+ end
35
+
36
+ create_table :mock_addresses, :force => true do |t|
37
+ t.column :addressable_id, :integer, :null => false
38
+ t.column :addressable_type, :string, :null => false
39
+ t.column :street, :string, :limit => 60
40
+ t.column :city, :string, :limit => 60
41
+ t.column :state, :string, :limit => 2
42
+ t.column :postal_code, :string, :limit => 16
43
+ t.column :lat, :decimal, :precision => 15, :scale => 10
44
+ t.column :lng, :decimal, :precision => 15, :scale => 10
45
+ end
46
+
47
+ create_table :mock_houses, :force=> true do |t|
48
+ t.column :address, :string
49
+ t.column :lat, :decimal, :precision => 15, :scale => 10
50
+ t.column :lng, :decimal, :precision => 15, :scale => 10
51
+ end
52
+
53
+ create_table :mock_families, :force => true do |t|
54
+ t.belongs_to :mock_house
55
+ end
56
+
57
+ create_table :mock_people, :force => true do |t|
58
+ t.belongs_to :mock_family
59
+ end
60
+ end
data/test/tasks.rake ADDED
@@ -0,0 +1,38 @@
1
+ require 'rake/testtask'
2
+
3
+ class EnvTestTask < Rake::TestTask
4
+ attr_accessor :env
5
+
6
+ def ruby(*args)
7
+ env.each { |key, value| ENV[key] = value } if env
8
+ super
9
+ env.keys.each { |key| ENV.delete(key) } if env
10
+ end
11
+
12
+ end
13
+
14
+ desc 'Test the GeoKit plugin.'
15
+ Rake::TestTask.new(:test) do |test|
16
+ test.libs << 'lib' << 'test'
17
+ test.pattern = 'test/**/test_*.rb'
18
+ test.verbose = true
19
+ end
20
+
21
+ %w(mysql postgresql sqlserver).each do |configuration|
22
+ EnvTestTask.new("test_#{configuration}") do |t|
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = true
25
+ t.env = { 'DB' => configuration }
26
+ t.libs << 'test'
27
+ end
28
+ end
29
+
30
+ desc 'Test available databases.'
31
+ task :test_databases => %w(test_mysql test_postgresql test_sqlserver)
32
+
33
+ require 'rcov/rcovtask'
34
+ Rcov::RcovTask.new do |test|
35
+ test.libs << 'test'
36
+ test.pattern = 'test/**/test_*.rb'
37
+ test.verbose = true
38
+ end
@@ -0,0 +1,23 @@
1
+ require 'mocha'
2
+ require 'pathname'
3
+
4
+ require 'boot'
5
+
6
+ require 'geokit'
7
+ require 'geokit-rails3'
8
+
9
+ ActiveRecord::Base.send(:include, Geokit::ActsAsMappable::Glue)
10
+
11
+ class GeokitTestCase < ActiveSupport::TestCase
12
+ begin
13
+ include ActiveRecord::TestFixtures
14
+ rescue NameError
15
+ puts "You appear to be using a pre-2.3 version of Rails. No need to include ActiveRecord::TestFixtures."
16
+ end
17
+
18
+ self.fixture_path = (PLUGIN_ROOT + 'test/fixtures').to_s
19
+ self.use_transactional_fixtures = true
20
+ self.use_instantiated_fixtures = false
21
+
22
+ fixtures :all
23
+ end
metadata ADDED
@@ -0,0 +1,236 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geokit-rails3
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - Andre Lewis
14
+ - Bill Eisenhauer
15
+ - Jeremy Lecour
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2010-10-11 00:00:00 +02:00
21
+ default_executable:
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ name: rails
25
+ prerelease: false
26
+ requirement: &id001 !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ hash: 7
32
+ segments:
33
+ - 3
34
+ - 0
35
+ - 0
36
+ version: 3.0.0
37
+ type: :runtime
38
+ version_requirements: *id001
39
+ - !ruby/object:Gem::Dependency
40
+ name: geokit
41
+ prerelease: false
42
+ requirement: &id002 !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ hash: 3
48
+ segments:
49
+ - 1
50
+ - 5
51
+ - 0
52
+ version: 1.5.0
53
+ type: :runtime
54
+ version_requirements: *id002
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ prerelease: false
58
+ requirement: &id003 !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ hash: 23
64
+ segments:
65
+ - 1
66
+ - 0
67
+ - 0
68
+ version: 1.0.0
69
+ type: :development
70
+ version_requirements: *id003
71
+ - !ruby/object:Gem::Dependency
72
+ name: rcov
73
+ prerelease: false
74
+ requirement: &id004 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ~>
78
+ - !ruby/object:Gem::Version
79
+ hash: 41
80
+ segments:
81
+ - 0
82
+ - 9
83
+ - 9
84
+ version: 0.9.9
85
+ type: :development
86
+ version_requirements: *id004
87
+ - !ruby/object:Gem::Dependency
88
+ name: mocha
89
+ prerelease: false
90
+ requirement: &id005 !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ hash: 43
96
+ segments:
97
+ - 0
98
+ - 9
99
+ - 8
100
+ version: 0.9.8
101
+ type: :development
102
+ version_requirements: *id005
103
+ - !ruby/object:Gem::Dependency
104
+ name: mysql
105
+ prerelease: false
106
+ requirement: &id006 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ hash: 45
112
+ segments:
113
+ - 2
114
+ - 8
115
+ - 1
116
+ version: 2.8.1
117
+ type: :development
118
+ version_requirements: *id006
119
+ description: Port of the Rails plugin "geokit-rails" to Rails 3, as a gem
120
+ email:
121
+ - andre@earthcode.com
122
+ - bill_eisenhauer@yahoo.com
123
+ - jeremy.lecour@gmail.com
124
+ executables: []
125
+
126
+ extensions: []
127
+
128
+ extra_rdoc_files: []
129
+
130
+ files:
131
+ - .gitignore
132
+ - CHANGELOG.rdoc
133
+ - CONFIG.markdown
134
+ - Gemfile
135
+ - Gemfile.lock
136
+ - MIT-LICENSE
137
+ - README.markdown
138
+ - Rakefile
139
+ - geokit-rails3.gemspec
140
+ - lib/geokit-rails.rb
141
+ - lib/geokit-rails3/acts_as_mappable.rb
142
+ - lib/geokit-rails3/adapters/abstract.rb
143
+ - lib/geokit-rails3/adapters/mysql.rb
144
+ - lib/geokit-rails3/adapters/postgresql.rb
145
+ - lib/geokit-rails3/adapters/sqlserver.rb
146
+ - lib/geokit-rails3/core_extensions.rb
147
+ - lib/geokit-rails3/defaults.rb
148
+ - lib/geokit-rails3/geocoder_control.rb
149
+ - lib/geokit-rails3/ip_geocode_lookup.rb
150
+ - lib/geokit-rails3/railtie.rb
151
+ - lib/geokit-rails3/version.rb
152
+ - test/acts_as_mappable_test.rb
153
+ - test/boot.rb
154
+ - test/database.yml
155
+ - test/fixtures/companies.yml
156
+ - test/fixtures/custom_locations.yml
157
+ - test/fixtures/locations.yml
158
+ - test/fixtures/mock_addresses.yml
159
+ - test/fixtures/mock_families.yml
160
+ - test/fixtures/mock_houses.yml
161
+ - test/fixtures/mock_organizations.yml
162
+ - test/fixtures/mock_people.yml
163
+ - test/fixtures/stores.yml
164
+ - test/models/company.rb
165
+ - test/models/custom_location.rb
166
+ - test/models/location.rb
167
+ - test/models/mock_address.rb
168
+ - test/models/mock_family.rb
169
+ - test/models/mock_house.rb
170
+ - test/models/mock_organization.rb
171
+ - test/models/mock_person.rb
172
+ - test/models/store.rb
173
+ - test/schema.rb
174
+ - test/tasks.rake
175
+ - test/test_helper.rb
176
+ has_rdoc: true
177
+ homepage: http://github.com/jlecour/geokit-rails3
178
+ licenses: []
179
+
180
+ post_install_message:
181
+ rdoc_options: []
182
+
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ hash: 3
191
+ segments:
192
+ - 0
193
+ version: "0"
194
+ required_rubygems_version: !ruby/object:Gem::Requirement
195
+ none: false
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ hash: 23
200
+ segments:
201
+ - 1
202
+ - 3
203
+ - 6
204
+ version: 1.3.6
205
+ requirements: []
206
+
207
+ rubyforge_project:
208
+ rubygems_version: 1.3.7
209
+ signing_key:
210
+ specification_version: 3
211
+ summary: Integrate Geokit with Rails 3
212
+ test_files:
213
+ - test/acts_as_mappable_test.rb
214
+ - test/boot.rb
215
+ - test/database.yml
216
+ - test/fixtures/companies.yml
217
+ - test/fixtures/custom_locations.yml
218
+ - test/fixtures/locations.yml
219
+ - test/fixtures/mock_addresses.yml
220
+ - test/fixtures/mock_families.yml
221
+ - test/fixtures/mock_houses.yml
222
+ - test/fixtures/mock_organizations.yml
223
+ - test/fixtures/mock_people.yml
224
+ - test/fixtures/stores.yml
225
+ - test/models/company.rb
226
+ - test/models/custom_location.rb
227
+ - test/models/location.rb
228
+ - test/models/mock_address.rb
229
+ - test/models/mock_family.rb
230
+ - test/models/mock_house.rb
231
+ - test/models/mock_organization.rb
232
+ - test/models/mock_person.rb
233
+ - test/models/store.rb
234
+ - test/schema.rb
235
+ - test/tasks.rake
236
+ - test/test_helper.rb