diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index c1d6835..09ddaaf 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,5 @@ class ApplicationMailer < ActionMailer::Base default from: "info@hubfeenix.fi" , bcc: "info@hubfeenix.fi" layout "mailer" + end diff --git a/app/mailers/form_mailer.rb b/app/mailers/form_mailer.rb index 7309647..f29784c 100644 --- a/app/mailers/form_mailer.rb +++ b/app/mailers/form_mailer.rb @@ -1,7 +1,7 @@ class FormMailer < ApplicationMailer default from: "info@hubfeenix.fi" , bcc: "info@hubfeenix.fi" - def received(data) + def received(data ) @data = data mail(to: data['Email'] , subject: "We have received your request") end diff --git a/app/mailers/news_mailer.rb b/app/mailers/news_mailer.rb new file mode 100644 index 0000000..bf56b73 --- /dev/null +++ b/app/mailers/news_mailer.rb @@ -0,0 +1,22 @@ +class NewsMailer < ApplicationMailer + helper Merged::ViewHelper + + def letter + @page = Merged::Page.find_by_type("blog") + + mail( to: "to@example.org" ) + end + + def subscribed + @greeting = "Hi" + + mail to: "to@example.org" + end + + def unsubscribed + @greeting = "Hi" + + mail to: "to@example.org" + end + +end diff --git a/app/views/layouts/mailer.html.haml b/app/views/layouts/mailer.html.haml index cbf6b8e..9c7ce62 100644 --- a/app/views/layouts/mailer.html.haml +++ b/app/views/layouts/mailer.html.haml @@ -2,7 +2,6 @@ %html %head %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/ - :css - /* Email styles need to be inline */ - %body + = stylesheet_link_tag "tailwind" + %body.wide = yield diff --git a/app/views/news_mailer/letter.html.haml b/app/views/news_mailer/letter.html.haml new file mode 100644 index 0000000..2a9b793 --- /dev/null +++ b/app/views/news_mailer/letter.html.haml @@ -0,0 +1,2 @@ +- @page.sections.each do |section| + = render_section( section ) diff --git a/app/views/news_mailer/letter.text.haml b/app/views/news_mailer/letter.text.haml new file mode 100644 index 0000000..e69de29 diff --git a/app/views/news_mailer/subscribed.html.haml b/app/views/news_mailer/subscribed.html.haml new file mode 100644 index 0000000..d6689f2 --- /dev/null +++ b/app/views/news_mailer/subscribed.html.haml @@ -0,0 +1,4 @@ +%h1= class_name + "#" + @action + +%p + = @greeting + ", find me in app/views/news_mailer/subscribed.html.haml" diff --git a/app/views/news_mailer/subscribed.text.haml b/app/views/news_mailer/subscribed.text.haml new file mode 100644 index 0000000..e749bf3 --- /dev/null +++ b/app/views/news_mailer/subscribed.text.haml @@ -0,0 +1,3 @@ +News#subscribed + += @greeting + ", find me in app/views/news_mailer/subscribed.text.haml" diff --git a/app/views/news_mailer/unsubscribed.html.haml b/app/views/news_mailer/unsubscribed.html.haml new file mode 100644 index 0000000..2076554 --- /dev/null +++ b/app/views/news_mailer/unsubscribed.html.haml @@ -0,0 +1,4 @@ +%h1= class_name + "#" + @action + +%p + = @greeting + ", find me in app/views/news_mailer/unsubscribed.html.haml" diff --git a/app/views/news_mailer/unsubscribed.text.haml b/app/views/news_mailer/unsubscribed.text.haml new file mode 100644 index 0000000..36b6bfe --- /dev/null +++ b/app/views/news_mailer/unsubscribed.text.haml @@ -0,0 +1,3 @@ +News#unsubscribed + += @greeting + ", find me in app/views/news_mailer/unsubscribed.text.haml" diff --git a/test/mailers/news_mailer_test.rb b/test/mailers/news_mailer_test.rb new file mode 100644 index 0000000..db10de1 --- /dev/null +++ b/test/mailers/news_mailer_test.rb @@ -0,0 +1,28 @@ +require "test_helper" + +class NewsMailerTest < ActionMailer::TestCase + test "letter" do + mail = NewsMailer.letter + assert_equal "Letter", mail.subject + assert_equal ["to@example.org"], mail.to + assert_equal ["from@example.com"], mail.from + assert_match "Hi", mail.body.encoded + end + + test "subscribed" do + mail = NewsMailer.subscribed + assert_equal "Subscribed", mail.subject + assert_equal ["to@example.org"], mail.to + assert_equal ["from@example.com"], mail.from + assert_match "Hi", mail.body.encoded + end + + test "unsubscribed" do + mail = NewsMailer.unsubscribed + assert_equal "Unsubscribed", mail.subject + assert_equal ["to@example.org"], mail.to + assert_equal ["from@example.com"], mail.from + assert_match "Hi", mail.body.encoded + end + +end diff --git a/test/mailers/previews/form_mailer_preview.rb b/test/mailers/previews/form_mailer_preview.rb index b8ddd32..c7f9e98 100644 --- a/test/mailers/previews/form_mailer_preview.rb +++ b/test/mailers/previews/form_mailer_preview.rb @@ -3,7 +3,7 @@ class FormMailerPreview < ActionMailer::Preview # Preview this email at http://localhost:3000/rails/mailers/form_mailer/received def received - FormMailer.received + FormMailer.received name: "Me" , email: "You" end end diff --git a/test/mailers/previews/news_mailer_preview.rb b/test/mailers/previews/news_mailer_preview.rb new file mode 100644 index 0000000..8ffd27f --- /dev/null +++ b/test/mailers/previews/news_mailer_preview.rb @@ -0,0 +1,7 @@ +class NewsMailerPreview < ActionMailer::Preview + + def letter + NewsMailer.letter + end + +end