aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXinhui2017-07-07 12:23:12 +0200
committerXinhui2017-07-07 12:43:24 +0200
commit72c90c1b3da9b09319a435bd549ba3b5070df31a (patch)
tree8fc64e34a34c535439abfe04437e5510a3cd8336
parent8d8c76aca3ab4a4cda2de7d9d2d80dc98949ed0e (diff)
downloadchouette-core-72c90c1b3da9b09319a435bd549ba3b5070df31a.tar.bz2
Add CalendarMailer
-rw-r--r--app/mailers/application_mailer.rb3
-rw-r--r--app/mailers/calendar_mailer.rb15
-rw-r--r--app/views/calendar_mailer/created.html.slim2
-rw-r--r--app/views/calendar_mailer/updated.html.slim2
-rw-r--r--app/views/layouts/mailer.html.slim6
-rw-r--r--app/views/layouts/mailer.text.slim1
-rw-r--r--config/locales/mailers.en.yml9
-rw-r--r--config/locales/mailers.fr.yml9
-rw-r--r--spec/mailers/calendar_mailer_spec.rb35
-rw-r--r--spec/mailers/previews/calendar_mailer_preview.rb4
10 files changed, 83 insertions, 3 deletions
diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb
new file mode 100644
index 000000000..d8bd387b5
--- /dev/null
+++ b/app/mailers/application_mailer.rb
@@ -0,0 +1,3 @@
+class ApplicationMailer < ActionMailer::Base
+ layout 'mailer'
+end
diff --git a/app/mailers/calendar_mailer.rb b/app/mailers/calendar_mailer.rb
new file mode 100644
index 000000000..f9189371e
--- /dev/null
+++ b/app/mailers/calendar_mailer.rb
@@ -0,0 +1,15 @@
+class CalendarMailer < ApplicationMailer
+ def updated calendar
+ users = User.all
+ users.each do |u|
+ mail to: u.email, subject: t('mailers.calendar_mailer.updated.subject')
+ end
+ end
+
+ def created calendar
+ users = User.all
+ users.each do |u|
+ mail to: u.email, subject: t('mailers.calendar_mailer.created.subject')
+ end
+ end
+end
diff --git a/app/views/calendar_mailer/created.html.slim b/app/views/calendar_mailer/created.html.slim
new file mode 100644
index 000000000..621796d34
--- /dev/null
+++ b/app/views/calendar_mailer/created.html.slim
@@ -0,0 +1,2 @@
+div = t('mailers.calendar_mailer.created.body')
+
diff --git a/app/views/calendar_mailer/updated.html.slim b/app/views/calendar_mailer/updated.html.slim
new file mode 100644
index 000000000..7f6deda07
--- /dev/null
+++ b/app/views/calendar_mailer/updated.html.slim
@@ -0,0 +1,2 @@
+div = t('mailers.calendar_mailer.updated.body')
+
diff --git a/app/views/layouts/mailer.html.slim b/app/views/layouts/mailer.html.slim
index 2ea993105..1485e8188 100644
--- a/app/views/layouts/mailer.html.slim
+++ b/app/views/layouts/mailer.html.slim
@@ -3,7 +3,7 @@ html
head
meta charset="utf-8"
title= message.subject
-
+
body style="font-family: Verdana, Helvetica, Arial, MS Trebuchet, sans-serif; font-size: 14px; width: 600px; background: #E5E5E5; padding: 15px"
<style>
@@ -14,9 +14,9 @@ html
h1 style="background: #61970B; height: 75px; font-size: 24px; font-weight: normal; color: white; padding: 20px 0 0 30px;"
|Chouette
-
+
div style="background: white; margin-bottom: 10px; padding: 15px; -moz-box-shadow: 3px 3px 4px #bbbbbb; -webkit-box-shadow: 3px 3px 4px #BBB; box-shadow: 3px 3px 4px #BBB; border-right: 1px solid #BBB; border-bottom: 1px solid #BBB;"
= yield
div style="color: #333333; text-align:center; font-size: 10px;"
- = "Envoyé par #{link_to 'Chouette', unauthenticated_root_url}" \ No newline at end of file
+ = "Envoyé par #{link_to 'Chouette', unauthenticated_root_url}"
diff --git a/app/views/layouts/mailer.text.slim b/app/views/layouts/mailer.text.slim
new file mode 100644
index 000000000..0a90f092c
--- /dev/null
+++ b/app/views/layouts/mailer.text.slim
@@ -0,0 +1 @@
+= yield
diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml
new file mode 100644
index 000000000..72fd0d725
--- /dev/null
+++ b/config/locales/mailers.en.yml
@@ -0,0 +1,9 @@
+en:
+ mailers:
+ calendar_mailer:
+ created:
+ subject: A new shared calendar has been created
+ body: body created
+ created:
+ subject: A shared calendar has been updated
+ body: body updated
diff --git a/config/locales/mailers.fr.yml b/config/locales/mailers.fr.yml
new file mode 100644
index 000000000..8c399b6e0
--- /dev/null
+++ b/config/locales/mailers.fr.yml
@@ -0,0 +1,9 @@
+fr:
+ mailers:
+ calendar_mailer:
+ created:
+ subject: Un nouveau calendrier partagé à été ajouté
+ body: body created
+ updated:
+ subject: Un nouveau calendrier partagé à été mise à jour
+ body: body updated
diff --git a/spec/mailers/calendar_mailer_spec.rb b/spec/mailers/calendar_mailer_spec.rb
new file mode 100644
index 000000000..75241b063
--- /dev/null
+++ b/spec/mailers/calendar_mailer_spec.rb
@@ -0,0 +1,35 @@
+require "rails_helper"
+
+RSpec.describe CalendarMailer, type: :mailer do
+
+ shared_examples 'notify all user' do |type|
+ let!(:user) { create(:user) }
+ let(:calendar) { create(:calendar, shared: true) }
+ let(:email) { CalendarMailer.send(type, calendar) }
+
+ it 'should deliver email to user' do
+ expect(email).to deliver_to user.email
+ end
+
+ it 'should have correct from' do
+ expect(email.from).to eq(['stif-boiv@af83.com'])
+ end
+
+ it 'should have subject' do
+ expect(email).to have_subject I18n.t("mailers.calendar_mailer.#{type}.subject")
+ end
+
+ it 'should have correct body' do
+ key = I18n.t("mailers.calendar_mailer.#{type}.body")
+ expect(email).to have_body_text /#{key}/
+ end
+ end
+
+ describe 'updated' do
+ it_behaves_like 'notify all user', 'updated'
+ end
+
+ describe 'created' do
+ it_behaves_like 'notify all user', 'created'
+ end
+end
diff --git a/spec/mailers/previews/calendar_mailer_preview.rb b/spec/mailers/previews/calendar_mailer_preview.rb
new file mode 100644
index 000000000..572c6c667
--- /dev/null
+++ b/spec/mailers/previews/calendar_mailer_preview.rb
@@ -0,0 +1,4 @@
+# Preview all emails at http://localhost:3000/rails/mailers/calendar_mailer
+class CalendarMailerPreview < ActionMailer::Preview
+
+end