From a0169110f90726ef03fdd6fd5e58718eff0b26d1 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Wed, 26 Mar 2014 16:28:59 +0000 Subject: Tidy HelpControllerSpec --- spec/controllers/help_controller_spec.rb | 70 +++++++++++++++++++------------- 1 file changed, 41 insertions(+), 29 deletions(-) (limited to 'spec/controllers/help_controller_spec.rb') diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb index cc024f840..d552127ba 100644 --- a/spec/controllers/help_controller_spec.rb +++ b/spec/controllers/help_controller_spec.rb @@ -1,48 +1,60 @@ # -*- coding: utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') -describe HelpController, "when using help" do +describe HelpController do render_views - it "shows the about page" do - get :about - end + describe :about do - it "shows contact form" do - get :contact - end + it 'shows the about page' do + get :about + end - it "sends a contact message" do - post :contact, { :contact => { - :name => "Vinny Vanilli", - :email => "vinny@localhost", - :subject => "Why do I have such an ace name?", - :message => "You really should know!!!\n\nVinny", - }, :submitted_contact_form => 1 - } - response.should redirect_to(:controller => 'general', :action => 'frontpage') - - deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 1 - deliveries[0].body.should include("really should know") - deliveries.clear end - describe 'when requesting a page in a supported locale ' do + describe 'GET contact' do - before do - # Prepend our fixture templates - fixture_theme_path = File.join(Rails.root, 'spec', 'fixtures', 'theme_views', 'theme_one') - controller.prepend_view_path fixture_theme_path + it 'shows contact form' do + get :contact end - it 'should render the locale-specific template if available' do - get :contact, {:locale => 'es'} - response.body.should match('contáctenos theme one') + describe 'when requesting a page in a supported locale' do + + before do + # Prepend our fixture templates + fixture_theme_path = File.join(Rails.root, 'spec', 'fixtures', 'theme_views', 'theme_one') + controller.prepend_view_path fixture_theme_path + end + + it 'should render the locale-specific template if available' do + get :contact, {:locale => 'es'} + response.body.should match('contáctenos theme one') + end + end end + describe 'POST contact' do + + it 'sends a contact message' do + post :contact, { :contact => { + :name => 'Vinny Vanilli', + :email => 'vinny@localhost', + :subject => 'Why do I have such an ace name?', + :comment => '', + :message => "You really should know!!!\n\nVinny", + }, :submitted_contact_form => 1 + } + response.should redirect_to(:controller => 'general', :action => 'frontpage') + + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + deliveries[0].body.should include('really should know') + deliveries.clear + end + + end end -- cgit v1.2.3 From b2acdc723ab7f56ca71f19ddcb571468dd5159ef Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Wed, 26 Mar 2014 16:54:37 +0000 Subject: Improve HelpControllerSpec - Actually assert something when getting the pages - Use named route --- spec/controllers/help_controller_spec.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'spec/controllers/help_controller_spec.rb') diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb index d552127ba..8ac10e244 100644 --- a/spec/controllers/help_controller_spec.rb +++ b/spec/controllers/help_controller_spec.rb @@ -8,6 +8,8 @@ describe HelpController do it 'shows the about page' do get :about + response.should be_success + response.should render_template('help/about') end end @@ -16,6 +18,8 @@ describe HelpController do it 'shows contact form' do get :contact + response.should be_success + response.should render_template('help/contact') end describe 'when requesting a page in a supported locale' do @@ -46,7 +50,7 @@ describe HelpController do :message => "You really should know!!!\n\nVinny", }, :submitted_contact_form => 1 } - response.should redirect_to(:controller => 'general', :action => 'frontpage') + response.should redirect_to(frontpage_path) deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 -- cgit v1.2.3 From 5d6d21f690e283682b9be74a8f00c501b148856f Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Wed, 26 Mar 2014 17:00:20 +0000 Subject: Add honeypot spam protection to contact form Intercepts the request and redirects to the homepage if the comment field is filled in on the contact form. --- spec/controllers/help_controller_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'spec/controllers/help_controller_spec.rb') diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb index 8ac10e244..f92323f50 100644 --- a/spec/controllers/help_controller_spec.rb +++ b/spec/controllers/help_controller_spec.rb @@ -58,6 +58,23 @@ describe HelpController do deliveries.clear end + it 'has rudimentary spam protection' do + post :contact, { :contact => { + :name => 'Vinny Vanilli', + :email => 'vinny@localhost', + :subject => 'Why do I have such an ace name?', + :comment => 'I AM A SPAMBOT', + :message => "You really should know!!!\n\nVinny", + }, :submitted_contact_form => 1 + } + + response.should redirect_to(frontpage_path) + + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 0 + deliveries.clear + end + end end -- cgit v1.2.3