added geocoding
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user