Start making better-written tests for the email job

This commit is contained in:
riking 2014-08-01 11:03:03 -07:00
parent d87edce6c3
commit d7df4e5979
5 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,5 @@
<p>Hey folks,</p>
<p>I was thinking. Wouldn't it be great if we could post topics via email? Yes it would!</p>
<p>Jakie</p>

Binary file not shown.

View File

@ -0,0 +1,3 @@
<p>I could not disagree more. I am obviously biased but adventure time is the greatest show ever created. Everyone should watch it.</p>
<p>- Jake out</p>

Binary file not shown.

View File

@ -41,6 +41,93 @@ describe Jobs::PollMailbox do
end
# Testing mock for the email objects that you get
# from Net::POP3.start { |pop| pop.mails }
class MockPop3EmailObject
def initialize(mail_string)
@message = mail_string
@delete_called = 0
end
def pop
@message
end
def delete
@delete_called += 1
end
# call 'assert email.deleted?' at the end of the test
def deleted?
@delete_called == 1
end
end
describe "processing email B" do
let(:category) { Fabricate(:category) }
let(:user) { Fabricate(:user) }
before do
SiteSetting.email_in = true
SiteSetting.reply_by_email_address = 'reply+%{reply_key}@discourse.example.com'
category.email_in = 'incoming+amazing@discourse.example.com'
category.save
user.change_trust_level! :regular
user.username = 'Jake'
user.email = 'jake@email.example.com'
user.save
end
describe "valid incoming email" do
let(:email) { MockPop3EmailObject.new fixture_file('emails/valid_incoming.eml')}
let(:expected_post) { fixture_file('emails/valid_incoming.cooked') }
it "posts a new topic with the correct content" do
poller.handle_mail(email)
topic = Topic.where(category: category).where.not(id: category.topic_id).first
assert topic.present?
post = topic.posts.first
assert_equal expected_post.strip, post.cooked.strip
assert email.deleted?
end
end
describe "valid reply" do
let(:email) { MockPop3EmailObject.new fixture_file('emails/valid_reply.eml')}
let(:expected_post) { fixture_file('emails/valid_reply.cooked')}
let(:topic) { Fabricate(:topic) }
let(:first_post) { Fabricate(:post, topic: topic, post_number: 1)}
before do
first_post.save
EmailLog.create(to_address: 'jake@email.example.com',
email_type: 'user_posted',
reply_key: '59d8df8370b7e95c5a49fbf86aeb2c93',
post: first_post,
topic: topic)
end
pending "creates a new post with the correct content" do
RejectionMailer.expects(:send_rejection).never
Discourse.expects(:handle_exception).never
poller.handle_mail(email)
new_post = Post.where(topic: topic, post_number: 2)
assert new_post.present?
assert_equal expected_post.strip, new_post.cooked.strip
assert email.deleted?
end
end
end
describe "processing email" do
let!(:receiver) { mock }