Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

replace legacy spec

ulferts03366d2a3839
diff --git a/spec_legacy/fixtures/mail_handler/japanese_keywords_iso_2022_jp.eml b/spec/fixtures/mail_handler/wp_with_attributes_japanese.eml
similarity index 91%
rename from spec_legacy/fixtures/mail_handler/japanese_keywords_iso_2022_jp.eml
rename to spec/fixtures/mail_handler/wp_with_attributes_japanese.eml
index 84bb265652f..06314bb8268 100644
--- a/spec_legacy/fixtures/mail_handler/japanese_keywords_iso_2022_jp.eml
+++ b/spec/fixtures/mail_handler/wp_with_attributes_japanese.eml
@@ -1,6 +1,6 @@
Message-ID: <001101ca9762$293d68c0$0600a8c0@osiris>
From: "jsmith" <[email protected]>
Subject: Japanese Character pattern matching
Date: Sun, 17 Jan 2010 11:45:18 +0100
MIME-Version: 1.0
@@ -21,7 +21,7 @@ Content-Transfer-Encoding: quoted-printable
It should be noted that I am receiving emails using pop and the patch in =
Issue #2420 but I don't think the problem lies with this.
-When I try and send emails to the redmine server with Japanese =
+When I try and send emails to the OpenProject server with Japanese =
characters in them it appears to work apart from the pattern matching.
For example if I send an email with the following keywords.
@@ -49,7 +49,7 @@ title=3D"Fetching emails from an POP server (New)"=20
href=3D"http://www.redmine.org/issues/2420">#2420</A> but I don't think =
the=20
problem lies with this.</P>
-<P>When I try and send emails to the redmine server with Japanese =
+<P>When I try and send emails to the OpenProject server with Japanese =
characters in=20
them it appears to work apart from the pattern matching.</P>
<P>For example if I send an email with the following keywords.</P>
diff --git a/spec_legacy/fixtures/mail_handler/ticket_html_only.eml b/spec/fixtures/mail_handler/wp_with_html_only_description.eml
similarity index 94%
rename from spec_legacy/fixtures/mail_handler/ticket_html_only.eml
rename to spec/fixtures/mail_handler/wp_with_html_only_description.eml
index 511e5f10768..6e80d3a8f12 100644
--- a/spec_legacy/fixtures/mail_handler/ticket_html_only.eml
+++ b/spec/fixtures/mail_handler/wp_with_html_only_description.eml
@@ -1,5 +1,5 @@
x-sender: <[email protected]>
-x-receiver: <[email protected]>
+x-receiver: <[email protected]>
Received: from [127.0.0.1] ([127.0.0.1]) by somenet.foo with Quick 'n Easy Mail Server SMTP (1.0.0.0);
Sun, 14 Dec 2008 16:18:06 GMT
Message-ID: <[email protected]>
diff --git a/spec_legacy/fixtures/mail_handler/subject_as_iso-8859-1.eml b/spec/fixtures/mail_handler/wp_with_iso_8859_1_subject.eml
similarity index 87%
rename from spec_legacy/fixtures/mail_handler/subject_as_iso-8859-1.eml
rename to spec/fixtures/mail_handler/wp_with_iso_8859_1_subject.eml
index 45f725bdf15..87056957ef6 100644
--- a/spec_legacy/fixtures/mail_handler/subject_as_iso-8859-1.eml
+++ b/spec/fixtures/mail_handler/wp_with_iso_8859_1_subject.eml
@@ -1,7 +1,7 @@
Content-Type: application/ms-tnef; name="winmail.dat"
Content-Transfer-Encoding: binary
From: John Smith <[email protected]>
Subject: =?iso-8859-1?Q?Testmail_from_Webmail:_=E4_=F6_=FC...?=
Date: Fri, 1 Jun 2012 14:39:38 +0200
Message-ID: <[email protected]>
diff --git a/spec_legacy/fixtures/mail_handler/ticket_with_long_subject.eml b/spec/fixtures/mail_handler/wp_with_long_subject.eml
similarity index 98%
rename from spec_legacy/fixtures/mail_handler/ticket_with_long_subject.eml
rename to spec/fixtures/mail_handler/wp_with_long_subject.eml
index 7912c196756..9b837af07da 100644
--- a/spec_legacy/fixtures/mail_handler/ticket_with_long_subject.eml
+++ b/spec/fixtures/mail_handler/wp_with_long_subject.eml
@@ -4,7 +4,7 @@ Received: from osiris ([127.0.0.1])
with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200
Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris>
From: "John Smith" <[email protected]>
Subject: New ticket on a given project with a very long subject line which exceeds 255 chars and should not be ignored but chopped off. And if the subject line is still not long enough, we just add more text. And more text. Wow, this is really annoying. Especially, if you have nothing to say...
Date: Sun, 22 Jun 2008 12:28:07 +0200
MIME-Version: 1.0
diff --git a/spec_legacy/fixtures/mail_handler/fullname_of_sender_as_utf8_encoded.eml b/spec/fixtures/mail_handler/wp_with_utf8_fullname_of_sender.eml
similarity index 100%
rename from spec_legacy/fixtures/mail_handler/fullname_of_sender_as_utf8_encoded.eml
rename to spec/fixtures/mail_handler/wp_with_utf8_fullname_of_sender.eml
diff --git a/spec/models/mail_handler_spec.rb b/spec/models/mail_handler_spec.rb
index 5ccc3708116..6cce261b9f3 100644
--- a/spec/models/mail_handler_spec.rb
+++ b/spec/models/mail_handler_spec.rb
@@ -316,6 +316,29 @@ describe MailHandler, type: :model do
end
end
+ shared_context 'with a new work package with attributes in japanese' do
+ let(:permissions) { %i[add_work_packages] }
+ let!(:user) do
+ create(:user,
+ firstname: 'John',
+ lastname: 'Smith',
+ member_in_project: project,
+ member_with_permissions: permissions)
+ end
+ let!(:japanese_type) do
+ create(:type,
+ name: '開発').tap do |type|
+ project.types << type
+ end
+ end
+ let(:submit_options) { {} }
+
+ subject do
+ submit_email('wp_with_attributes_japanese.eml', **submit_options)
+ end
+ end
+
shared_context 'with a new work package with attachment' do
# The edit_work_packages is currently wrongfully needed as the work package
# is created first and only then the attachment is added.
@@ -425,6 +448,73 @@ describe MailHandler, type: :model do
end
end
+ shared_context 'with a new work package with iso 8859 1 subject' do
+ let(:permissions) { %i[add_work_packages] }
+ let!(:user) do
+ create(:user,
+ firstname: 'John',
+ lastname: 'Smith',
+ language: 'de',
+ member_in_project: project,
+ member_with_permissions: permissions)
+ end
+ let(:submit_options) { {} }
+
+ subject do
+ submit_email('wp_with_iso_8859_1_subject.eml', **submit_options)
+ end
+ end
+
+ shared_context 'with a new work package with long subject' do
+ let(:permissions) { %i[add_work_packages] }
+ let!(:user) do
+ create(:user,
+ firstname: 'John',
+ lastname: 'Smith',
+ language: 'de',
+ member_in_project: project,
+ member_with_permissions: permissions)
+ end
+ let(:submit_options) { {} }
+
+ subject do
+ submit_email('wp_with_long_subject.eml', **submit_options)
+ end
+ end
+
+ shared_context 'with a new work package with html only description' do
+ let(:permissions) { %i[add_work_packages] }
+ let!(:user) do
+ create(:user,
+ firstname: 'John',
+ lastname: 'Smith',
+ language: 'de',
+ member_in_project: project,
+ member_with_permissions: permissions)
+ end
+ let(:submit_options) { {} }
+
+ subject do
+ submit_email('wp_with_html_only_description.eml', **submit_options)
+ end
+ end
+
+ shared_context 'with a new work package with the sender fullname in utf-8' do
+ let(:submit_options) { {} }
+
+ before do
+ Role.non_member.update_attribute :permissions, [:add_work_packages]
+ project.update_attribute :public, true
+ end
+
+ subject do
+ submit_email('wp_with_utf8_fullname_of_sender.eml', **submit_options)
+ end
+ end
+
describe '#receive' do
shared_examples_for 'work package created' do
it 'creates the work package' do
@@ -621,6 +711,22 @@ describe MailHandler, type: :model do
end
end
+ context 'with unknown_user: \'create\' and an utf8 encoded fullname' do
+ include_context 'with a new work package with the sender fullname in utf-8'
+ let(:submit_options) { { issue: { project: 'onlinestore' }, unknown_user: 'create' } }
+
+ it_behaves_like 'work package created'
+
+ it 'adds the user with decoded fullname' do
+ expect do
+ expect(subject.author).to be_active
+ expect(subject.author.mail).to eq('[email protected]')
+ expect(subject.author.firstname).to eq("\xc3\x84\xc3\xa4".force_encoding('UTF-8'))
+ expect(subject.author.lastname).to eq("\xc3\x96\xc3\xb6".force_encoding('UTF-8'))
+ end.to change(User, :count).by(1)
+ end
+ end
+
context 'with unknown_user: nil (default)' do
let(:results) { [] }
@@ -917,6 +1023,18 @@ describe MailHandler, type: :model do
end
end
+ context 'for a wp overriding attributes in japanese' do
+ include_context 'with a new work package with attributes in japanese'
+ let(:submit_options) { { issue: { project: 'onlinestore' }, allow_override: 'type' } }
+
+ it_behaves_like 'work package created'
+
+ it 'sets the provided attributes' do
+ expect(subject.type)
+ .to eql japanese_type
+ end
+ end
+
context 'for a wp with attachment' do
include_context 'with a new work package with attachment'
let(:submit_options) { { issue: { project: 'onlinestore' } } }
@@ -1018,6 +1136,49 @@ describe MailHandler, type: :model do
.to eql urgent_priority
end
end
+
+ context 'for a wp with iso 8859 1 subject' do
+ include_context 'with a new work package with iso 8859 1 subject'
+ let(:submit_options) { { issue: { project: 'onlinestore' } } }
+
+ it_behaves_like 'work package created'
+
+ it 'sets the subject' do
+ expect(subject.subject)
+ .to eql 'Testmail from Webmail: ä ö ü...'
+ end
+ end
+
+ context 'for a wp with long subject' do
+ include_context 'with a new work package with long subject'
+ let(:submit_options) { { issue: { project: 'onlinestore' } } }
+
+ it_behaves_like 'work package created'
+
+ it 'sets the subject' do
+ original_subject = <<~MSG.squish
+ New ticket on a given project with a very long subject line
+ which exceeds 255 chars and should not be ignored but chopped off.
+ And if the subject line is still not long enough, we just add more text.
+ And more text. Wow, this is really annoying. Especially, if you have nothing to say...
+ MSG
+
+ expect(subject.subject)
+ .to eql original_subject[0, 255]
+ end
+ end
+
+ context 'for a wp with html only description' do
+ include_context 'with a new work package with html only description'
+ let(:submit_options) { { issue: { project: 'onlinestore' } } }
+
+ it_behaves_like 'work package created'
+
+ it 'sets the description' do
+ expect(subject.description)
+ .to eql 'This is a html-only email.'
+ end
+ end
end
context 'when sending a reply to work package mail' do
@@ -1359,6 +1520,66 @@ describe MailHandler, type: :model do
end
end
+ describe '.new_user_from_attributes' do
+ context 'with sufficient information' do
+ # [address, name] => [login, firstname, lastname]
+ {
+ ['[email protected]', nil] => %w[[email protected] jsmith -],
+ %w[[email protected] John] => %w[[email protected] John -],
+ ['[email protected]', 'John Smith'] => %w[[email protected] John Smith],
+ ['[email protected]', 'John Paul Smith'] => ['[email protected]', 'John', 'Paul Smith'],
+ ['[email protected]', 'AVeryLongFirstnameThatNoLongerExceedsTheMaximumLength Smith'] =>
+ %w[[email protected] AVeryLongFirstnameThatNoLongerExceedsTheMaximumLength Smith],
+ ['[email protected]', 'John AVeryLongLastnameThatNoLongerExceedsTheMaximumLength'] =>
+ %w[[email protected] John AVeryLongLastnameThatNoLongerExceedsTheMaximumLength]
+ }.each do |(provided_mail, provided_fullname), (expected_login, expected_firstname, expected_lastname)|
+ it 'returns a valid user' do
+ user = described_class.new_user_from_attributes(provided_mail, provided_fullname)
+
+ expect(user)
+ .to be_valid
+ expect(user.mail)
+ .to eq provided_mail
+ expect(user.login)
+ .to eq expected_login
+ expect(user.firstname)
+ .to eq expected_firstname
+ expect(user.lastname)
+ .to eq expected_lastname
+ end
+ end
+ end
+
+ context 'with min password length',
+ with_legacy_settings: { password_min_length: 15 } do
+ it 'respects minimum password length' do
+ user = described_class.new_user_from_attributes('[email protected]')
+
+ expect(user)
+ .to be_valid
+
+ expect(user.password.length)
+ .to be 15
+ end
+ end
+
+ context 'when the attributes are invalid',
+ with_legacy_settings: { password_min_length: 15 } do
+ it 'respects minimum password length' do
+ user = described_class.new_user_from_attributes('foo&[email protected]')
+
+ expect(user)
+ .to be_valid
+
+ expect(user.login)
+ .to match /^user[a-f0-9]+$/
+
+ expect(user.mail)
+ .to eq 'foo&[email protected]'
+ end
+ end
+ end
+
private
def read_email(filename)
diff --git a/spec_legacy/fixtures/mail_handler/issue_update_with_multiple_quoted_reply_above.eml b/spec_legacy/fixtures/mail_handler/issue_update_with_multiple_quoted_reply_above.eml
deleted file mode 100644
index 4db4ab891b8..00000000000
--- a/spec_legacy/fixtures/mail_handler/issue_update_with_multiple_quoted_reply_above.eml
+++ /dev/null
@@ -1,48 +0,0 @@
-Return-Path: <[email protected]>
-Received: from osiris ([127.0.0.1])
- by OSIRIS
- with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200
-Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris>
-In-Reply-To: <openproject.issue-1-2.20060719210421@osiris>
-From: "John Smith" <[email protected]>
-Subject: Re: update to issue 2
-Date: Sun, 22 Jun 2008 12:28:07 +0200
-MIME-Version: 1.0
-Content-Type: text/plain;
- format=flowed;
- charset="iso-8859-1";
- reply-type=original
-Content-Transfer-Encoding: 7bit
-X-Priority: 3
-X-MSMail-Priority: Normal
-X-Mailer: Microsoft Outlook Express 6.00.2900.2869
-X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
-
-An update to the issue by the sender.
-
-Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas imperdiet
-turpis et odio. Integer eget pede vel dolor euismod varius. Phasellus
-blandit eleifend augue. Nulla facilisi. Duis id diam. Class aptent taciti
-sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In
-in urna sed tellus aliquet lobortis. Morbi scelerisque tortor in dolor. Cras
-sagittis odio eu lacus. Aliquam sem tortor, consequat sit amet, vestibulum
-id, iaculis at, lectus. Fusce tortor libero, congue ut, euismod nec, luctus
-eget, eros. Pellentesque tortor enim, feugiat in, dignissim eget, tristique
-sed, mauris --- Pellentesque habitant morbi tristique senectus et netus et
-malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse
-platea dictumst.
-
->> > --- Reply above. Do not remove this line. ---
->> >
->> > Issue #6779 has been updated by Eric Davis.
->> >
->> > Subject changed from Projects with JSON to Project JSON API
->> > Status changed from New to Assigned
->> > Assignee set to Eric Davis
->> > Priority changed from Low to Normal
->> > Estimated time deleted (1.00)
->> >
->> > Looks like the JSON api for projects was missed. I'm going to be
->> > reviewing the existing APIs and trying to clean them up over the next
->> > few weeks.
diff --git a/spec_legacy/fixtures/mail_handler/issue_update_with_quoted_reply_above.eml b/spec_legacy/fixtures/mail_handler/issue_update_with_quoted_reply_above.eml
deleted file mode 100644
index 4b0cb9dd507..00000000000
--- a/spec_legacy/fixtures/mail_handler/issue_update_with_quoted_reply_above.eml
+++ /dev/null
@@ -1,48 +0,0 @@
-Return-Path: <[email protected]>
-Received: from osiris ([127.0.0.1])
- by OSIRIS
- with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200
-Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris>
-In-Reply-To: <openproject.issue-1-2.20060719210421@osiris>
-From: "John Smith" <[email protected]>
-Subject: Re: update to issue 2
-Date: Sun, 22 Jun 2008 12:28:07 +0200
-MIME-Version: 1.0
-Content-Type: text/plain;
- format=flowed;
- charset="iso-8859-1";
- reply-type=original
-Content-Transfer-Encoding: 7bit
-X-Priority: 3
-X-MSMail-Priority: Normal
-X-Mailer: Microsoft Outlook Express 6.00.2900.2869
-X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
-
-An update to the issue by the sender.
-
-Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas imperdiet
-turpis et odio. Integer eget pede vel dolor euismod varius. Phasellus
-blandit eleifend augue. Nulla facilisi. Duis id diam. Class aptent taciti
-sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In
-in urna sed tellus aliquet lobortis. Morbi scelerisque tortor in dolor. Cras
-sagittis odio eu lacus. Aliquam sem tortor, consequat sit amet, vestibulum
-id, iaculis at, lectus. Fusce tortor libero, congue ut, euismod nec, luctus
-eget, eros. Pellentesque tortor enim, feugiat in, dignissim eget, tristique
-sed, mauris --- Pellentesque habitant morbi tristique senectus et netus et
-malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse
-platea dictumst.
-
-> --- Reply above. Do not remove this line. ---
->
-> Issue #6779 has been updated by Eric Davis.
->
-> Subject changed from Projects with JSON to Project JSON API
-> Status changed from New to Assigned
-> Assignee set to Eric Davis
-> Priority changed from Low to Normal
-> Estimated time deleted (1.00)
->
-> Looks like the JSON api for projects was missed. I'm going to be
-> reviewing the existing APIs and trying to clean them up over the next
-> few weeks.
diff --git a/spec_legacy/fixtures/mail_handler/ticket_by_unknown_user.eml b/spec_legacy/fixtures/mail_handler/ticket_by_unknown_user.eml
deleted file mode 100644
index c5854769112..00000000000
--- a/spec_legacy/fixtures/mail_handler/ticket_by_unknown_user.eml
+++ /dev/null
@@ -1,18 +0,0 @@
-Return-Path: <[email protected]>
-Received: from osiris ([127.0.0.1])
- by OSIRIS
- with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200
-Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris>
-From: "John Doe" <[email protected]>
-Subject: Ticket by unknown user
-Date: Sun, 22 Jun 2008 12:28:07 +0200
-MIME-Version: 1.0
-Content-Type: text/plain;
- format=flowed;
- charset="iso-8859-1";
- reply-type=original
-Content-Transfer-Encoding: 7bit
-
-This is a ticket submitted by an unknown user.
-
diff --git a/spec_legacy/fixtures/mail_handler/ticket_on_given_project.eml b/spec_legacy/fixtures/mail_handler/ticket_on_given_project.eml
deleted file mode 100644
index 34166bf7888..00000000000
--- a/spec_legacy/fixtures/mail_handler/ticket_on_given_project.eml
+++ /dev/null
@@ -1,60 +0,0 @@
-Return-Path: <[email protected]>
-Received: from osiris ([127.0.0.1])
- by OSIRIS
- with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200
-Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris>
-From: "John Smith" <[email protected]>
-Subject: New ticket on a given project
-Date: Sun, 22 Jun 2008 12:28:07 +0200
-MIME-Version: 1.0
-Content-Type: text/plain;
- format=flowed;
- charset="iso-8859-1";
- reply-type=original
-Content-Transfer-Encoding: 7bit
-X-Priority: 3
-X-MSMail-Priority: Normal
-X-Mailer: Microsoft Outlook Express 6.00.2900.2869
-X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
-
-Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas imperdiet
-turpis et odio. Integer eget pede vel dolor euismod varius. Phasellus
-blandit eleifend augue. Nulla facilisi. Duis id diam. Class aptent taciti
-sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In
-in urna sed tellus aliquet lobortis. Morbi scelerisque tortor in dolor. Cras
-sagittis odio eu lacus. Aliquam sem tortor, consequat sit amet, vestibulum
-id, iaculis at, lectus. Fusce tortor libero, congue ut, euismod nec, luctus
-eget, eros. Pellentesque tortor enim, feugiat in, dignissim eget, tristique
-sed, mauris --- Pellentesque habitant morbi tristique senectus et netus et
-malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse
-platea dictumst.
-
---- This line starts with a delimiter and should not be stripped
-
-This paragraph is before delimiters.
-
-BREAK
-
-This paragraph is between delimiters.
-
----
-
-This paragraph is after the delimiter so it shouldn't appear.
-
-Nulla et nunc. Duis pede. Donec et ipsum. Nam ut dui tincidunt neque
-sollicitudin iaculis. Duis vitae dolor. Vestibulum eget massa. Sed lorem.
-Nullam volutpat cursus erat. Cras felis dolor, lacinia quis, rutrum et,
-dictum et, ligula. Sed erat nibh, gravida in, accumsan non, placerat sed,
-massa. Sed sodales, ante fermentum ultricies sollicitudin, massa leo
-pulvinar dui, a gravida orci mi eget odio. Nunc a lacus.
-
-Project: onlinestore
-Status: Resolved
-due date: 2010-12-31
-Start Date:2010-01-01
-Assigned to: John Smith
-version: alpha
-estimated hours: 2.5
-done ratio: 30
-
diff --git a/spec_legacy/unit/mail_handler_spec.rb b/spec_legacy/unit/mail_handler_spec.rb
deleted file mode 100644
index 92e3c82a1f5..00000000000
--- a/spec_legacy/unit/mail_handler_spec.rb
+++ /dev/null
@@ -1,143 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2022 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-require_relative '../legacy_spec_helper'
-
-describe MailHandler, type: :model, with_settings: { report_incoming_email_errors: false } do
- fixtures :all
-
- FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
-
- it 'adds work package with japanese keywords' do
- type = ::Type.create!(name: '開発')
- Project.find(1).types << type
- issue = submit_email('japanese_keywords_iso_2022_jp.eml', issue: { project: 'ecookbook' }, allow_override: 'type')
- assert_kind_of WorkPackage, issue
- assert_equal type, issue.type
- end
-
- it 'adds work package with iso 8859 1 subject' do
- issue = submit_email(
- 'subject_as_iso-8859-1.eml',
- issue: { project: 'ecookbook' }
- )
- assert_kind_of WorkPackage, issue
- assert_equal 'Testmail from Webmail: ä ö ü...', issue.subject
- end
-
- it 'strips tags of html only emails' do
- issue = submit_email('ticket_html_only.eml', issue: { project: 'ecookbook' })
- assert issue.is_a?(WorkPackage)
- assert !issue.new_record?
- issue.reload
- assert_equal 'HTML email', issue.subject
- assert_equal 'This is a html-only email.', issue.description
- end
-
- it 'emails with long subject line' do
- issue = submit_email('ticket_with_long_subject.eml')
- assert issue.is_a?(WorkPackage)
- assert_equal issue.subject,
- 'New ticket on a given project with a very long subject line which exceeds 255 chars and should not be ignored but chopped off. And if the subject line is still not long enough, we just add more text. And more text. Wow, this is really annoying. Especially, if you have nothing to say...'[
-0, 255]
- end
-
- it 'news user from attributes should return valid user' do
- to_test = {
- # [address, name] => [login, firstname, lastname]
- ['[email protected]', nil] => ['[email protected]', 'jsmith', '-'],
- ['[email protected]', 'John'] => ['[email protected]', 'John', '-'],
- ['[email protected]', 'John Smith'] => ['[email protected]', 'John', 'Smith'],
- ['[email protected]', 'John Paul Smith'] => ['[email protected]', 'John', 'Paul Smith'],
- 'AVeryLongFirstnameThatNoLongerExceedsTheMaximumLength Smith'] => ['[email protected]',
- 'AVeryLongFirstnameThatNoLongerExceedsTheMaximumLength', 'Smith'],
- 'John AVeryLongLastnameThatNoLongerExceedsTheMaximumLength'] => ['[email protected]', 'John',
- 'AVeryLongLastnameThatNoLongerExceedsTheMaximumLength']
- }
-
- to_test.each do |attrs, expected|
- user = MailHandler.new_user_from_attributes(attrs.first, attrs.last)
-
- assert user.valid?, user.errors.full_messages.to_s
- assert_equal attrs.first, user.mail
- assert_equal expected[0], user.login
- assert_equal expected[1], user.firstname
- assert_equal expected[2], user.lastname
- end
- end
-
- context 'with min password length',
- with_legacy_settings: { password_min_length: 15 } do
- it 'news user from attributes should respect minimum password length' do
- user = MailHandler.new_user_from_attributes('[email protected]')
- assert user.valid?
- assert user.password.length >= 15
- end
- end
-
- it 'news user from attributes should use default login if invalid' do
- user = MailHandler.new_user_from_attributes('foo&[email protected]')
- assert user.valid?
- assert user.login =~ /^user[a-f0-9]+$/
- assert_equal 'foo&[email protected]', user.mail
- end
-
- it 'news user with utf8 encoded fullname should be decoded' do
- assert_difference 'User.count' do
- issue = submit_email(
- 'fullname_of_sender_as_utf8_encoded.eml',
- issue: { project: 'ecookbook' },
- unknown_user: 'create'
- )
- end
-
- user = User.order('id DESC').first
- assert_equal '[email protected]', user.mail
- str1 = "\xc3\x84\xc3\xa4"
- str2 = "\xc3\x96\xc3\xb6"
- str1.force_encoding('UTF-8') if str1.respond_to?(:force_encoding)
- str2.force_encoding('UTF-8') if str2.respond_to?(:force_encoding)
- assert_equal str1, user.firstname
- assert_equal str2, user.lastname
- end
-
- private
-
- def submit_email(filename, options = {})
- raw = IO.read(File.join(FIXTURES_PATH, filename))
- yield raw if block_given?
- MailHandler.receive(raw, options)
- end
-
- def assert_issue_created(issue)
- assert issue.is_a?(WorkPackage)
- assert !issue.new_record?
- issue.reload
- end
-end