From e93410d83452d193da4c1abb43c68f4c43522b5a Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Tue, 29 Mar 2016 15:56:06 -0400 Subject: [PATCH] Bugfix ability to send emails when filter_spam is set to false --- app/models/refinery/inquiries/inquiry.rb | 3 +++ .../refinery/inquiries/mailer_spec.rb | 22 +++++++------------ spec/support/shared_examples/mail_sender.rb | 19 ++++++++++++++++ spec/support/spec_helper.rb | 3 +++ 4 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 spec/support/shared_examples/mail_sender.rb create mode 100644 spec/support/spec_helper.rb diff --git a/app/models/refinery/inquiries/inquiry.rb b/app/models/refinery/inquiries/inquiry.rb index 7e6e3942..2be4f09e 100644 --- a/app/models/refinery/inquiries/inquiry.rb +++ b/app/models/refinery/inquiries/inquiry.rb @@ -25,6 +25,9 @@ def self.latest(number = 7, include_spam = false) include_spam ? limit(number) : ham.limit(number) end + def ham? + Inquiries.config.filter_spam ? not(spam?) : true + end end end end diff --git a/spec/features/refinery/inquiries/mailer_spec.rb b/spec/features/refinery/inquiries/mailer_spec.rb index e21f264c..e5eafed3 100644 --- a/spec/features/refinery/inquiries/mailer_spec.rb +++ b/spec/features/refinery/inquiries/mailer_spec.rb @@ -20,22 +20,16 @@ module Inquiries click_button "Send message" end - it "sends confirmation email" do - open_email("ugis.ozols@refinerycms.com") + it_has_behaviour 'sends emails' - expect(current_email.from).to eq(["#{Refinery::Inquiries.from_name}@example.com"]) - expect(current_email.to).to eq(["ugis.ozols@refinerycms.com"]) - expect(current_email.subject).to eq("Thank you for your inquiry") - expect(current_email.body).to eq("Thank you for your inquiry Ugis Ozols,\n\nThis email is a receipt to confirm we have received your inquiry and we'll be in touch shortly.\n\nThanks.") - end - - it "sends notification email" do - open_email("rspec@refinerycms.com") + describe "filter_spam" do + context "when filter_spam setting is set to false" do + before(:each) do + allow(Refinery::Inquiries.config).to receive(:filter_spam).and_return(false) + end - expect(current_email.from).to eq(["#{Refinery::Inquiries.from_name}@example.com"]) - expect(current_email.to).to eq(["rspec@refinerycms.com"]) - expect(current_email.subject).to eq("New inquiry from your website") - expect(current_email.body).to eq("Hi there,\n\nYou just received a new inquiry on your website.\n\n--- inquiry starts ---\n\nFrom: Ugis Ozols\nEmail: ugis.ozols@refinerycms.com\nPhone: \nMessage:\nHey, I'm testing!\n\n--- inquiry ends ---\n\nKind Regards,\nCompany Name\n\nP.S. All your inquiries are stored in the \"Inquiries\" section of Refinery should you ever want to view it later there.") + it_has_behaviour 'sends emails' + end end end end diff --git a/spec/support/shared_examples/mail_sender.rb b/spec/support/shared_examples/mail_sender.rb new file mode 100644 index 00000000..6c34502a --- /dev/null +++ b/spec/support/shared_examples/mail_sender.rb @@ -0,0 +1,19 @@ +shared_examples_for 'sends emails' do + it "sends confirmation email" do + open_email("ugis.ozols@refinerycms.com") + + expect(current_email.from).to eq(["#{Refinery::Inquiries.from_name}@example.com"]) + expect(current_email.to).to eq(["ugis.ozols@refinerycms.com"]) + expect(current_email.subject).to eq("Thank you for your inquiry") + expect(current_email.body).to eq("Thank you for your inquiry Ugis Ozols,\n\nThis email is a receipt to confirm we have received your inquiry and we'll be in touch shortly.\n\nThanks.") + end + + it "sends notification email" do + open_email("rspec@refinerycms.com") + + expect(current_email.from).to eq(["#{Refinery::Inquiries.from_name}@example.com"]) + expect(current_email.to).to eq(["rspec@refinerycms.com"]) + expect(current_email.subject).to eq("New inquiry from your website") + expect(current_email.body).to eq("Hi there,\n\nYou just received a new inquiry on your website.\n\n--- inquiry starts ---\n\nFrom: Ugis Ozols\nEmail: ugis.ozols@refinerycms.com\nPhone: \nMessage:\nHey, I'm testing!\n\n--- inquiry ends ---\n\nKind Regards,\nCompany Name\n\nP.S. All your inquiries are stored in the \"Inquiries\" section of Refinery should you ever want to view it later there.") + end +end \ No newline at end of file diff --git a/spec/support/spec_helper.rb b/spec/support/spec_helper.rb new file mode 100644 index 00000000..464440fd --- /dev/null +++ b/spec/support/spec_helper.rb @@ -0,0 +1,3 @@ +RSpec.configure do |c| + c.alias_it_should_behave_like_to :it_has_behaviour, 'has behaviour:' +end \ No newline at end of file