Add contact form notification
This commit is contained in:
@@ -2,6 +2,7 @@ class ContactFormsController < ApplicationController
|
|||||||
def create
|
def create
|
||||||
@contact_form = Cmtool::ContactForm.new(contact_form_params)
|
@contact_form = Cmtool::ContactForm.new(contact_form_params)
|
||||||
if @contact_form.save
|
if @contact_form.save
|
||||||
|
Notifier.contact_form(@contact_form.id).deliver
|
||||||
redirect_to root_path, notice: t('contact_form.submitted')
|
redirect_to root_path, notice: t('contact_form.submitted')
|
||||||
else
|
else
|
||||||
redirect_to go_to_path('contact', locale: I18n.locale), alert: @contact_form.errors.full_messages.join(', ')
|
redirect_to go_to_path('contact', locale: I18n.locale), alert: @contact_form.errors.full_messages.join(', ')
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
class Notifier < ActionMailer::Base
|
||||||
|
default from: "Qwaiter <service@mozo.bar>"
|
||||||
|
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
|
||||||
@@ -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
|
||||||
@@ -2,4 +2,9 @@ Feature: Submitting contact form
|
|||||||
Scenario: Website visitor submits contact form
|
Scenario: Website visitor submits contact form
|
||||||
Given there are standard website pages
|
Given there are standard website pages
|
||||||
When I visit '/contact'
|
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
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,30 @@
|
|||||||
step "there are standard website pages" do
|
step "there are standard website pages" do
|
||||||
create_site_pages
|
create_site_pages
|
||||||
end
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user