From 96982e47a7d0d199d70b8f7b4ecd1df243888e5f Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Sat, 4 Jun 2016 14:39:16 +0200 Subject: [PATCH] blacklist some funding sources --- .../cmtool/contact_forms_controller.rb | 20 +++++++++---------- app/models/cmtool/contact_form.rb | 9 +++++++++ spec/models/cmtool/contact_form_spec.rb | 10 ++++++++++ 3 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 spec/models/cmtool/contact_form_spec.rb diff --git a/app/controllers/cmtool/contact_forms_controller.rb b/app/controllers/cmtool/contact_forms_controller.rb index 5e8241a..4648098 100644 --- a/app/controllers/cmtool/contact_forms_controller.rb +++ b/app/controllers/cmtool/contact_forms_controller.rb @@ -9,7 +9,7 @@ module Cmtool respond_to do |format| format.html # index.html.erb - format.xml { render :xml => @contact_forms } + format.xml { render xml: @contact_forms } end end @@ -20,7 +20,7 @@ module Cmtool respond_to do |format| format.html # show.html.erb - format.xml { render :xml => @contact_form } + format.xml { render xml: @contact_form } end end @@ -31,7 +31,7 @@ module Cmtool respond_to do |format| format.html # new.html.erb - format.xml { render :xml => @contact_form } + format.xml { render xml: @contact_form } end end @@ -47,11 +47,11 @@ module Cmtool respond_to do |format| if @contact_form.save - format.html { redirect_to([cmtool, @contact_form], :notice => I18n.t('cmtool.action.create.successful', :model => Cmtool::ContactForm.model_name.human)) } - format.xml { render :xml => @contact_form, :status => :created, :location => @contact_form } + format.html { redirect_to([cmtool, @contact_form], notice: I18n.t('cmtool.action.create.successful', model: Cmtool::ContactForm.model_name.human)) } + format.xml { render xml: @contact_form, status: :created, location: @contact_form } else - format.html { render :action => "new" } - format.xml { render :xml => @contact_form.errors, :status => :unprocessable_entity } + format.html { render action: "new" } + format.xml { render xml: @contact_form.errors, status: :unprocessable_entity } end end end @@ -63,11 +63,11 @@ module Cmtool respond_to do |format| if @contact_form.update_attributes(contact_form_params) - format.html { redirect_to([cmtool, @contact_form], :notice => I18n.t('cmtool.action.update.successful', :model => Cmtool::ContactForm.model_name.human)) } + format.html { redirect_to([cmtool, @contact_form], notice: I18n.t('cmtool.action.update.successful', model: Cmtool::ContactForm.model_name.human)) } format.xml { head :ok } else - format.html { render :action => "edit" } - format.xml { render :xml => @contact_form.errors, :status => :unprocessable_entity } + format.html { render action: "edit" } + format.xml { render xml: @contact_form.errors, status: :unprocessable_entity } end end end diff --git a/app/models/cmtool/contact_form.rb b/app/models/cmtool/contact_form.rb index bc767ac..e252da7 100644 --- a/app/models/cmtool/contact_form.rb +++ b/app/models/cmtool/contact_form.rb @@ -7,5 +7,14 @@ module Cmtool property :phone property :body validates :email, presence: true + validate :if_there_are_bad_intentions + + private + + def if_there_are_bad_intentions + has_bad_intentions = false + has_bad_intentions = true if "#{email}#{body}" =~ /funded\.com/i + errors.add(:base, :bad_intentions) if has_bad_intentions + end end end diff --git a/spec/models/cmtool/contact_form_spec.rb b/spec/models/cmtool/contact_form_spec.rb new file mode 100644 index 0000000..34f3f41 --- /dev/null +++ b/spec/models/cmtool/contact_form_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper' + +describe Cmtool::ContactForm do + + it "is invalid with Funded.com in email or body" do + build(:contact_form).should be_valid + build(:contact_form, email: "fundingteam+url.com@getbusinessfunded.com").should_not be_valid + build(:contact_form, body: "fundingteam+url.com@getbusinessFunded.com").should_not be_valid + end +end