Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/models/refinery/inquiries/inquiry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 8 additions & 14 deletions spec/features/refinery/inquiries/mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,16 @@ module Inquiries
click_button "Send message"
end

it "sends confirmation email" do
open_email("[email protected]")
it_has_behaviour 'sends emails'

expect(current_email.from).to eq(["#{Refinery::Inquiries.from_name}@example.com"])
expect(current_email.to).to eq(["[email protected]"])
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("[email protected]")
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(["[email protected]"])
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: [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.")
it_has_behaviour 'sends emails'
end
end
end
end
Expand Down
19 changes: 19 additions & 0 deletions spec/support/shared_examples/mail_sender.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
shared_examples_for 'sends emails' do
it "sends confirmation email" do
open_email("[email protected]")

expect(current_email.from).to eq(["#{Refinery::Inquiries.from_name}@example.com"])
expect(current_email.to).to eq(["[email protected]"])
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("[email protected]")

expect(current_email.from).to eq(["#{Refinery::Inquiries.from_name}@example.com"])
expect(current_email.to).to eq(["[email protected]"])
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: [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.")
end
end
3 changes: 3 additions & 0 deletions spec/support/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RSpec.configure do |c|
c.alias_it_should_behave_like_to :it_has_behaviour, 'has behaviour:'
end