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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
replace flickering legacy specs
ulferts325ccbc3636e
diff --git a/spec/fixtures/mail_handler/wp_on_given_project.eml b/spec/fixtures/mail_handler/wp_on_given_project.emlnew file mode 100644index 00000000000..1cf91d6e213--- /dev/null+++ b/spec/fixtures/mail_handler/wp_on_given_project.eml@@ -0,0 +1,60 @@+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]>+To: <[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+fixed version: alpha+estimated hours: 2.5+done ratio: 30+diff --git a/spec/fixtures/mail_handler/wp_update_with_multiple_quoted_reply_above.eml b/spec/fixtures/mail_handler/wp_update_with_multiple_quoted_reply_above.emlnew file mode 100644index 00000000000..988720200f3--- /dev/null+++ b/spec/fixtures/mail_handler/wp_update_with_multiple_quoted_reply_above.eml@@ -0,0 +1,48 @@+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-2.20060719210421@osiris>+From: "John Smith" <[email protected]>+To: <[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/fixtures/mail_handler/wp_update_with_quoted_reply_above.eml b/spec/fixtures/mail_handler/wp_update_with_quoted_reply_above.emlnew file mode 100644index 00000000000..b097b25c139--- /dev/null+++ b/spec/fixtures/mail_handler/wp_update_with_quoted_reply_above.eml@@ -0,0 +1,48 @@+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-2.20060719210421@osiris>+From: "John Smith" <[email protected]>+To: <[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/models/mail_handler_spec.rb b/spec/models/mail_handler_spec.rbindex f12ce04a6b9..7172cdd4cfa 100644--- a/spec/models/mail_handler_spec.rb+++ b/spec/models/mail_handler_spec.rb@@ -49,7 +49,77 @@ describe MailHandler, type: :model doallow(Setting).to receive(:default_language).and_return('en')end+ shared_context 'wp_on_given_project' do+ let(:permissions) { %i[add_work_packages] }+ let!(:user) do+ FactoryBot.create(:user,+ mail: '[email protected]',+ member_in_project: project,+ member_with_permissions: permissions)+ end++ subject do+ submit_email('wp_on_given_project.eml')+ end+ end++ shared_context 'wp_update_with_quoted_reply_above' do+ let(:permissions) { %i[edit_work_packages view_work_packages] }+ let!(:user) do+ FactoryBot.create(:user,+ mail: '[email protected]',+ member_in_project: project,+ member_with_permissions: permissions)+ end++ let!(:work_package) do+ FactoryBot.create(:work_package, id: 2, project: project)+ end++ subject do+ submit_email('wp_update_with_quoted_reply_above.eml')+ end+ end++ shared_context 'wp_update_with_multiple_quoted_reply_above' do+ let(:permissions) { %i[edit_work_packages view_work_packages] }+ let!(:user) do+ FactoryBot.create(:user,+ mail: '[email protected]',+ member_in_project: project,+ member_with_permissions: permissions)+ end++ let!(:work_package) do+ FactoryBot.create(:work_package, id: 2, project: project)+ end++ subject do+ submit_email('wp_update_with_multiple_quoted_reply_above.eml')+ end+ end+describe '#receive' do+ shared_examples_for 'work package created' do+ it 'creates the work package' do+ expect(subject)+ .to be_a(WorkPackage)++ expect(subject)+ .to be_persisted+ end+ end++ shared_examples_for 'journal created' do+ it 'creates the journal' do+ expect(subject)+ .to be_a(Journal)++ expect(subject)+ .to be_persisted+ end+ end+it 'should add a work_package by create user on public project' doRole.non_member.update_attribute :permissions, [:add_work_packages]project.update_attribute :is_public, true@@ -101,6 +171,20 @@ describe MailHandler, type: :model doendend+ context 'wp with status' do+ let!(:status) { FactoryBot.create(:status, name: 'Resolved') }++ # This email contains: 'Project: onlinestore' and 'Status: Resolved'+ include_context 'wp_on_given_project'++ it_behaves_like 'work package created'++ it 'assigns the status to the created work package' do+ expect(subject.status)+ .to eql(status)+ end+ end+describe 'update work package' dolet!(:mail_user) { FactoryBot.create :admin, mail: '[email protected]' }let!(:work_package) { FactoryBot.create :work_package, project: project }@@ -190,6 +274,102 @@ describe MailHandler, type: :model doendend+ context 'truncate emails based on the Setting' do+ context 'with no setting', with_settings: { mail_handler_body_delimiters: '' } do+ include_context 'wp_on_given_project'++ it_behaves_like 'work package created'++ it 'adds the entire email into the work_package' do+ expect(subject.description)+ .to include('---')++ expect(subject.description)+ .to include('This paragraph is after the delimiter')+ end+ end++ context 'with a single string', with_settings: { mail_handler_body_delimiters: '---' } do+ include_context 'wp_on_given_project'++ it_behaves_like 'work package created'++ it 'truncates the email at the delimiter for the work package' do+ expect(subject.description)+ .to include('This paragraph is before delimiters')++ expect(subject.description)+ .to include('--- This line starts with a delimiter')++ expect(subject.description)+ .not_to match(/^---$/)++ expect(subject.description)+ .not_to include('This paragraph is after the delimiter')+ end+ end++ context 'with a single quoted reply (e.g. reply to a OpenProject email notification)',+ with_settings: { mail_handler_body_delimiters: '--- Reply above. Do not remove this line. ---' } do+ include_context 'wp_update_with_quoted_reply_above'++ it_behaves_like 'journal created'++ it 'truncates the email at the delimiter with the quoted reply symbols (>)' do+ expect(subject.notes)+ .to include('An update to the issue by the sender.')++ expect(subject.notes)+ .not_to match(Regexp.escape('--- Reply above. Do not remove this line. ---'))++ expect(subject.notes)+ .not_to include('Looks like the JSON api for projects was missed.')+ end+ end++ context 'with multiple quoted replies (e.g. reply to a reply of a Redmine email notification)',+ with_settings: { mail_handler_body_delimiters: '--- Reply above. Do not remove this line. ---' } do+ include_context 'wp_update_with_quoted_reply_above'++ it_behaves_like 'journal created'++ it 'truncates the email at the delimiter with the quoted reply symbols (>)' do+ expect(subject.notes)+ .to include('An update to the issue by the sender.')++ expect(subject.notes)+ .not_to match(Regexp.escape('--- Reply above. Do not remove this line. ---'))++ expect(subject.notes)+ .not_to include('Looks like the JSON api for projects was missed.')+ end+ end++ context 'with multiple strings',+ with_settings: { mail_handler_body_delimiters: "---\nBREAK" } do+ include_context 'wp_on_given_project'++ it_behaves_like 'work package created'++ it 'truncates the email at the first delimiter found (BREAK)' do+ expect(subject.description)+ .to include('This paragraph is before delimiters')++ expect(subject.description)+ .not_to include('BREAK')++ expect(subject.description)+ .not_to include('This paragraph is between delimiters')++ expect(subject.description)+ .not_to match(/^---$/)++ expect(subject.description)+ .not_to include('This paragraph is after the delimiter')+ end+ end+ end+describe 'category' dolet!(:category) { FactoryBot.create :category, project: project, name: 'Foobar' }diff --git a/spec_legacy/unit/mail_handler_spec.rb b/spec_legacy/unit/mail_handler_spec.rbindex 28eeec1b35b..26b5d4fc1ca 100644--- a/spec_legacy/unit/mail_handler_spec.rb+++ b/spec_legacy/unit/mail_handler_spec.rb@@ -77,16 +77,6 @@ describe MailHandler, type: :model doassert_equal 'Support request', issue.type.nameend- it 'should add work package with status' do- # This email contains: 'Project: onlinestore' and 'Status: Resolved'- issue = submit_email('ticket_on_given_project.eml')- assert issue.is_a?(WorkPackage)- assert !issue.new_record?- issue.reload- assert_equal Project.find(2), issue.project- assert_equal Status.find_by(name: 'Resolved'), issue.status- end-it 'should add work package with attributes override' doissue = submit_email('ticket_with_attributes.eml', allow_override: 'type,category,priority')assert issue.is_a?(WorkPackage)@@ -425,80 +415,6 @@ describe MailHandler, type: :model doassert_equal 'This is a html-only email.', issue.descriptionend- context 'truncate emails based on the Setting' do- context 'with no setting' do- before do- Setting.mail_handler_body_delimiters = ''- end-- it 'should add the entire email into the issue' do- issue = submit_email('ticket_on_given_project.eml')- assert_issue_created(issue)- assert issue.description.include?('---')- assert issue.description.include?('This paragraph is after the delimiter')- end- end-- context 'with a single string' do- before do- Setting.mail_handler_body_delimiters = '---'- end-- it 'should truncate the email at the delimiter for the issue' do- issue = submit_email('ticket_on_given_project.eml')- assert_issue_created(issue)- assert issue.description.include?('This paragraph is before delimiters')- assert issue.description.include?('--- This line starts with a delimiter')- assert !issue.description.match(/^---$/)- assert !issue.description.include?('This paragraph is after the delimiter')- end- end-- context 'with a single quoted reply (e.g. reply to a Redmine email notification)' do- before do- Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---'- end-- it 'should truncate the email at the delimiter with the quoted reply symbols (>)' do- journal = submit_email('issue_update_with_quoted_reply_above.eml')- assert journal.is_a?(Journal)- assert journal.notes.include?('An update to the issue by the sender.')- assert !journal.notes.match(Regexp.escape('--- Reply above. Do not remove this line. ---'))- assert !journal.notes.include?('Looks like the JSON api for projects was missed.')- end- end-- context 'with multiple quoted replies (e.g. reply to a reply of a Redmine email notification)' do- before do- Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---'- end-- it 'should truncate the email at the delimiter with the quoted reply symbols (>)' do- journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml')- assert journal.is_a?(Journal)- assert journal.notes.include?('An update to the issue by the sender.')- assert !journal.notes.match(Regexp.escape('--- Reply above. Do not remove this line. ---'))- assert !journal.notes.include?('Looks like the JSON api for projects was missed.')- end- end-- context 'with multiple strings' do- before do- Setting.mail_handler_body_delimiters = "---\nBREAK"- end-- it 'should truncate the email at the first delimiter found (BREAK)' do- issue = submit_email('ticket_on_given_project.eml')- assert_issue_created(issue)- assert issue.description.include?('This paragraph is before delimiters')- assert !issue.description.include?('BREAK')- assert !issue.description.include?('This paragraph is between delimiters')- assert !issue.description.match(/^---$/)- assert !issue.description.include?('This paragraph is after the delimiter')- end- end- end-it 'should email with long subject line' doissue = submit_email('ticket_with_long_subject.eml')assert issue.is_a?(WorkPackage)