Skip to content

Commit

Permalink
add real geocoder
Browse files Browse the repository at this point in the history
  • Loading branch information
ajb committed Sep 27, 2013
1 parent 179ae7e commit a140bdc
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ source "https://rubygems.org"
# development dependencies will be added by default to the :development group.
gemspec

# Explicitly require carrierwave
# Explicitly require gems
gem 'carrierwave', require: 'carrierwave'
gem 'geocoder', require: 'geocoder'

# Bundle spring from github
gem 'spring', github: 'jonleighton/spring'
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ PATH
specs:
formbuilder (0.0.1)
carrierwave
geocoder
pg
rails (~> 4.0.0)
rmagick
Expand Down Expand Up @@ -72,6 +73,7 @@ GEM
railties (>= 3.0.0)
ffi (1.9.0)
formatador (0.2.4)
geocoder (1.1.8)
guard (1.8.3)
formatador (>= 0.2.4)
listen (~> 1.3)
Expand Down Expand Up @@ -189,6 +191,7 @@ DEPENDENCIES
coveralls
factory_girl_rails
formbuilder!
geocoder
guard-rspec
launchy
rspec-rails
Expand Down
9 changes: 4 additions & 5 deletions app/models/formbuilder/response_field_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ def render_entry(value, opts = {})

def audit_response(value, all_responses)
begin
# @todo add Geocoder
# coords = Geocoder.coordinates("#{value['street']} #{value['city']} " +
# "#{value['state']} #{value['zipcode']} #{value['country']}")
coords = Geocoder.coordinates("#{value['street']} #{value['city']} " +
"#{value['state']} #{value['zipcode']} #{value['country']}")

all_responses["#{self.id}_x"] = 'temp'#coords[0]
all_responses["#{self.id}_y"] = 'temp'#coords[1]
all_responses["#{self.id}_x"] = coords[0]
all_responses["#{self.id}_y"] = coords[1]
rescue
all_responses["#{self.id}_x"] = nil
all_responses["#{self.id}_y"] = nil
Expand Down
20 changes: 20 additions & 0 deletions formbuilder-rb.sublimeproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"folders":
[
{
"path": ".",
"folder_exclude_patterns": ["coverage", "log", "tmp"],
"file_exclude_patterns": ["*.sublime-workspace", "*.sql"]
}
],

"settings":
{
// indentation
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
// ensure line endings is linux style (even when on Windows)
"default_line_ending": "LF"
}
}
1 change: 1 addition & 0 deletions formbuilder.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Gem::Specification.new do |s|
s.add_dependency "rails", "~> 4.0.0"

s.add_dependency 'carrierwave'
s.add_dependency 'geocoder'
s.add_dependency 'pg'
s.add_dependency 'rmagick'

Expand Down
16 changes: 16 additions & 0 deletions spec/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,20 @@

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr

Geocoder.configure(:lookup => :test)

Geocoder::Lookup::Test.set_default_stub(
[
{
'latitude' => 40.7143528,
'longitude' => -74.0059731,
'address' => 'New York, NY, USA',
'state' => 'New York',
'state_code' => 'NY',
'country' => 'United States',
'country_code' => 'US'
}
]
)
end
2 changes: 1 addition & 1 deletion spec/lib/formbuilder/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def file_value
entry.save(validate: false)
entry.responses["#{first_response_field.id}_x"].should be_nil
entry.submit!(true)
entry.responses["#{first_response_field.id}_x"].should == 'temp' # @todo geocoder
entry.responses["#{first_response_field.id}_x"].should == Geocoder::Lookup::Test.read_stub(nil)[0]['latitude']
end
end

Expand Down

0 comments on commit a140bdc

Please sign in to comment.