fix the build

This commit is contained in:
Régis Hanol 2015-12-16 01:31:19 +01:00
parent 4bb31daa2e
commit 51b2279af0
4 changed files with 35 additions and 24 deletions

View File

@ -484,14 +484,6 @@ This is a link http://example.com"
end
def fill_email(mail, from, to, body = nil, subject = nil, cc = nil)
result = mail.gsub("FROM", from).gsub("TO", to)
result.gsub!(/Hey.*/m, body) if body
result.sub!(/We .*/, subject) if subject
result.sub!("CC", cc.presence || "")
result
end
def process_email(opts)
incoming_email = fixture_file("emails/valid_incoming.eml")
email = fill_email(incoming_email, opts[:from], opts[:to], opts[:body], opts[:subject], opts[:cc])

View File

@ -5,7 +5,7 @@ Received: by mail-ie0-f180.google.com with SMTP id f4so21977375iea.25 for <reply
Received: by 10.0.0.1 with HTTP; Thu, 13 Jun 2013 14:03:48 -0700
Date: Thu, 13 Jun 2013 17:03:48 -0400
From: Jake the Dog <jake@adventuretime.ooo>
To: reply+QQd8df8370b7e95c5a49fbf86aeb2c93@appmail.adventuretime.ooo
To: reply+03d8df8370b7e95c5a49fbf86aeb2c93@appmail.adventuretime.ooo
Message-ID: <CADkmRc+rNGAGGbV2iE5p918UVy4UyJqVcXRO2=otppgzduJSg@mail.gmail.com>
Subject: re: [Discourse Meta] eviltrout posted in 'Adventure Time Sux'
Mime-Version: 1.0
@ -37,4 +37,4 @@ On Sun, Jun 9, 2013 at 1:39 PM, eviltrout via Discourse Meta
> Please visit this link to respond: http://localhost:3000/t/adventure-time-sux/1234/3
>
> To unsubscribe from these emails, visit your [user preferences](http://localhost:3000/user_preferences).
>
>

View File

@ -172,16 +172,19 @@ describe Jobs::PollMailbox do
end
describe "a valid reply" do
let(:email) { MockPop3EmailObject.new fixture_file('emails/valid_reply.eml')}
let(:expected_post) { fixture_file('emails/valid_reply.cooked')}
let(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' }
let(:to) { SiteSetting.reply_by_email_address.gsub("%{reply_key}", reply_key) }
let(:raw_email) { fill_email(fixture_file("emails/valid_reply.eml"), user.email, to) }
let(:email) { MockPop3EmailObject.new(raw_email) }
let(:expected_post) { fixture_file('emails/valid_reply.cooked') }
let(:topic) { Fabricate(:topic) }
let(:first_post) { Fabricate(:post, topic: topic, post_number: 1)}
let(:first_post) { Fabricate(:post, user: user, topic: topic, post_number: 1) }
before do
first_post.save
EmailLog.create(to_address: 'jake@email.example.com',
EmailLog.create(to_address: user.email,
email_type: 'user_posted',
reply_key: '59d8df8370b7e95c5a49fbf86aeb2c93',
reply_key: reply_key,
user: user,
post: first_post,
topic: topic)
@ -225,15 +228,18 @@ describe Jobs::PollMailbox do
end
describe "when topic is closed" do
let(:email) { MockPop3EmailObject.new fixture_file('emails/valid_reply.eml')}
let(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' }
let(:to) { SiteSetting.reply_by_email_address.gsub("%{reply_key}", reply_key) }
let(:raw_email) { fill_email(fixture_file("emails/valid_reply.eml"), user.email, to) }
let(:email) { MockPop3EmailObject.new(raw_email) }
let(:topic) { Fabricate(:topic, closed: true) }
let(:first_post) { Fabricate(:post, topic: topic, post_number: 1)}
let(:first_post) { Fabricate(:post, user: user, topic: topic, post_number: 1) }
before do
first_post.save
EmailLog.create(to_address: 'jake@email.example.com',
EmailLog.create(to_address: user.email,
email_type: 'user_posted',
reply_key: '59d8df8370b7e95c5a49fbf86aeb2c93',
reply_key: reply_key,
user: user,
post: first_post,
topic: topic)
@ -250,15 +256,18 @@ describe Jobs::PollMailbox do
end
describe "when topic is deleted" do
let(:email) { MockPop3EmailObject.new fixture_file('emails/valid_reply.eml')}
let(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' }
let(:to) { SiteSetting.reply_by_email_address.gsub("%{reply_key}", reply_key) }
let(:raw_email) { fill_email(fixture_file("emails/valid_reply.eml"), user.email, to) }
let(:email) { MockPop3EmailObject.new(raw_email) }
let(:deleted_topic) { Fabricate(:deleted_topic) }
let(:first_post) { Fabricate(:post, topic: deleted_topic, post_number: 1)}
let(:first_post) { Fabricate(:post, user: user, topic: deleted_topic, post_number: 1)}
before do
first_post.save
EmailLog.create(to_address: 'jake@email.example.com',
EmailLog.create(to_address: user.email,
email_type: 'user_posted',
reply_key: '59d8df8370b7e95c5a49fbf86aeb2c93',
reply_key: reply_key,
user: user,
post: first_post,
topic: deleted_topic)
@ -277,7 +286,9 @@ describe Jobs::PollMailbox do
describe "in failure conditions" do
it "a valid reply without an email log raises an EmailLogNotFound error" do
email = MockPop3EmailObject.new fixture_file('emails/valid_reply.eml')
to = SiteSetting.reply_by_email_address.gsub("%{reply_key}", '59d8df8370b7e95c5a49fbf86aeb2c93')
raw_email = fill_email(fixture_file("emails/valid_reply.eml"), user.email, to)
email = MockPop3EmailObject.new(raw_email)
expect_exception Email::Receiver::EmailLogNotFound
poller.handle_mail(email)

View File

@ -64,4 +64,12 @@ module Helpers
expect(result).to eq(true)
end
def fill_email(mail, from, to, body = nil, subject = nil, cc = nil)
result = mail.gsub("FROM", from).gsub("TO", to)
result.gsub!(/Hey.*/m, body) if body
result.sub!(/We .*/, subject) if subject
result.sub!("CC", cc.presence || "")
result
end
end