Skip to content

A platform for community discussion. Free, open, simple.

DEV: Refactor test to not call private method.

Guo Xiang Tan7dcc69aef481
diff --git a/lib/email/processor.rb b/lib/email/processor.rb
index da1c39e04fe..ad43efeda92 100644
--- a/lib/email/processor.rb
+++ b/lib/email/processor.rb
@@ -1,6 +1,7 @@
module Email
class Processor
+ attr_reader :receiver
def initialize(mail, retry_on_rate_limit = true)
@mail = mail
diff --git a/spec/components/email/processor_spec.rb b/spec/components/email/processor_spec.rb
index 1cec58aca00..0a0a0c7b4cc 100644
--- a/spec/components/email/processor_spec.rb
+++ b/spec/components/email/processor_spec.rb
@@ -2,44 +2,40 @@ require "rails_helper"
require "email/processor"
describe Email::Processor do
+ after do
+ $redis.flushall
+ end
let(:from) { "[email protected]" }
context "when reply via email is too short" do
- let(:mail) { file_from_fixtures("email_reply_3.eml", "emails").read }
+ let(:mail) { file_from_fixtures("chinese_reply.eml", "emails").read }
let(:post) { Fabricate(:post) }
- let!(:user) { Fabricate(:user, email: "[email protected]") }
- let!(:email_log) do
- Fabricate(:email_log,
- message_id: "[email protected]", # don't change, based on fixture file "email_reply_3.eml"
- email_type: "user_posted",
- post_id: post.id,
- to_address: "[email protected]"
+ let(:user) { Fabricate(:user, email: '[email protected]') }
+
+ let!(:post_reply_key) do
+ Fabricate(:post_reply_key,
+ user: user,
+ post: post,
+ reply_key: '4f97315cc828096c9cb34c6f1a0d6fe8'
)
end
before do
+ SiteSetting.email_in = true
+ SiteSetting.reply_by_email_address = "reply+%{reply_key}@bar.com"
SiteSetting.min_post_length = 1000
- SiteSetting.find_related_post_with_key = false
end
it "rejects reply and sends an email with custom error message" do
- begin
- receiver = Email::Receiver.new(mail)
- receiver.process!
- rescue Email::Receiver::TooShortPost => e
- error = e
- end
-
- expect(error.class).to eq(Email::Receiver::TooShortPost)
processor = Email::Processor.new(mail)
processor.process!
- rejection_raw = processor.send(:handle_failure, mail, error).body.raw_source
+ rejection_raw = ActionMailer::Base.deliveries.first.body.raw_source
count = SiteSetting.min_post_length
- destination = receiver.mail.to
- former_title = receiver.mail.subject
+ destination = processor.receiver.mail.to
+ former_title = processor.receiver.mail.subject
expect(rejection_raw.gsub(/\r/, "")).to eq(
I18n.t("system_messages.email_reject_post_too_short.text_body_template",
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
index 0bd62cd22b0..b267a16e0ef 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -133,6 +133,7 @@ RSpec.configure do |config|
end
unfreeze_time
+ ActionMailer::Base.deliveries.clear
raise if ActiveRecord::Base.connection_pool.stat[:busy] > 1
end