mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 14:08:32 +08:00
Add Email-In-Per-Category
- allow the configuration of an inbox-email-address per category - post emails to that email into that category instead of global - Adds UI for configuration - Adds Documentation for configuration - Adds Tests for new feature
This commit is contained in:
@ -301,4 +301,123 @@ Jakie" }
|
||||
|
||||
end
|
||||
|
||||
|
||||
describe "processes an email to a category" do
|
||||
before do
|
||||
SiteSetting.stubs(:email_in_address).returns("")
|
||||
SiteSetting.stubs(:email_in_category).returns("42")
|
||||
SiteSetting.stubs(:email_in).returns(true)
|
||||
end
|
||||
|
||||
let(:incoming_email) { File.read("#{Rails.root}/spec/fixtures/emails/valid_incoming.eml") }
|
||||
let(:receiver) { Email::Receiver.new(incoming_email) }
|
||||
let(:user) { Fabricate.build(:user, id: 3456) }
|
||||
let(:category) { Fabricate.build(:category, id: 10) }
|
||||
let(:subject) { "We should have a post-by-email-feature." }
|
||||
let(:email_body) {
|
||||
"Hey folks,
|
||||
|
||||
I was thinking. Wouldn't it be great if we could post topics via email? Yes it would!
|
||||
|
||||
Jakie" }
|
||||
|
||||
describe "category not found" do
|
||||
|
||||
before do
|
||||
Category.expects(:find_by_email).returns(nil)
|
||||
end
|
||||
|
||||
let!(:result) { receiver.process }
|
||||
|
||||
it "returns missing" do
|
||||
expect(result).to eq(Email::Receiver.results[:missing])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "email from non user" do
|
||||
|
||||
before do
|
||||
User.expects(:find_by_email).returns(nil)
|
||||
Category.expects(:find_by_email).with(
|
||||
"discourse-in@appmail.adventuretime.ooo").returns(category)
|
||||
end
|
||||
|
||||
let!(:result) { receiver.process }
|
||||
|
||||
it "returns unprocessable" do
|
||||
expect(result).to eq(Email::Receiver.results[:unprocessable])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "email from untrusted user" do
|
||||
before do
|
||||
User.expects(:find_by_email).with(
|
||||
"jake@adventuretime.ooo").returns(user)
|
||||
Category.expects(:find_by_email).with(
|
||||
"discourse-in@appmail.adventuretime.ooo").returns(category)
|
||||
SiteSetting.stubs(:email_in_min_trust).returns(TrustLevel.levels[:elder].to_s)
|
||||
end
|
||||
|
||||
let!(:result) { receiver.process }
|
||||
|
||||
it "returns unprocessable" do
|
||||
expect(result).to eq(Email::Receiver.results[:unprocessable])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "with proper user" do
|
||||
|
||||
before do
|
||||
SiteSetting.stubs(:email_in_min_trust).returns(
|
||||
TrustLevel.levels[:newuser].to_s)
|
||||
User.expects(:find_by_email).with(
|
||||
"jake@adventuretime.ooo").returns(user)
|
||||
Category.expects(:find_by_email).with(
|
||||
"discourse-in@appmail.adventuretime.ooo").returns(category)
|
||||
|
||||
topic_creator = mock()
|
||||
TopicCreator.expects(:new).with(instance_of(User),
|
||||
instance_of(Guardian),
|
||||
has_entries(title: subject,
|
||||
category: 10)) # Make sure it is posted to the right category
|
||||
.returns(topic_creator)
|
||||
|
||||
topic_creator.expects(:create).returns(topic_creator)
|
||||
topic_creator.expects(:id).twice.returns(12345)
|
||||
|
||||
|
||||
post_creator = mock
|
||||
PostCreator.expects(:new).with(instance_of(User),
|
||||
has_entries(raw: email_body,
|
||||
topic_id: 12345,
|
||||
cooking_options: {traditional_markdown_linebreaks: true}))
|
||||
.returns(post_creator)
|
||||
|
||||
post_creator.expects(:create)
|
||||
|
||||
EmailLog.expects(:create).with(has_entries(
|
||||
email_type: 'topic_via_incoming_email',
|
||||
to_address: "discourse-in@appmail.adventuretime.ooo",
|
||||
user_id: 3456,
|
||||
topic_id: 12345
|
||||
))
|
||||
end
|
||||
|
||||
let!(:result) { receiver.process }
|
||||
|
||||
it "returns a processed result" do
|
||||
expect(result).to eq(Email::Receiver.results[:processed])
|
||||
end
|
||||
|
||||
it "extracts the body" do
|
||||
expect(receiver.body).to eq(email_body)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user