DEV: Refactor some mail receiver related specs.

This commit is contained in:
Guo Xiang Tan
2018-08-21 14:00:45 +08:00
parent d104de2a09
commit 48f499b324
2 changed files with 22 additions and 16 deletions

View File

@ -550,26 +550,33 @@ describe Email::Receiver do
expect(Topic.last.ordered_posts[-1].post_type).to eq(Post.types[:moderator_action])
end
it "associates email replies using both 'In-Reply-To' and 'References' headers when 'find_related_post_with_key' is disabled" do
SiteSetting.find_related_post_with_key = false
describe "when 'find_related_post_with_key' is disabled" do
before do
SiteSetting.find_related_post_with_key = false
end
expect { process(:email_reply_1) }.to change(Topic, :count)
it "associates email replies using both 'In-Reply-To' and 'References' headers" do
expect { process(:email_reply_1) }
.to change(Topic, :count).by(1) & change(Post, :count).by(3)
topic = Topic.last
topic = Topic.last
ordered_posts = topic.ordered_posts
expect { process(:email_reply_2) }.to change { topic.posts.count }
expect { process(:email_reply_3) }.to change { topic.posts.count }
expect(ordered_posts.first.raw).to eq('This is email reply **1**.')
# Why 5 when we only processed 3 emails?
# - 3 of them are indeed "regular" posts generated from the emails
# - The 2 others are "small action" posts automatically added because
# we invited 2 users (two@foo.com and three@foo.com)
expect(topic.posts.count).to eq(5)
ordered_posts[1..-1].each do |post|
expect(post.action_code).to eq('invited_user')
expect(post.user.email).to eq('one@foo.com')
# trash all but the 1st post
topic.ordered_posts[1..-1].each(&:trash!)
expect(%w{two three}.include?(post.custom_fields["action_code_who"]))
.to eq(true)
end
expect { process(:email_reply_4) }.to change { topic.posts.count }
expect { process(:email_reply_2) }.to change { topic.posts.count }.by(1)
expect { process(:email_reply_3) }.to change { topic.posts.count }.by(1)
ordered_posts[1..-1].each(&:trash!)
expect { process(:email_reply_4) }.to change { topic.posts.count }.by(1)
end
end
it "supports any kind of attachments when 'allow_all_attachments_for_group_messages' is enabled" do
@ -1000,7 +1007,6 @@ describe Email::Receiver do
before do
SiteSetting.block_auto_generated_emails = true
SiteSetting.find_related_post_with_key = true
end
it "should allow creating topic even when email is autogenerated" do