Automat mail chimp subscription
This commit is contained in:
@@ -40,6 +40,7 @@ gem 'puma'
|
||||
gem 'geocoder'
|
||||
gem 'rails_12factor'
|
||||
|
||||
|
||||
gem 'rails_admin'
|
||||
|
||||
gem 'mongoid_paranoia'
|
||||
@@ -53,6 +54,7 @@ group :development, :test do
|
||||
gem 'rspec-rails', '~> 3.0'
|
||||
|
||||
gem 'pry-rails'
|
||||
gem 'dotenv-rails'
|
||||
end
|
||||
|
||||
group :development do
|
||||
|
||||
@@ -66,6 +66,10 @@ GEM
|
||||
concurrent-ruby (1.0.2)
|
||||
debug_inspector (0.0.2)
|
||||
diff-lcs (1.2.5)
|
||||
dotenv (2.1.1)
|
||||
dotenv-rails (2.1.1)
|
||||
dotenv (= 2.1.1)
|
||||
railties (>= 4.0, < 5.1)
|
||||
erubis (2.7.0)
|
||||
excon (0.49.0)
|
||||
execjs (2.7.0)
|
||||
@@ -266,6 +270,7 @@ DEPENDENCIES
|
||||
byebug
|
||||
capybara
|
||||
coffee-rails (~> 4.1.0)
|
||||
dotenv-rails
|
||||
geocoder
|
||||
jbuilder (~> 2.0)
|
||||
jquery-rails
|
||||
|
||||
@@ -9,6 +9,7 @@ class SupportersController < ApplicationController
|
||||
@supporter = Supporter.new supporter_form_params.merge(language: I18n.locale)
|
||||
if !input_to_fast? && @supporter.save
|
||||
# SupporterMailer.welcome_email(@supporter).deliver_now
|
||||
mailchimp_registration
|
||||
redirect_to thanks_path
|
||||
else
|
||||
flash.now[:danger] = t '.timeout' if input_to_fast?
|
||||
@@ -21,4 +22,20 @@ class SupportersController < ApplicationController
|
||||
def supporter_form_params
|
||||
params.require(:supporter).permit(:first_name, :last_name, :street, :zip, :email, :support, :li_membership, :age_category, :city, :comments)
|
||||
end
|
||||
|
||||
def mailchimp_registration
|
||||
mailchimp = Mailchimp::API.new(ENV['MAILCHIMP_API'])
|
||||
mailchimp.lists.subscribe(ENV['CH420_LIST_ID'], { 'email' => @supporter.email }, merge_vars, 'html', false)
|
||||
end
|
||||
|
||||
def merge_vars
|
||||
{ 'EMAIL' => @supporter.email,
|
||||
'FNAME' => @supporter.first_name,
|
||||
'LNAME' => @supporter.last_name,
|
||||
'SUPPORT' => @supporter.support,
|
||||
'MEMBERSHIP' => @supporter.li_membership.to_s,
|
||||
'AGE' => @supporter.age_category,
|
||||
'LANG' => @supporter.language,
|
||||
'ZIP' => @supporter.zip }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ class Supporter
|
||||
include Mongoid::Paranoia
|
||||
include Geocoder::Model::Mongoid
|
||||
|
||||
COUNTER_START = 10003
|
||||
COUNTER_START = 10_003
|
||||
|
||||
geocoded_by :address
|
||||
after_validation :geocode # auto-fetch coordinates
|
||||
|
||||
@@ -21,9 +21,10 @@ feature 'Support announcement' do
|
||||
sleep 5 # Do a real sleep to have a real integration test
|
||||
|
||||
expect(ActionMailer::Base.deliveries.count).to eq 0
|
||||
expect_any_instance_of(SupportersController).to receive(:mailchimp_registration).and_return(true)
|
||||
|
||||
expect { click_button 'Unterstützung zusichern' }.to change { Supporter.count }.by(1)
|
||||
# expect(ActionMailer::Base.deliveries.count).to eq 1
|
||||
|
||||
supporter = Supporter.find_by(email: 'blocher@blocher.ch')
|
||||
expect(supporter.coordinates).to eq [8.618589100000001, 47.2926304]
|
||||
expect(supporter.comments).to eq 'Test text'
|
||||
|
||||
Reference in New Issue
Block a user