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
legacy_spec to spec
ulfertsb91e9d420191
diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rbindex 100aa56e883..b2fc5dd0d7d 100644--- a/spec/mailers/user_mailer_spec.rb+++ b/spec/mailers/user_mailer_spec.rb@@ -31,6 +31,8 @@require 'spec_helper'describe UserMailer, type: :mailer do+ subject(:deliveries) { ActionMailer::Base.deliveries }+let(:type_standard) { FactoryBot.build_stubbed(:type_standard) }let(:user) { FactoryBot.build_stubbed(:user) }let(:journal) do@@ -63,15 +65,15 @@ describe UserMailer, type: :mailer dolet(:letters_sent_count) { 1 }it 'actually sends a mail' do- expect(ActionMailer::Base.deliveries.size).to eql(letters_sent_count)+ expect(deliveries.size).to eql(letters_sent_count)endit 'is sent to the recipient' do- expect(ActionMailer::Base.deliveries.first.to).to include(recipient.mail)+ expect(deliveries.first.to).to include(recipient.mail)endit 'is sent from the configured address' do- expect(ActionMailer::Base.deliveries.first.from).to include('[email protected]')+ expect(deliveries.first.from).to match_array([Setting.mail_from])endend@@ -83,7 +85,8 @@ describe UserMailer, type: :mailer doshared_examples_for 'mail is not sent' doit 'sends no mail' do- expect(ActionMailer::Base.deliveries.size).to eql(0)+ expect(deliveries)+ be_emptyendend@@ -106,18 +109,29 @@ describe UserMailer, type: :mailer dodescribe '#test_mail' dolet(:test_email) { '[email protected]' }- let(:test_user) { User.new(firstname: 'Bob', lastname: 'Bobbi', mail: test_email) }- let(:mail) { UserMailer.test_mail(test_user) }+ let(:recipient) { FactoryBot.build_stubbed(:user, firstname: 'Bob', lastname: 'Bobbi', mail: test_email) }before do- # the name method uses a format setting to determine how to concatenate first name- # and last name whereby an unescaped comma will lead to have two email addresses- # defined instead of one (['Bobbi', '[email protected]'] vs. ['[email protected]'])- allow(test_user).to receive(:name).and_return('Bobbi, Bob')+ UserMailer.test_mail(recipient).deliver_now+ end++ it_behaves_like 'mail is sent' do+ it 'has the expected subject' do+ expect(deliveries.first.subject)+ .to eql 'OpenProject Test'+ end++ it 'includes the url to the instance' do+ expect(deliveries.first.body.encoded)+ .to match Regexp.new("OpenProject URL: #{Setting.protocol}://#{Setting.host_name}")+ endend- it 'escapes the name attribute properly' do- expect(mail.to).to eql [test_email]+ # the name method uses a format setting to determine how to concatenate first name+ # and last name whereby an unescaped comma will lead to have two email addresses+ # defined instead of one (['Bobbi', '[email protected]'] vs. ['[email protected]'])+ context 'with the user name setting prone to trip up email address separation', with_settings: { user_format: :lastname_coma_firstname } do+ it_behaves_like 'mail is sent'endend@@ -126,10 +140,21 @@ describe UserMailer, type: :mailer doUserMailer.work_package_added(recipient, journal, user).deliver_nowend- it_behaves_like 'mail is sent'+ it_behaves_like 'mail is sent' do+ it 'contains the WP subject in the mail subject' do+ expect(deliveries.first.subject)+ .to include(work_package.subject)+ end- it 'contains the WP subject in the mail subject' do- expect(ActionMailer::Base.deliveries.first.subject).to include(work_package.subject)+ it 'has the desired "Precedence" header' do+ expect(deliveries.first['Precedence'].value)+ .to eql 'bulk'+ end++ it 'has the desired "Auto-Submitted" header' do+ expect(deliveries.first['Auto-Submitted'].value)+ .to eql 'auto-generated'+ endendit_behaves_like 'does only send mails to author if permitted'@@ -155,7 +180,7 @@ describe UserMailer, type: :mailer doinclude_examples 'multiple mails are sent', 2it 'contains the WP subject in the mail subject' do- expect(ActionMailer::Base.deliveries.first.subject).to include(work_package.subject)+ expect(deliveries.first.subject).to include(work_package.subject)endend@@ -181,7 +206,7 @@ describe UserMailer, type: :mailer doit_behaves_like 'mail is sent'it 'should link to the latest version diff page' do- expect(ActionMailer::Base.deliveries.first.body.encoded).to include 'diff/1'+ expect(deliveries.first.body.encoded).to include 'diff/1'endit_behaves_like 'does only send mails to author if permitted'diff --git a/spec_legacy/functional/user_mailer_spec.rb b/spec_legacy/functional/user_mailer_spec.rbindex b0bc423801e..a2c8899e97e 100644--- a/spec_legacy/functional/user_mailer_spec.rb+++ b/spec_legacy/functional/user_mailer_spec.rb@@ -44,20 +44,6 @@ describe UserMailer, type: :mailer do::Type.delete_allend- it 'should test mail sends a simple greeting' do- user = FactoryBot.create(:admin, mail: '[email protected]', preferences: { no_self_notified: false })-- mail = UserMailer.test_mail(user)- assert mail.deliver_now-- assert_equal 1, ActionMailer::Base.deliveries.size-- assert_equal 'OpenProject Test', mail.subject- assert_equal ['[email protected]'], mail.to- assert_equal ['[email protected]'], mail.from- assert_match /OpenProject URL/, mail.body.encoded- end-it 'should generated links in emails' doSetting.default_language = 'en'Setting.host_name = 'mydomain.foo'@@ -135,16 +121,6 @@ describe UserMailer, type: :mailer doendend- it 'should email headers' do- user = FactoryBot.create(:user)- issue = FactoryBot.create(:work_package)- mail = UserMailer.work_package_added(user, issue.journals.first, user)- assert mail.deliver_now- refute_nil mail- assert_equal 'bulk', mail.header['Precedence'].to_s- assert_equal 'auto-generated', mail.header['Auto-Submitted'].to_s- end-it 'sends plain text mail' doSetting.plain_text_mail = 1user = FactoryBot.create(:user, preferences: { no_self_notified: false })@@ -167,16 +143,6 @@ describe UserMailer, type: :mailer doassert mail.encoded.include?('href')end- context 'with mail_from set', with_settings: { mail_from: 'Redmine app <[email protected]>' } do- it 'should mail from with phrase' do- user = FactoryBot.create(:user, preferences: { no_self_notified: false })- UserMailer.test_mail(user).deliver_now- mail = ActionMailer::Base.deliveries.last- refute_nil mail- assert_equal 'Redmine app <[email protected]>', mail.header['From'].to_s- end- end-it 'should not send email without recipient' douser = FactoryBot.create(:user)news = FactoryBot.create(:news)