added geocoding

This commit is contained in:
2015-10-06 13:07:01 +02:00
parent e06cc82642
commit 43b6197ead
4 changed files with 15 additions and 1 deletions
+1
View File
@@ -37,6 +37,7 @@ gem 'simple_form'
gem 'capybara' gem 'capybara'
gem 'rails-i18n' gem 'rails-i18n'
gem 'puma' gem 'puma'
gem 'geocoder'
group :development, :test do group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console # Call 'byebug' anywhere in the code to stop execution and get a debugger console
+2
View File
@@ -66,6 +66,7 @@ GEM
diff-lcs (1.2.5) diff-lcs (1.2.5)
erubis (2.7.0) erubis (2.7.0)
execjs (2.6.0) execjs (2.6.0)
geocoder (1.2.11)
globalid (0.3.6) globalid (0.3.6)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
i18n (0.7.0) i18n (0.7.0)
@@ -217,6 +218,7 @@ DEPENDENCIES
byebug byebug
capybara capybara
coffee-rails (~> 4.1.0) coffee-rails (~> 4.1.0)
geocoder
jbuilder (~> 2.0) jbuilder (~> 2.0)
jquery-rails jquery-rails
mongoid (~> 5.0.0) mongoid (~> 5.0.0)
+9
View File
@@ -1,6 +1,10 @@
class Supporter class Supporter
include Mongoid::Document include Mongoid::Document
include Mongoid::Timestamps include Mongoid::Timestamps
include Geocoder::Model::Mongoid
geocoded_by :address
after_validation :geocode # auto-fetch coordinates
field :first_name, type: String field :first_name, type: String
field :last_name, type: String field :last_name, type: String
@@ -10,6 +14,7 @@ class Supporter
field :email, type: String field :email, type: String
field :support, type: String # Indicates the type of support field :support, type: String # Indicates the type of support
field :age_category, type: String field :age_category, type: String
field :coordinates, type: Array
validates :first_name, presence: true validates :first_name, presence: true
validates :last_name, presence: true validates :last_name, presence: true
@@ -19,4 +24,8 @@ class Supporter
validates :email, presence: true, uniqueness: true validates :email, presence: true, uniqueness: true
validates :support, presence: true validates :support, presence: true
validates :age_category, presence: true validates :age_category, presence: true
def address
"#{street}, #{zip}, #{city}, Switzerland"
end
end end
+3 -1
View File
@@ -9,7 +9,7 @@ feature 'Support announcement' do
fill_in 'Nachname', with: 'Blocher' fill_in 'Nachname', with: 'Blocher'
fill_in 'Strasse/Nr.', with: 'Wängirain 53' fill_in 'Strasse/Nr.', with: 'Wängirain 53'
fill_in 'Postleitzahl', with: '8704' fill_in 'Postleitzahl', with: '8704'
fill_in 'Ort', with: 'Hinterm Mond' fill_in 'Ort', with: 'Herrliberg'
fill_in 'E-Mail', with: 'blocher@blocher.ch' fill_in 'E-Mail', with: 'blocher@blocher.ch'
choose 'Ich unterschreibe eine Volksinitiative für die Freigabe von Cannabis und helfe aktiv Unterschriften in meiner Umgebung zu sammeln.' choose 'Ich unterschreibe eine Volksinitiative für die Freigabe von Cannabis und helfe aktiv Unterschriften in meiner Umgebung zu sammeln.'
@@ -17,6 +17,8 @@ feature 'Support announcement' do
choose 'Ich bin über 64 Jahre alt' choose 'Ich bin über 64 Jahre alt'
expect { click_button 'Unterstützung zusichern' }.to change { Supporter.count }.by(1) expect { click_button 'Unterstützung zusichern' }.to change { Supporter.count }.by(1)
expect(Supporter.find_by(email: 'blocher@blocher.ch').coordinates).to eq [8.618589100000001, 47.2926304]
end end
scenario 'A bot tries to enter data' do scenario 'A bot tries to enter data' do