mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 01:34:39 +08:00
DEV: Refactor some mail receiver related specs.
This commit is contained in:
@ -550,26 +550,33 @@ describe Email::Receiver do
|
|||||||
expect(Topic.last.ordered_posts[-1].post_type).to eq(Post.types[:moderator_action])
|
expect(Topic.last.ordered_posts[-1].post_type).to eq(Post.types[:moderator_action])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "associates email replies using both 'In-Reply-To' and 'References' headers when 'find_related_post_with_key' is disabled" do
|
describe "when 'find_related_post_with_key' is disabled" do
|
||||||
SiteSetting.find_related_post_with_key = false
|
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(ordered_posts.first.raw).to eq('This is email reply **1**.')
|
||||||
expect { process(:email_reply_3) }.to change { topic.posts.count }
|
|
||||||
|
|
||||||
# Why 5 when we only processed 3 emails?
|
ordered_posts[1..-1].each do |post|
|
||||||
# - 3 of them are indeed "regular" posts generated from the emails
|
expect(post.action_code).to eq('invited_user')
|
||||||
# - The 2 others are "small action" posts automatically added because
|
expect(post.user.email).to eq('one@foo.com')
|
||||||
# we invited 2 users (two@foo.com and three@foo.com)
|
|
||||||
expect(topic.posts.count).to eq(5)
|
|
||||||
|
|
||||||
# trash all but the 1st post
|
expect(%w{two three}.include?(post.custom_fields["action_code_who"]))
|
||||||
topic.ordered_posts[1..-1].each(&:trash!)
|
.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
|
end
|
||||||
|
|
||||||
it "supports any kind of attachments when 'allow_all_attachments_for_group_messages' is enabled" do
|
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
|
before do
|
||||||
SiteSetting.block_auto_generated_emails = true
|
SiteSetting.block_auto_generated_emails = true
|
||||||
SiteSetting.find_related_post_with_key = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should allow creating topic even when email is autogenerated" do
|
it "should allow creating topic even when email is autogenerated" do
|
||||||
|
@ -20,7 +20,7 @@ describe ReplyByEmailAddressValidator do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "returns true if value does not contain '%{reply_key}' but 'find_related_post_with_key' is also disabled" do
|
it "returns true if value does not contain '%{reply_key}' but 'find_related_post_with_key' is also disabled" do
|
||||||
SiteSetting.expects(:find_related_post_with_key).returns(false)
|
SiteSetting.find_related_post_with_key = false
|
||||||
expect(validator.valid_value?('foo@bar.com')).to eq(true)
|
expect(validator.valid_value?('foo@bar.com')).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user