Skip to content

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

DEV: Refactor some mail receiver related specs.

Guo Xiang Tan48f499b3247d
diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb
index f5b8fb08ad6..7289aa92f16 100644
--- a/spec/components/email/receiver_spec.rb
+++ b/spec/components/email/receiver_spec.rb
@@ -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 ([email protected] and [email protected])
- 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('[email protected]')
- # 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
diff --git a/spec/components/validators/reply_by_email_address_validator_spec.rb b/spec/components/validators/reply_by_email_address_validator_spec.rb
index c64a4a62a5e..79eb7d443ba 100644
--- a/spec/components/validators/reply_by_email_address_validator_spec.rb
+++ b/spec/components/validators/reply_by_email_address_validator_spec.rb
@@ -20,7 +20,7 @@ describe ReplyByEmailAddressValidator do
end
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?('[email protected]')).to eq(true)
end