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

ulfertsc0bd8b531c3b
diff --git a/spec_legacy/fixtures/mail_handler/apple_mail_with_attachment.eml b/spec/fixtures/mail_handler/wp_with_attachment_apple.eml
similarity index 99%
rename from spec_legacy/fixtures/mail_handler/apple_mail_with_attachment.eml
rename to spec/fixtures/mail_handler/wp_with_attachment_apple.eml
index 3f54a6241b1..48de5647bcc 100644
--- a/spec_legacy/fixtures/mail_handler/apple_mail_with_attachment.eml
+++ b/spec/fixtures/mail_handler/wp_with_attachment_apple.eml
@@ -1,13 +1,13 @@
From [email protected] Mon Jun 27 06:55:56 2011
Return-Path: <[email protected]>
-X-Original-To: [email protected]
-Delivered-To: [email protected]
+X-Original-To: [email protected]
+Delivered-To: [email protected]
From: John Smith <[email protected]>
Mime-Version: 1.0 (Apple Message framework v1084)
Content-Type: multipart/alternative; boundary=Apple-Mail-3-163265085
Subject: Test attaching images to tickets by HTML mail
Date: Mon, 27 Jun 2011 16:55:46 +0300
Message-Id: <[email protected]>
X-Mailer: Apple Mail (2.1084)
diff --git a/spec_legacy/fixtures/mail_handler/ticket_with_custom_fields.eml b/spec/fixtures/mail_handler/wp_with_custom_field.eml
similarity index 98%
rename from spec_legacy/fixtures/mail_handler/ticket_with_custom_fields.eml
rename to spec/fixtures/mail_handler/wp_with_custom_field.eml
index df2e7a48db2..83403710834 100644
--- a/spec_legacy/fixtures/mail_handler/ticket_with_custom_fields.eml
+++ b/spec/fixtures/mail_handler/wp_with_custom_field.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 with custom field values
Date: Sun, 22 Jun 2008 12:28:07 +0200
MIME-Version: 1.0
diff --git a/spec_legacy/fixtures/mail_handler/ticket_with_invalid_attributes.eml b/spec/fixtures/mail_handler/wp_with_invalid_attributes.eml
similarity index 98%
rename from spec_legacy/fixtures/mail_handler/ticket_with_invalid_attributes.eml
rename to spec/fixtures/mail_handler/wp_with_invalid_attributes.eml
index f762a797616..8e6569a4a23 100644
--- a/spec_legacy/fixtures/mail_handler/ticket_with_invalid_attributes.eml
+++ b/spec/fixtures/mail_handler/wp_with_invalid_attributes.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
Date: Sun, 22 Jun 2008 12:28:07 +0200
MIME-Version: 1.0
diff --git a/spec_legacy/fixtures/mail_handler/ticket_with_localized_attributes.eml b/spec/fixtures/mail_handler/wp_with_localized_attributes.eml
similarity index 98%
rename from spec_legacy/fixtures/mail_handler/ticket_with_localized_attributes.eml
rename to spec/fixtures/mail_handler/wp_with_localized_attributes.eml
index 56d539719e4..6a9088e1e6f 100644
--- a/spec_legacy/fixtures/mail_handler/ticket_with_localized_attributes.eml
+++ b/spec/fixtures/mail_handler/wp_with_localized_attributes.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
Date: Sun, 22 Jun 2008 12:28:07 +0200
MIME-Version: 1.0
diff --git a/spec/models/mail_handler_spec.rb b/spec/models/mail_handler_spec.rb
index 8d27f8c40d4..5ccc3708116 100644
--- a/spec/models/mail_handler_spec.rb
+++ b/spec/models/mail_handler_spec.rb
@@ -335,6 +335,96 @@ describe MailHandler, type: :model do
end
end
+ shared_context 'with a new work package with attachment in apple format' do
+ # The edit_work_packages is currently wrongfully needed as the work package
+ # is created first and only then the attachment is added.
+ let(:permissions) { %i[add_work_packages edit_work_packages] }
+ let!(:user) do
+ create(:user,
+ firstname: 'John',
+ lastname: 'Smith',
+ member_in_project: project,
+ member_with_permissions: permissions)
+ end
+ let(:submit_options) { {} }
+
+ subject do
+ submit_email('wp_with_attachment_apple.eml', **submit_options)
+ end
+ end
+
+ shared_context 'with a new work package with a custom field' 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!(:custom_field) do
+ create(:string_wp_custom_field, name: 'Searchable field').tap do |cf|
+ project.work_package_custom_fields << cf
+ project.types.first.custom_fields << cf
+ end
+ end
+ let(:submit_options) { {} }
+
+ subject do
+ submit_email('wp_with_custom_field.eml', **submit_options)
+ end
+ end
+
+ shared_context 'with a new work package with invalid attributes' 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(:submit_options) { {} }
+
+ subject do
+ submit_email('wp_with_invalid_attributes.eml', **submit_options)
+ end
+ end
+
+ shared_context 'with a new work package with localized attributes' 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) { {} }
+
+ let!(:feature_type) do
+ create(:type,
+ name: 'Feature request').tap do |type|
+ project.types << type
+ end
+ end
+ let!(:stock_category) do
+ project.categories.create(name: 'Stock management')
+ end
+ let!(:urgent_priority) do
+ create(:priority_urgent)
+ end
+
+ subject do
+ submit_email('wp_with_localized_attributes.eml', **submit_options)
+ end
+ end
+
describe '#receive' do
shared_examples_for 'work package created' do
it 'creates the work package' do
@@ -847,6 +937,87 @@ describe MailHandler, type: :model do
.to be 10790
end
end
+
+ context 'for a wp with attachment in apple format' do
+ include_context 'with a new work package with attachment in apple format'
+ let(:submit_options) { { issue: { project: 'onlinestore' } } }
+
+ it_behaves_like 'work package created'
+
+ it 'adds the attachment' do
+ expect(subject.attachments.count)
+ .to be 1
+
+ expect(subject.attachments.first.filename)
+ .to eql 'paella.jpg'
+
+ expect(subject.attachments.first.content_type)
+ .to eql 'image/jpeg'
+
+ expect(subject.attachments.first.filesize)
+ .to be 10790
+ end
+ end
+
+ context 'for a wp with a custom field value' do
+ include_context 'with a new work package with a custom field'
+ let(:submit_options) { { issue: { project: 'onlinestore' } } }
+
+ it_behaves_like 'work package created'
+
+ it 'sets the custom field value and removes it from the text' do
+ expect(subject.custom_value_attributes)
+ .to eql(custom_field.id => 'Value for a custom field')
+
+ expect(subject.description)
+ .not_to include 'searchable field'
+ end
+ end
+
+ context 'for a wp with invalid attributes' do
+ include_context 'with a new work package with invalid attributes'
+ let(:submit_options) { { issue: { project: 'onlinestore' }, allow_override: 'type,category,priority' } }
+
+ it_behaves_like 'work package created'
+
+ it 'ignores the invalid attributes and set default ones where possible' do
+ expect(subject.assigned_to)
+ .to be_nil
+
+ expect(subject.start_date)
+ .to be_nil
+
+ expect(subject.due_date)
+ .to be_nil
+
+ expect(subject.done_ratio)
+ .to be 0
+
+ expect(subject.priority)
+ .to eql priority_low
+ end
+ end
+
+ context 'for a wp with localized attributes' do
+ include_context 'with a new work package with localized attributes'
+ let(:submit_options) { { allow_override: 'type,category,priority' } }
+
+ it_behaves_like 'work package created'
+
+ it 'sets the provided attributes' do
+ expect(subject.project)
+ .to eql project
+
+ expect(subject.type)
+ .to eql feature_type
+
+ expect(subject.category)
+ .to eql stock_category
+
+ expect(subject.priority)
+ .to eql urgent_priority
+ end
+ end
end
context 'when sending a reply to work package mail' do
@@ -1021,6 +1192,30 @@ describe MailHandler, type: :model do
end
end
end
+
+ context 'when receiving an auto reply' do
+ include_context 'with a reply to a wp mention with quotes above' do
+ [
+ 'X-Auto-Response-Suppress: OOF',
+ 'Auto-Submitted: auto-replied',
+ 'Auto-Submitted: Auto-Replied',
+ 'Auto-Submitted: auto-generated'
+ ].each do |header|
+ subject do
+ raw = File.read(File.join("#{File.dirname(__FILE__)}/../fixtures/mail_handler",
+ 'wp_reply_with_quoted_reply_above.eml'))
+ raw = "#{header}\n#{raw}"
+
+ described_class.receive(raw)
+ end
+
+ it 'does not update the work package' do
+ expect { subject }
+ .not_to change(Journal, :count)
+ end
+ end
+ end
+ end
end
context 'when sending a reply to a message mail' do
diff --git a/spec_legacy/unit/mail_handler_spec.rb b/spec_legacy/unit/mail_handler_spec.rb
index 99d904c1f44..92e3c82a1f5 100644
--- a/spec_legacy/unit/mail_handler_spec.rb
+++ b/spec_legacy/unit/mail_handler_spec.rb
@@ -32,47 +32,6 @@ describe MailHandler, type: :model, with_settings: { report_incoming_email_error
FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
- it 'adds work package with custom fields' do
- issue = submit_email('ticket_with_custom_fields.eml', issue: { project: 'onlinestore' })
- assert issue.is_a?(WorkPackage)
- assert !issue.new_record?
- issue.reload
- assert_equal 'New ticket with custom field values', issue.subject
- assert_equal 'Value for a custom field', issue.custom_value_for(CustomField.find_by(name: 'Searchable field')).value
- assert !issue.description.match(/^searchable field:/i)
- end
-
- context 'without default start_date', with_legacy_settings: { work_package_startdate_is_adddate: false } do
- it 'adds work package with invalid attributes' do
- issue = submit_email('ticket_with_invalid_attributes.eml', allow_override: 'type,category,priority')
- assert issue.is_a?(WorkPackage)
- assert !issue.new_record?
- issue.reload
- assert_nil issue.assigned_to
- assert_nil issue.start_date
- assert_nil issue.due_date
- assert_equal 0, issue.done_ratio
- assert_equal 'Normal', issue.priority.to_s
- assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
- end
- end
-
- it 'adds work package with localized attributes' do
- User.find_by_mail('[email protected]').update_attribute 'language', 'de'
-
- issue = submit_email('ticket_with_localized_attributes.eml', allow_override: 'type,category,priority')
- assert issue.is_a?(WorkPackage)
- assert !issue.new_record?
- issue.reload
- assert_equal 'New ticket on a given project', issue.subject
- assert_equal User.find_by_login('jsmith'), issue.author
- assert_equal Project.find(2), issue.project
- assert_equal 'Feature request', issue.type.to_s
- assert_equal 'Stock management', issue.category.to_s
- assert_equal 'Urgent', issue.priority.to_s
- assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
- end
-
it 'adds work package with japanese keywords' do
type = ::Type.create!(name: '開発')
Project.find(1).types << type
@@ -81,22 +40,6 @@ describe MailHandler, type: :model, with_settings: { report_incoming_email_error
assert_equal type, issue.type
end
- it 'adds from apple mail' do
- issue = submit_email(
- 'apple_mail_with_attachment.eml',
- issue: { project: 'ecookbook' }
- )
- assert_kind_of WorkPackage, issue
- assert_equal 1, issue.attachments.size
-
- attachment = issue.attachments.first
- assert_equal 'paella.jpg', attachment.filename
- assert_equal 10790, attachment.filesize
- assert File.exist?(attachment.diskfile)
- assert_equal 10790, File.size(attachment.diskfile)
- assert_equal 'caaf384198bcbc9563ab5c058acd73cd', attachment.digest
- end
-
it 'adds work package with iso 8859 1 subject' do
issue = submit_email(
'subject_as_iso-8859-1.eml',
@@ -106,23 +49,6 @@ describe MailHandler, type: :model, with_settings: { report_incoming_email_error
assert_equal 'Testmail from Webmail: ä ö ü...', issue.subject
end
- it 'ignores auto replied emails' do
- expect_any_instance_of(MailHandler).not_to receive(:dispatch)
- [
- 'X-Auto-Response-Suppress: OOF',
- 'Auto-Submitted: auto-replied',
- 'Auto-Submitted: Auto-Replied',
- 'Auto-Submitted: auto-generated'
- ].each do |header|
- raw = IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
- raw = header + "\n" + raw
-
- assert_no_difference 'WorkPackage.count' do
- assert_equal false, MailHandler.receive(raw), "email with #{header} header was not ignored"
- end
- end
- end
-
it 'strips tags of html only emails' do
issue = submit_email('ticket_html_only.eml', issue: { project: 'ecookbook' })
assert issue.is_a?(WorkPackage)