added mailer

This commit is contained in:
2016-04-08 15:22:31 +02:00
parent 7aacbe8d56
commit 8103f7b439
11 changed files with 71 additions and 0 deletions
+1
View File
@@ -8,6 +8,7 @@ class SupportersController < ApplicationController
def create def create
@supporter = Supporter.new supporter_form_params.merge(language: I18n.locale) @supporter = Supporter.new supporter_form_params.merge(language: I18n.locale)
if !input_to_fast? && @supporter.save if !input_to_fast? && @supporter.save
SupporterMailer.welcome_email(@supporter).deliver_now
redirect_to thanks_path redirect_to thanks_path
else else
flash.now[:danger] = t '.timeout' if input_to_fast? flash.now[:danger] = t '.timeout' if input_to_fast?
+4
View File
@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: 'markus@hanflegal.ch'
layout 'mailer'
end
+6
View File
@@ -0,0 +1,6 @@
class SupporterMailer < ApplicationMailer
def welcome_email(supporter)
@supporter = supporter
mail(to: @supporter.email, subject: I18n.t('welcome_email.subject'))
end
end
+6
View File
@@ -0,0 +1,6 @@
doctype html
html
head
meta content=("text/html; charset=UTF-8") http-equiv="Content-Type" /
body style='padding: 20px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;'
= yield
@@ -0,0 +1,20 @@
p
strong Hallo #{@supporter.first_name},
p Du bist nun ein Teil der Bewegung!
p Wir informieren dich per E-Mail über die nächsten Schritte und kommen aktiv auf dich zu. Auf <a href="https://www.hanflegal.ch/initiative">https://www.hanflegal.ch/initiative</a> informieren wir über laufende Aktivitäten.
p
b Was kannst du machen?
p
ul
li Folge uns auf Facebook <a href="https://www.facebook.com/vereinlegalizeit">Facebook</a> und <a href="https://twitter.com/VereinLegalize">Twitter</a>
li Teile unser Projekt in den sozialen Medien mit dem Hashtag #ch420
li Erzähle allen von unserem Vorhaben und bitte Sie mitzumachen
li Werde Mitglied beim <a href="https://www.hanflegal.ch">Verein Legalize it!</a>
p
| Hanfige Grüsse,
em die Initianten
+5
View File
@@ -35,4 +35,9 @@ Rails.application.configure do
# Raises error for missing translations # Raises error for missing translations
# config.action_view.raise_on_missing_translations = true # config.action_view.raise_on_missing_translations = true
config.action_mailer.default_url_options = { host: 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { address: 'localhost', port: 1025 }
end end
+13
View File
@@ -73,4 +73,17 @@ Rails.application.configure do
# Use default logging formatter so that PID and timestamp are not suppressed. # Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new config.log_formatter = ::Logger::Formatter.new
config.action_mailer.default_url_options = { host: 'ch420.herokuapp.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
port: '587',
address: ENV['SMTP_HOST'],
user_name: ENV['SMTP_USER'],
password: ENV['SMTP_PASSWORD'],
domain: 'hanflegal.ch',
authentication: :plain,
enable_starttls_auto: true
}
end end
+3
View File
@@ -1,4 +1,7 @@
de: de:
welcome_email:
subject: Besten dank für deine Unterstützung!
support_type: support_type:
signer: Ich unterschreibe eine Volksinitiative für die <span class="text-success">Legalisierung von Cannabis</span>. signer: Ich unterschreibe eine Volksinitiative für die <span class="text-success">Legalisierung von Cannabis</span>.
supporter: Ich unterschreibe eine Volksinitiative für die <span class="text-success">Legalisierung von Cannabis</span> und helfe aktiv Unterschriften in meiner Umgebung zu sammeln. supporter: Ich unterschreibe eine Volksinitiative für die <span class="text-success">Legalisierung von Cannabis</span> und helfe aktiv Unterschriften in meiner Umgebung zu sammeln.
+3
View File
@@ -20,7 +20,10 @@ feature 'Support announcement' do
sleep 5 # Do a real sleep to have a real integration test sleep 5 # Do a real sleep to have a real integration test
expect(ActionMailer::Base.deliveries.count).to eq 0
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(ActionMailer::Base.deliveries.count).to eq 1
supporter = Supporter.find_by(email: 'blocher@blocher.ch') supporter = Supporter.find_by(email: 'blocher@blocher.ch')
expect(supporter.coordinates).to eq [8.618589100000001, 47.2926304] expect(supporter.coordinates).to eq [8.618589100000001, 47.2926304]
expect(supporter.comments).to eq 'Test text' expect(supporter.comments).to eq 'Test text'
@@ -0,0 +1,6 @@
# Preview all emails at http://localhost:3000/rails/mailers/supporter_mailer
class SupporterMailerPreview < ActionMailer::Preview
def welcome
SupporterMailer.welcome_email(Supporter.first)
end
end
+4
View File
@@ -44,4 +44,8 @@ RSpec.configure do |config|
config.after(:each) do config.after(:each) do
Mongoid.purge! Mongoid.purge!
end end
config.before(:each) do
ActionMailer::Base.deliveries.clear
end
end end