Commit 109255cb authored by Eugenia Grieff's avatar Eugenia Grieff

Change trim_reply method to use split

- Update specs
parent f03510b0
......@@ -70,14 +70,12 @@ module Gitlab
end
def trim_reply(text, append_trimmed_reply: false)
trimmed_body = EmailReplyTrimmer.trim(text)
return '' unless trimmed_body
return trimmed_body unless append_trimmed_reply
trimmed_body, stripped_text = EmailReplyTrimmer.trim(text, true)
_, main_body, stripped_text = text.partition(trimmed_body)
return main_body if stripped_text.chomp.empty?
return '' unless trimmed_body.present?
return trimmed_body unless stripped_text.present? && append_trimmed_reply
main_body + "\n<details><summary>...</summary>\n#{stripped_text}\n</details>"
trimmed_body + "\n\n<details><summary>...</summary>\n\n#{stripped_text}\n\n</details>"
end
end
end
......
Return-Path: <jake@adventuretime.ooo>
Received: from iceking.adventuretime.ooo ([unix socket]) by iceking (Cyrus v2.2.13-Debian-2.2.13-19+squeeze3) with LMTPA; Thu, 13 Jun 2013 17:03:50 -0400
Received: from mail-ie0-x234.google.com (mail-ie0-x234.google.com [IPv6:2607:f8b0:4001:c03::234]) by iceking.adventuretime.ooo (8.14.3/8.14.3/Debian-9.4) with ESMTP id r5DL3nFJ016967 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for <reply+59d8df8370b7e95c5a49fbf86aeb2c93@appmail.adventuretime.ooo>; Thu, 13 Jun 2013 17:03:50 -0400
Received: by mail-ie0-f180.google.com with SMTP id f4so21977375iea.25 for <reply+59d8df8370b7e95c5a49fbf86aeb2c93@appmail.adventuretime.ooo>; Thu, 13 Jun 2013 14:03:48 -0700
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+59d8df8370b7e95c5a49fbf86aeb2c93@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
Content-Type: text/plain;
charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Sieve: CMU Sieve 2.2
X-Received: by 10.0.0.1 with SMTP id n7mr11234144ipb.85.1371157428600; Thu,
13 Jun 2013 14:03:48 -0700 (PDT)
X-Scanned-By: MIMEDefang 2.69 on IPv6:2001:470:1d:165::1
--
> quote line 1
> quote line 2
> quote line 3
......@@ -108,40 +108,57 @@ RSpec.describe Gitlab::Email::Handler::CreateNoteHandler do
it_behaves_like 'an email that contains a mail key', 'References'
end
end
end
context 'when email contains quoted text' do
context 'when noteable is an issue' do
let_it_be(:issue) { create(:issue, project: project )}
let_it_be(:note) { create(:note_on_issue, noteable: issue, project: project) }
context 'when email contains reply' do
shared_examples 'no content message' do
context 'when email contains quoted text only' do
let(:email_raw) { fixture_file('emails/no_content_with_quote.eml') }
context 'when email contains quoted text only' do
let(:email_raw) { fixture_file('emails/no_content_reply.eml') }
it 'raises an EmptyEmailError' do
expect { receiver.execute }.to raise_error(Gitlab::Email::EmptyEmailError)
end
end
it 'creates a discussion without appended reply' do
expect { receiver.execute }.to change { noteable.notes.count }.by(1)
new_note = noteable.notes.last
context 'when email contains quoted text and quick commands only' do
let(:email_raw) { fixture_file('emails/commands_only_reply.eml') }
expect(new_note.note).not_to include('<details><summary>...</summary>')
end
it 'does not create a discussion' do
expect { receiver.execute }.not_to change { noteable.notes.count }
end
end
end
context 'when noteable is not an issue' do
let_it_be(:note) { create(:note_on_merge_request, project: project) }
it_behaves_like 'no content message'
context 'when email contains text, quoted text and quick commands' do
let(:email_raw) { fixture_file('emails/commands_in_reply.eml') }
context 'when email contains quoted text and quick commands only' do
let(:email_raw) { fixture_file('emails/commands_only_reply.eml') }
it 'creates a discussion without appended reply' do
expect { receiver.execute }.to change { noteable.notes.count }.by(1)
new_note = noteable.notes.last
it 'does not create a discussion' do
expect { receiver.execute }.not_to change { noteable.notes.count }
end
expect(new_note.note).not_to include('<details><summary>...</summary>')
end
end
end
context 'when email contains text, quoted text and quick commands' do
let(:email_raw) { fixture_file('emails/commands_in_reply.eml') }
context 'when noteable is an issue' do
let_it_be(:note) { create(:note_on_issue, project: project) }
it 'creates a discussion with appended reply' do
expect { receiver.execute }.to change { noteable.notes.count }.by(1)
new_note = noteable.notes.last
it_behaves_like 'no content message'
context 'when email contains text, quoted text and quick commands' do
let(:email_raw) { fixture_file('emails/commands_in_reply.eml') }
it 'creates a discussion with appended reply' do
expect { receiver.execute }.to change { noteable.notes.count }.by(1)
new_note = noteable.notes.last
expect(new_note.note).to include('<details><summary>...</summary>')
end
expect(new_note.note).to include('<details><summary>...</summary>')
end
end
end
......
......@@ -237,10 +237,11 @@ RSpec.describe Gitlab::Email::ReplyParser do
even when the email is forwarded to the project which may include lines that begin with ">"
there should be a quote below this line:
<details><summary>...</summary>
<details><summary>...</summary>
> this is a quote
</details>
BODY
)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment