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

ulfertsde8ca66f9888
diff --git a/spec_legacy/fixtures/mail_handler/ticket_with_attachment.eml b/spec/fixtures/mail_handler/wp_with_attachment.eml
similarity index 99%
rename from spec_legacy/fixtures/mail_handler/ticket_with_attachment.eml
rename to spec/fixtures/mail_handler/wp_with_attachment.eml
index 230823f966c..6e0f69ce3e1 100644
--- a/spec_legacy/fixtures/mail_handler/ticket_with_attachment.eml
+++ b/spec/fixtures/mail_handler/wp_with_attachment.eml
@@ -4,7 +4,7 @@ Received: from osiris ([127.0.0.1])
with hMailServer ; Sat, 21 Jun 2008 15:53:25 +0200
Message-ID: <002301c8d3a6$2cdf6950$0a00a8c0@osiris>
From: "John Smith" <[email protected]>
Subject: Ticket created by email with attachment
Date: Sat, 21 Jun 2008 15:53:25 +0200
MIME-Version: 1.0
diff --git a/spec_legacy/fixtures/mail_handler/ticket_with_attributes.eml b/spec/fixtures/mail_handler/wp_with_attributes.eml
similarity index 98%
rename from spec_legacy/fixtures/mail_handler/ticket_with_attributes.eml
rename to spec/fixtures/mail_handler/wp_with_attributes.eml
index 22ec6361bcb..7bcfe9df134 100644
--- a/spec_legacy/fixtures/mail_handler/ticket_with_attributes.eml
+++ b/spec/fixtures/mail_handler/wp_with_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_spaces_between_attribute_and_separator.eml b/spec/fixtures/mail_handler/wp_with_spaces_between_attribute_and_separator.eml
similarity index 98%
rename from spec_legacy/fixtures/mail_handler/ticket_with_spaces_between_attribute_and_separator.eml
rename to spec/fixtures/mail_handler/wp_with_spaces_between_attribute_and_separator.eml
index ba3dcfa89d6..0330669dc6e 100644
--- a/spec_legacy/fixtures/mail_handler/ticket_with_spaces_between_attribute_and_separator.eml
+++ b/spec/fixtures/mail_handler/wp_with_spaces_between_attribute_and_separator.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 0250e3fd059..8d27f8c40d4 100644
--- a/spec/models/mail_handler_spec.rb
+++ b/spec/models/mail_handler_spec.rb
@@ -252,6 +252,89 @@ describe MailHandler, type: :model do
end
end
+ shared_context 'with a new work package with attributes' do
+ let(:permissions) { %i[add_work_packages assign_versions work_package_assigned] }
+ let!(:user) do
+ create(:user,
+ firstname: 'John',
+ lastname: 'Smith',
+ member_in_project: project,
+ member_with_permissions: permissions)
+ end
+ 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
+ let!(:high_priority) do
+ create(:priority_high)
+ end
+ let(:submit_options) { {} }
+
+ subject do
+ submit_email('wp_with_attributes.eml', **submit_options)
+ end
+ end
+
+ shared_context 'with a new work package with attributes with additional spaces' do
+ let(:permissions) { %i[add_work_packages assign_versions work_package_assigned] }
+ let!(:user) do
+ create(:user,
+ firstname: 'John',
+ lastname: 'Smith',
+ member_in_project: project,
+ member_with_permissions: permissions)
+ end
+ 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
+ let!(:high_priority) do
+ create(:priority_high)
+ end
+ let(:submit_options) { {} }
+
+ subject do
+ submit_email('wp_with_spaces_between_attribute_and_separator.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.
+ 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.eml', **submit_options)
+ end
+ end
+
describe '#receive' do
shared_examples_for 'work package created' do
it 'creates the work package' do
@@ -680,6 +763,90 @@ describe MailHandler, type: :model do
.to match_array([user, cc_user])
end
end
+
+ context 'for a wp overriding attributes' do
+ include_context 'with a new work package with 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
+
+ context 'for a wp overriding attributes partially' do
+ include_context 'with a new work package with attributes'
+ let(:submit_options) { { issue: { priority: 'High' }, allow_override: ['type'] } }
+
+ it_behaves_like 'work package created'
+
+ it 'sets the provided attributes only to the extend allowed and uses default' do
+ expect(subject.project)
+ .to eql project
+
+ expect(subject.type)
+ .to eql feature_type
+
+ expect(subject.category)
+ .to be_nil
+
+ expect(subject.priority)
+ .to eql high_priority
+ end
+ end
+
+ context 'for a wp overriding attributes with spaces between attribute and separator' do
+ include_context 'with a new work package with attributes with additional spaces'
+ 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
+
+ context 'for a wp with attachment' do
+ include_context 'with a new work package with attachment'
+ 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
end
context 'when sending a reply to work package mail' do
diff --git a/spec_legacy/unit/mail_handler_spec.rb b/spec_legacy/unit/mail_handler_spec.rb
index ce150c623b7..99d904c1f44 100644
--- a/spec_legacy/unit/mail_handler_spec.rb
+++ b/spec_legacy/unit/mail_handler_spec.rb
@@ -32,64 +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 attributes override' do
- issue = submit_email('ticket_with_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 partial attributes override' do
- issue = submit_email('ticket_with_attributes.eml', issue: { priority: 'High' }, allow_override: ['type'])
- 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_nil issue.category
- assert_equal 'High', issue.priority.to_s
- assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
- end
-
- it 'adds work package with spaces between attribute and separator' do
- issue = submit_email('ticket_with_spaces_between_attribute_and_separator.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 attachment to specific project' do
- issue = submit_email('ticket_with_attachment.eml', issue: { project: 'onlinestore' })
- assert issue.is_a?(WorkPackage)
- assert !issue.new_record?
- issue.reload
- assert_equal 'Ticket created by email with attachment', issue.subject
- assert_equal User.find_by_login('jsmith'), issue.author
- assert_equal Project.find(2), issue.project
- assert_equal 'This is a new ticket with attachments', issue.description
- # Attachment properties
- assert_equal 1, issue.attachments.size
- assert_equal 'Paella.jpg', issue.attachments.first.filename
- assert_equal 'image/jpeg', issue.attachments.first.content_type
- assert_equal 10790, issue.attachments.first.filesize
- end
-
it 'adds work package with custom fields' do
issue = submit_email('ticket_with_custom_fields.eml', issue: { project: 'onlinestore' })
assert issue.is_a?(WorkPackage)