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
ulfertsd34d14cfb265
diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rbindex eabe9df73a2..4c443e1f9db 100644--- a/spec/mailers/user_mailer_spec.rb+++ b/spec/mailers/user_mailer_spec.rb@@ -109,6 +109,28 @@ describe UserMailer, type: :mailer doendend+ describe '#with_deliveries' do+ context 'with false' do+ before do+ described_class.with_deliveries(false) do+ described_class.test_mail(recipient).deliver_now+ end+ end++ it_behaves_like 'mail is not sent'+ end++ context 'with true' do+ before do+ described_class.with_deliveries(true) do+ described_class.test_mail(recipient).deliver_now+ end+ end++ it_behaves_like 'mail is sent'+ end+ end+describe '#test_mail' dolet(:test_email) { '[email protected]' }let(:recipient) { FactoryBot.build_stubbed(:user, firstname: 'Bob', lastname: 'Bobbi', mail: test_email) }@@ -167,6 +189,20 @@ describe UserMailer, type: :mailer doexpect(deliveries.first.references).to be_nilend++ context 'with plain_text_mail active', with_settings: { plain_text_mail: 1 } do+ it 'only sends plain text' do+ expect(mail.content_type)+ .to match /text\/plain/+ end+ end++ context 'with plain_text_mail inactive', with_settings: { plain_text_mail: 0 } do+ it 'sends a multipart mail' do+ expect(mail.content_type)+ .to match /multipart\/alternative/+ end+ endendit_behaves_like 'does only send mails to author if permitted'@@ -187,6 +223,32 @@ describe UserMailer, type: :mailer doexpect(deliveries.first.references).to eql UserMailer.generate_message_id(journal, recipient)end++ context 'with a link' do+ let(:work_package) do+ FactoryBot.build_stubbed(:work_package,+ type: type_standard,+ description: "Some text with a reference to ##{referenced_wp.id}")+ end++ let(:referenced_wp) do+ FactoryBot.build_stubbed(:work_package)+ end++ it 'renders the link' do+ expect(html_body)+ .to have_link("##{referenced_wp.id}", href: work_package_url(referenced_wp, host: Setting.host_name))+ end++ context 'with a relative url root',+ with_config: { rails_relative_url_root: '/subpath' } do+ it 'renders the link' do+ expect(html_body)+ .to have_link("##{referenced_wp.id}",+ href: work_package_url(referenced_wp, host: Setting.host_name, script_name: '/subpath'))+ end+ end+ endendit_behaves_like 'does only send mails to author if permitted'@@ -730,4 +792,72 @@ describe UserMailer, type: :mailer doendendend++ describe 'localization' do+ context 'with the user having a language configured',+ with_settings: { available_languages: %w[en de],+ default_language: 'en',+ emails_header: {+ "de" => 'deutscher header',+ "en" => 'english header'+ } } do+ let(:recipient) do+ FactoryBot.build_stubbed(:user, language: 'de', preferences: { no_self_notified: false })+ end++ before do+ I18n.locale = :en++ described_class.account_information(recipient, 'pwd').deliver_now+ end++ it 'uses the recipients language' do+ expect(ActionMailer::Base.deliveries.last.body.parts.detect { |p| p.content_type.include? 'text/html' }.body.encoded)+ .to include I18n.t(:mail_body_account_information, locale: :de)+ end++ it 'does not alter I18n.locale' do+ expect(I18n.locale)+ .to eql :en+ end++ it 'include the user language header' do+ expect(ActionMailer::Base.deliveries.last.body.parts.detect { |p| p.content_type.include? 'text/html' }.body.encoded)+ .to include 'deutscher header'+ end+ end++ context 'with the user having no language configured',+ with_settings: { available_languages: %w[en de],+ default_language: 'en',+ emails_header: {+ "de" => 'deutscher header',+ "en" => 'english header'+ } } do+ let(:recipient) do+ FactoryBot.build_stubbed(:user, language: '', preferences: { no_self_notified: false })+ end++ before do+ I18n.locale = :de++ described_class.account_information(recipient, 'pwd').deliver_now+ end++ it 'uses the default language' do+ expect(ActionMailer::Base.deliveries.last.body.parts.detect { |p| p.content_type.include? 'text/html' }.body.encoded)+ .to include I18n.t(:mail_body_account_information, locale: :en)+ end++ it 'include the default language header' do+ expect(ActionMailer::Base.deliveries.last.body.parts.detect { |p| p.content_type.include? 'text/html' }.body.encoded)+ .to include 'english header'+ end++ it 'does not alter I18n.locale' do+ expect(I18n.locale)+ .to eql :de+ end+ end+ endenddiff --git a/spec_legacy/functional/user_mailer_spec.rb b/spec_legacy/functional/user_mailer_spec.rbdeleted file mode 100644index d1c4d662149..00000000000--- a/spec_legacy/functional/user_mailer_spec.rb+++ /dev/null@@ -1,277 +0,0 @@-#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2021 the OpenProject GmbH-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License version 3.-#-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-# Copyright (C) 2006-2013 Jean-Philippe Lang-# Copyright (C) 2010-2013 the ChiliProject Team-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License-# as published by the Free Software Foundation; either version 2-# of the License, or (at your option) any later version.-#-# This program is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU General Public License-# along with this program; if not, write to the Free Software-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.-#-# See docs/COPYRIGHT.rdoc for more details.-#++--require_relative '../legacy_spec_helper'--describe UserMailer, type: :mailer do- include ::Rails::Dom::Testing::Assertions::SelectorAssertions-- before do- Setting.mail_from = '[email protected]'- Setting.host_name = 'mydomain.foo'- Setting.protocol = 'http'- Setting.plain_text_mail = '0'- Setting.default_language = 'en'-- User.delete_all- WorkPackage.delete_all- Project.delete_all- ::Type.delete_all- end-- it 'should generated links in emails' do- Setting.default_language = 'en'- Setting.host_name = 'mydomain.foo'- Setting.protocol = 'https'-- project, user, related_issue, issue, changeset, attachment, journal = setup_complex_issue_update-- assert UserMailer.work_package_updated(user, journal).deliver_now- assert last_email-- assert_select_email do- # link to the main ticket- assert_select 'a[href=?]',- "https://mydomain.foo/work_packages/#{issue.id}",- text: "My Type ##{issue.id}: My awesome Ticket"- # link to a description diff- assert_select 'li', text: /Description changed/- assert_select 'li>a[href=?]',- "https://mydomain.foo/journals/#{journal.id}/diff/description",- text: 'Details'- # link to a referenced ticket- assert_select 'a[href=?]',- "https://mydomain.foo/work_packages/#{related_issue.id}",- text: "##{related_issue.id}"- # link to a changeset- if changeset- assert_select 'a[href=?][title=?]',- url_for(controller: 'repositories',- action: 'revision',- project_id: project,- rev: changeset.revision),- 'This commit fixes #1, #2 and references #1 and #3',- text: "r#{changeset.revision}"- end- end- end-- context 'with prefix', with_config: { rails_relative_url_root: '/rdm' } do- it 'should generated links with prefix and relative url root' do- Setting.default_language = 'en'- Setting.host_name = 'mydomain.foo'- Setting.protocol = 'http'-- project, user, related_issue, issue, changeset, attachment, journal = setup_complex_issue_update-- assert UserMailer.work_package_updated(user, journal).deliver_now- assert last_email-- assert_select_email do- # link to the main ticket- assert_select 'a[href=?]',- "http://mydomain.foo/rdm/work_packages/#{issue.id}",- text: "My Type ##{issue.id}: My awesome Ticket"- # link to a description diff- assert_select 'li', text: /Description changed/- assert_select 'li>a[href=?]',- "http://mydomain.foo/rdm/journals/#{journal.id}/diff/description",- text: 'Details'- # link to a referenced ticket- assert_select 'a[href=?]',- "http://mydomain.foo/rdm/work_packages/#{related_issue.id}",- text: "##{related_issue.id}"- # link to a changeset- if changeset- assert_select 'a[href=?][title=?]',- url_for(controller: 'repositories',- script_name: '/rdm',- action: 'revision',- project_id: project,- rev: changeset.revision),- 'This commit fixes #1, #2 and references #1 and #3',- text: "r#{changeset.revision}"- end- end- end- end-- it 'sends plain text mail' do- Setting.plain_text_mail = 1- user = FactoryBot.create(:user, preferences: { no_self_notified: false })- issue = FactoryBot.create(:work_package)- UserMailer.work_package_added(user, issue.journals.first, user).deliver_now- mail = ActionMailer::Base.deliveries.last- assert_match /text\/plain/, mail.content_type- assert_equal 0, mail.parts.size- assert !mail.encoded.include?('href')- end-- it 'sends html mail' do- Setting.plain_text_mail = 0- user = FactoryBot.create(:user, preferences: { no_self_notified: false })- issue = FactoryBot.create(:work_package)- UserMailer.work_package_added(user, issue.journals.first, user).deliver_now- mail = ActionMailer::Base.deliveries.last- assert_match /multipart\/alternative/, mail.content_type- assert_equal 2, mail.parts.size- assert mail.encoded.include?('href')- end-- context '#issue_add',- with_settings: { available_languages: ['en', 'de'], default_language: 'de' } do- it 'should change mail language depending on recipient language' do- issue = FactoryBot.create(:work_package)- user = FactoryBot.create(:user, mail: '[email protected]', language: 'de', preferences: { no_self_notified: false })-- I18n.locale = 'en'- assert UserMailer.work_package_added(user, issue.journals.first, user).deliver_now- assert_equal 1, ActionMailer::Base.deliveries.size- mail = last_email- assert_equal ['[email protected]'], mail.to- assert mail.body.encoded.include?('erstellt')- assert !mail.body.encoded.include?('reported')- assert_equal :en, I18n.locale- end-- it 'should falls back to default language if user has no language' do- # 1. user's language- # 2. Setting.default_language- # 3. I18n.default_locale- issue = FactoryBot.create(:work_package)- user = FactoryBot.create(:user, mail: '[email protected]', language: '', preferences: { no_self_notified: false }) # (auto)-- I18n.locale = 'de'- assert UserMailer.work_package_added(user, issue.journals.first, user).deliver_now- assert_equal 1, ActionMailer::Base.deliveries.size- mail = last_email- assert_equal ['[email protected]'], mail.to- assert !mail.body.encoded.include?('reported')- assert mail.body.encoded.include?('erstellt')- assert_equal :de, I18n.locale- end- end-- context 'with locale settings',- with_settings: { available_languages: ['en', 'de'], default_language: 'de' } do- it 'should mailer should not change locale' do- # Set current language to english- I18n.locale = :en- # Send an email to a german user- user = FactoryBot.create(:user, language: 'de')- UserMailer.account_activated(user).deliver_now- mail = ActionMailer::Base.deliveries.last- assert mail.body.encoded.include?('aktiviert')- assert_equal :en, I18n.locale- end- end-- it 'should with deliveries off' do- user = FactoryBot.create(:user)- UserMailer.with_deliveries(false) do- UserMailer.test_mail(user).deliver_now- end- assert ActionMailer::Base.deliveries.empty?- # should restore perform_deliveries- assert ActionMailer::Base.perform_deliveries- end-- context 'layout',- with_settings: {- available_languages: %i[en de],- emails_header: {- "de" => 'deutscher header'- }- } do- it 'should include the emails_header depeding on the locale' do- user = FactoryBot.create(:user, language: :de)- assert UserMailer.test_mail(user).deliver_now- mail = ActionMailer::Base.deliveries.last- assert mail.body.encoded.include?('deutscher header')- end- end-- private-- def last_email- mail = ActionMailer::Base.deliveries.last- refute_nil mail- end-- def setup_complex_issue_update- project = FactoryBot.create(:valid_project)- user = FactoryBot.create(:admin, member_in_project: project)- type = FactoryBot.create(:type, name: 'My Type')- project.types << type- project.save-- related_issue = FactoryBot.create(:work_package,- subject: 'My related Ticket',- type: type,- project: project)-- issue = FactoryBot.create(:work_package,- subject: 'My awesome Ticket',- type: type,- project: project,- description: 'nothing here yet')-- # now change the issue, to get a nice journal- issue.description = "This is related to issue ##{related_issue.id}\n"-- repository = FactoryBot.create(:repository_subversion,- project: project)-- changeset = FactoryBot.create :changeset,- repository: repository,- comments: 'This commit fixes #1, #2 and references #1 and #3'-- issue.description += " A reference to a changeset r#{changeset.revision}\n" if changeset-- attachment = FactoryBot.build(:attachment,- author: issue.author)-- issue.attachments << attachment-- issue.description += " A reference to an attachment attachment:#{attachment.filename}"-- assert issue.save- issue.reload- journal = issue.journals.last-- ActionMailer::Base.deliveries = [] # remove issue-created mails-- [project, user, related_issue, issue, changeset, attachment, journal]- end-- def url_for(options)- options.merge!(host: Setting.host_name, protocol: Setting.protocol)- Rails.application.routes.url_helpers.url_for options- end-end