Skip to content

Commit e93410d

Browse files
author
Brice Sanchez
committed
Bugfix ability to send emails when filter_spam is set to false
1 parent 774c7cb commit e93410d

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

app/models/refinery/inquiries/inquiry.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ def self.latest(number = 7, include_spam = false)
2525
include_spam ? limit(number) : ham.limit(number)
2626
end
2727

28+
def ham?
29+
Inquiries.config.filter_spam ? not(spam?) : true
30+
end
2831
end
2932
end
3033
end

spec/features/refinery/inquiries/mailer_spec.rb

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,16 @@ module Inquiries
2020
click_button "Send message"
2121
end
2222

23-
it "sends confirmation email" do
24-
open_email("[email protected]")
23+
it_has_behaviour 'sends emails'
2524

26-
expect(current_email.from).to eq(["#{Refinery::Inquiries.from_name}@example.com"])
27-
expect(current_email.to).to eq(["[email protected]"])
28-
expect(current_email.subject).to eq("Thank you for your inquiry")
29-
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.")
30-
end
31-
32-
it "sends notification email" do
33-
open_email("[email protected]")
25+
describe "filter_spam" do
26+
context "when filter_spam setting is set to false" do
27+
before(:each) do
28+
allow(Refinery::Inquiries.config).to receive(:filter_spam).and_return(false)
29+
end
3430

35-
expect(current_email.from).to eq(["#{Refinery::Inquiries.from_name}@example.com"])
36-
expect(current_email.to).to eq(["[email protected]"])
37-
expect(current_email.subject).to eq("New inquiry from your website")
38-
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: [email protected]\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.")
31+
it_has_behaviour 'sends emails'
32+
end
3933
end
4034
end
4135
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
shared_examples_for 'sends emails' do
2+
it "sends confirmation email" do
3+
open_email("[email protected]")
4+
5+
expect(current_email.from).to eq(["#{Refinery::Inquiries.from_name}@example.com"])
6+
expect(current_email.to).to eq(["[email protected]"])
7+
expect(current_email.subject).to eq("Thank you for your inquiry")
8+
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.")
9+
end
10+
11+
it "sends notification email" do
12+
open_email("[email protected]")
13+
14+
expect(current_email.from).to eq(["#{Refinery::Inquiries.from_name}@example.com"])
15+
expect(current_email.to).to eq(["[email protected]"])
16+
expect(current_email.subject).to eq("New inquiry from your website")
17+
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: [email protected]\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.")
18+
end
19+
end

spec/support/spec_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RSpec.configure do |c|
2+
c.alias_it_should_behave_like_to :it_has_behaviour, 'has behaviour:'
3+
end

0 commit comments

Comments
 (0)