From 9e9a7323846aa047df4519666f88fddf14c519a2 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Thu, 26 Feb 2015 05:22:36 +0100 Subject: [PATCH] Add contact form notification --- app/controllers/contact_forms_controller.rb | 1 + app/mailers/notifier.rb | 10 +++++++ app/views/notifier/contact_form.html.slim | 10 +++++++ spec/acceptance/website/contact_form.feature | 5 ++++ spec/acceptance_steps/global_website_steps.rb | 27 +++++++++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 app/mailers/notifier.rb create mode 100644 app/views/notifier/contact_form.html.slim diff --git a/app/controllers/contact_forms_controller.rb b/app/controllers/contact_forms_controller.rb index 35395a67..484283c4 100644 --- a/app/controllers/contact_forms_controller.rb +++ b/app/controllers/contact_forms_controller.rb @@ -2,6 +2,7 @@ class ContactFormsController < ApplicationController def create @contact_form = Cmtool::ContactForm.new(contact_form_params) if @contact_form.save + Notifier.contact_form(@contact_form.id).deliver redirect_to root_path, notice: t('contact_form.submitted') else redirect_to go_to_path('contact', locale: I18n.locale), alert: @contact_form.errors.full_messages.join(', ') diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb new file mode 100644 index 00000000..8b85f573 --- /dev/null +++ b/app/mailers/notifier.rb @@ -0,0 +1,10 @@ +class Notifier < ActionMailer::Base + default from: "Qwaiter " + layout 'mail' + + def contact_form(contact_form_id) + @contact_form = Cmtool::ContactForm.find(contact_form_id) + I18n.locale = :en + mail to: "contact-form@mozo.bar", subject: "[CONTACTFORM] new entry" + end +end diff --git a/app/views/notifier/contact_form.html.slim b/app/views/notifier/contact_form.html.slim new file mode 100644 index 00000000..9b279247 --- /dev/null +++ b/app/views/notifier/contact_form.html.slim @@ -0,0 +1,10 @@ +h2 New contact form entry +dl + dt Name + dd= @contact_form.name + dt Gender + dd= @contact_form.gender + dt E-mail + dd= @contact_form.email + +pre= @contact_form.body diff --git a/spec/acceptance/website/contact_form.feature b/spec/acceptance/website/contact_form.feature index 58d639cf..860d9514 100644 --- a/spec/acceptance/website/contact_form.feature +++ b/spec/acceptance/website/contact_form.feature @@ -2,4 +2,9 @@ Feature: Submitting contact form Scenario: Website visitor submits contact form Given there are standard website pages When I visit '/contact' + And I fill in the website contact form + And I submit the website contact form + Then I should be redirected to the homepage + And a contact form object should be created having the proper data + And an email should be sent containing the contact form body diff --git a/spec/acceptance_steps/global_website_steps.rb b/spec/acceptance_steps/global_website_steps.rb index 2d7c8ff6..269d130b 100644 --- a/spec/acceptance_steps/global_website_steps.rb +++ b/spec/acceptance_steps/global_website_steps.rb @@ -1,3 +1,30 @@ step "there are standard website pages" do create_site_pages end + +step "I fill in the website contact form" do + find('#contact_form_name').set "Benji" + find('#contact_form_body').set "Awesome website!" + find('#contact_form_email').set "benji@mozo.bar" +end + +step "I submit the website contact form" do + find('[type="submit"]').click +end + +step "I should be redirected to the homepage" do + page.current_path.should eq '/' +end + +step "a contact form object should be created having the proper data" do + cf = Cmtool::ContactForm.last + cf.name.should eq 'Benji' + cf.body.should eq "Awesome website!" + cf.email.should eq "benji@mozo.bar" +end + +step "an email should be sent containing the contact form body" do + mail = ActionMailer::Base.deliveries.last + mail.should be_present + mail.body.should include "Awesome website!" +end