Merge branch 'master' into features/publicity

# Conflicts:
#	.gitignore
This commit is contained in:
2017-04-18 16:22:36 +02:00
13 changed files with 11 additions and 81 deletions
-2
View File
@@ -78,8 +78,6 @@ gem 'rails_admin'
gem 'mongoid_paranoia'
gem 'mailchimp-api', require: 'mailchimp'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
-5
View File
@@ -103,7 +103,6 @@ GEM
dotenv (= 2.2.0)
railties (>= 3.2, < 5.1)
erubis (2.7.0)
excon (0.55.0)
execjs (2.7.0)
factory_girl (4.8.0)
activesupport (>= 3.0.0)
@@ -145,9 +144,6 @@ GEM
nokogiri (>= 1.5.9)
mail (2.6.4)
mime-types (>= 1.16, < 4)
mailchimp-api (2.0.6)
excon (>= 0.16.0)
json (>= 1.7.7)
memory_profiler (0.9.8)
method_source (0.8.2)
mime-types (3.1)
@@ -353,7 +349,6 @@ DEPENDENCIES
jquery-rails
kaminari-actionview
kaminari-mongoid
mailchimp-api
mongoid (~> 5.0.0)
mongoid-paperclip
mongoid-rspec (= 3.0.0)
+1 -1
View File
@@ -36,6 +36,6 @@ class ApplicationController < ActionController::Base
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name, :street, :city, :zip, :support, :language, :age_category, :unsubscribed])
devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name, :street, :city, :zip, :support, :language, :age_category])
end
end
+7 -16
View File
@@ -10,7 +10,7 @@ class SupportersController < ApplicationController
@supporter.password = random_password = SecureRandom.hex(5)
if !input_to_fast? && @supporter.save
SupporterMailer.welcome_email(@supporter, random_password).deliver_now
mailchimp_registration
sendy_registraion
redirect_to thanks_path
else
flash.now[:danger] = input_to_fast? ? t('.timeout') : t('input_error')
@@ -24,20 +24,11 @@ class SupportersController < ApplicationController
params.require(:supporter).permit(:first_name, :last_name, :street, :zip, :email, :support, :li_membership, :age_category, :city, :comments)
end
def mailchimp_registration
return unless Rails.env.production?
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 }
# We use sendy for newsletters atm
def sendy_registraion
uri = URI('http://newsletter.cannabis-initiative.ch/subscribe')
Net::HTTP.post_form(uri, list: ENV["SENDY_LIST_#{I18n.locale.upcase}"],
email: @supporter.email,
name: "#{@supporter.first_name} #{@supporter.last_name}")
end
end
-1
View File
@@ -44,7 +44,6 @@ class Supporter
field :coordinates, type: Array
field :comments, type: String
field :language, type: String
field :unsubscribed, type: Boolean, default: false
field :duplicate, type: Boolean, default: false
validates :first_name, presence: true
-2
View File
@@ -23,8 +23,6 @@
dd == t("age_category.#{current_supporter.age_category}")
dt = Supporter.human_attribute_name(:language)
dd = t("languages.#{current_supporter.language}")
dt = Supporter.human_attribute_name(:unsubscribed)
dd = current_supporter.unsubscribed? ? t('shared.yes') : t('shared.no')
p
= link_to t('.edit'), edit_supporter_registration_path(), class: 'pull-right'
@@ -19,7 +19,6 @@
= f.input :support, as: :radio_buttons, collection: t('support_type').map{ |x| [x.first, raw(x.last)]}, label_method: :last, value_method: :first
= f.input :age_category, as: :radio_buttons, collection: t('age_category'), label_method: :last, value_method: :first
= f.input :language, as: :radio_buttons, collection: t('languages').map{ |x| [x.first, raw(x.last)]}, label_method: :last, value_method: :first
= f.input :unsubscribed, as: :boolean
.form-actions
= f.button :submit, t("devise.registrations.edit.update"), class: 'btn btn-primary'
p = link_to t("devise.shared.links.back"), :back
+2 -2
View File
@@ -74,8 +74,8 @@ Rails.application.configure do
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
config.action_mailer.default_url_options = { host: 'ch420.herokuapp.com' }
config.action_mailer.asset_host = 'https://ch420.herokuapp.com'
config.action_mailer.default_url_options = { host: 'www.cannabis-initiative.ch' }
config.action_mailer.asset_host = 'https://www.cannabis-initiative.ch'
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
-1
View File
@@ -131,7 +131,6 @@ de:
remember_me: Angemeldet bleiben
password: Passwort
language: Sprache
unsubscribed: Kein Newsletter
password_confirmation: Passwort bestätigen
current_password: Aktuelles Passwort
publicity:
-1
View File
@@ -127,7 +127,6 @@ fr:
remember_me: Se souvenir de moi
password: mot de passe
language: Langue
unsubscribed: pas de newslettre
password_confirmation: confirmer le mot de passe
current_password: Mot de passe actuel
-1
View File
@@ -128,7 +128,6 @@ it:
remember_me: Ricordati di mel
password: Password
language: Lingua
unsubscribed: No Newsletter
password_confirmation: conferma password
current_password: Password corrente
publicity:
-47
View File
@@ -1,47 +0,0 @@
class MailChimpBatchUpdate
def initialize(api_key, list_id)
@mailchimp = Mailchimp::API.new(api_key)
@list_id = list_id
end
def update_all
subscribers = []
Supporter.each_with_index do |supporter, index|
subscribers.push(subscriber(supporter))
if index.modulo(20).zero?
batch_subscribe(subscribers)
subscribers = []
end
end
batch_subscribe(subscribers)
end
def batch_subscribe(subscribers)
@mailchimp.lists.batch_subscribe(@list_id, subscribers, false, true, false)
end
def subscriber(supporter)
{ 'EMAIL' => { 'email' => supporter.email }, 'language' => supporter.language, :EMAIL_TYPE => 'html',
: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
def update_unsubscibed
unsubscribed_members = @mailchimp.lists.members(@list_id, 'unsubscribed', limit: 100)
unsubscribed_members['data'].each do |member|
Supporter.where(email: member['email']).each do |supporter|
supporter.update_attributes unsubscribed: true
end
end
end
end
+1 -1
View File
@@ -21,7 +21,7 @@ feature 'Support' 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_any_instance_of(SupportersController).to receive(:sendy_registraion).and_return(true)
expect { click_button 'Unterstützung zusichern' }.to change { Supporter.count }.by(1)
# expect(ActionMailer::Base.deliveries.count).to eq 1