replace legacy spec

pull/11359/head
ulferts 2 years ago
parent c4658d79d1
commit c0bd8b531c
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 6
      spec/fixtures/mail_handler/wp_with_attachment_apple.eml
  2. 2
      spec/fixtures/mail_handler/wp_with_custom_field.eml
  3. 2
      spec/fixtures/mail_handler/wp_with_invalid_attributes.eml
  4. 2
      spec/fixtures/mail_handler/wp_with_localized_attributes.eml
  5. 195
      spec/models/mail_handler_spec.rb
  6. 74
      spec_legacy/unit/mail_handler_spec.rb

@ -1,13 +1,13 @@
From JSmith@somenet.foo Mon Jun 27 06:55:56 2011
Return-Path: <JSmith@somenet.foo>
X-Original-To: redmine@somenet.foo
Delivered-To: redmine@somenet.foo
X-Original-To: openproject@somenet.foo
Delivered-To: openproject@somenet.foo
From: John Smith <JSmith@somenet.foo>
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
To: redmine@somenet.foo
To: openproject@somenet.foo
Message-Id: <7ABE3636-07E8-47C9-90A1-FCB1AA894DA1@somenet.foo>
X-Mailer: Apple Mail (2.1084)

@ -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" <jsmith@somenet.foo>
To: <redmine@somenet.foo>
To: <openproject@somenet.foo>
Subject: New ticket with custom field values
Date: Sun, 22 Jun 2008 12:28:07 +0200
MIME-Version: 1.0

@ -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" <jsmith@somenet.foo>
To: <redmine@somenet.foo>
To: <openproject@somenet.foo>
Subject: New ticket on a given project
Date: Sun, 22 Jun 2008 12:28:07 +0200
MIME-Version: 1.0

@ -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" <jsmith@somenet.foo>
To: <redmine@somenet.foo>
To: <openproject@somenet.foo>
Subject: New ticket on a given project
Date: Sun, 22 Jun 2008 12:28:07 +0200
MIME-Version: 1.0

@ -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,
mail: 'JSmith@somenet.foo',
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,
mail: 'JSmith@somenet.foo',
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,
mail: 'JSmith@somenet.foo',
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,
mail: 'JSmith@somenet.foo',
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

@ -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('jsmith@somenet.foo').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)

Loading…
Cancel
Save