From 93d20011e511ff1b08fe011b591ec3f48bb77f89 Mon Sep 17 00:00:00 2001 From: Jan Sandbrink Date: Thu, 26 Mar 2015 12:06:06 +0100 Subject: [PATCH] fix more TestUnit tests - also adding author to news_added --- app/mailers/user_mailer.rb | 4 ++-- app/models/news_observer.rb | 2 +- test/functional/user_mailer_test.rb | 27 +++++++++------------------ 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 0337280e66..60354c2f3f 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -139,7 +139,7 @@ class UserMailer < ActionMailer::Base end end - def news_added(user, news) + def news_added(user, news, author) @news = news open_project_headers 'Type' => 'News' @@ -150,7 +150,7 @@ class UserMailer < ActionMailer::Base with_locale_for(user) do subject = "#{News.model_name.human}: #{@news.title}" subject = "[#{@news.project.name}] #{subject}" if @news.project - mail to: user.mail, subject: subject + mail_for_author author, to: user.mail, subject: subject end end diff --git a/app/models/news_observer.rb b/app/models/news_observer.rb index 68ed05af6d..fac62827e4 100644 --- a/app/models/news_observer.rb +++ b/app/models/news_observer.rb @@ -32,7 +32,7 @@ class NewsObserver < ActiveRecord::Observer if Setting.notified_events.include?('news_added') users = User.find_all_by_mails(news.recipients) users.each do |user| - UserMailer.news_added(user, news).deliver + UserMailer.news_added(user, news, User.current).deliver end end end diff --git a/test/functional/user_mailer_test.rb b/test/functional/user_mailer_test.rb index 1414cf6998..0797bc392d 100644 --- a/test/functional/user_mailer_test.rb +++ b/test/functional/user_mailer_test.rb @@ -200,7 +200,7 @@ class UserMailerTest < ActionMailer::TestCase def test_email_headers user = FactoryGirl.create(:user) issue = FactoryGirl.create(:work_package) - mail = UserMailer.work_package_added(user, issue) + mail = UserMailer.work_package_added(user, issue, user) assert mail.deliver assert_not_nil mail assert_equal 'bulk', mail.header['Precedence'].to_s @@ -211,7 +211,7 @@ class UserMailerTest < ActionMailer::TestCase Setting.plain_text_mail = 1 user = FactoryGirl.create(:user) issue = FactoryGirl.create(:work_package) - UserMailer.work_package_added(user, issue).deliver + UserMailer.work_package_added(user, issue, user).deliver mail = ActionMailer::Base.deliveries.last assert_match /text\/plain/, mail.content_type assert_equal 0, mail.parts.size @@ -222,7 +222,7 @@ class UserMailerTest < ActionMailer::TestCase Setting.plain_text_mail = 0 user = FactoryGirl.create(:user) issue = FactoryGirl.create(:work_package) - UserMailer.work_package_added(user, issue).deliver + UserMailer.work_package_added(user, issue, user).deliver mail = ActionMailer::Base.deliveries.last assert_match /multipart\/alternative/, mail.content_type assert_equal 2, mail.parts.size @@ -248,7 +248,7 @@ class UserMailerTest < ActionMailer::TestCase user.pref.save User.current = user ActionMailer::Base.deliveries.clear - UserMailer.news_added(user, news).deliver + UserMailer.news_added(user, news, user).deliver assert_equal 1, last_email.to.size # nobody to notify @@ -256,14 +256,14 @@ class UserMailerTest < ActionMailer::TestCase user.pref.save User.current = user ActionMailer::Base.deliveries.clear - UserMailer.news_added(user, news).deliver + UserMailer.news_added(user, news, user).deliver assert ActionMailer::Base.deliveries.empty? end def test_issue_add_message_id user = FactoryGirl.create(:user) issue = FactoryGirl.create(:work_package) - mail = UserMailer.work_package_added(user, issue) + mail = UserMailer.work_package_added(user, issue, user) mail.deliver assert_not_nil mail assert_equal UserMailer.generate_message_id(issue, user), mail.message_id @@ -311,22 +311,13 @@ class UserMailerTest < ActionMailer::TestCase end context('#issue_add') do - should 'send one email per recipient' do - user = FactoryGirl.create(:user, mail: 'foo@bar.de') - issue = FactoryGirl.create(:work_package) - ActionMailer::Base.deliveries.clear - assert UserMailer.work_package_added(user, issue).deliver - assert_equal 1, ActionMailer::Base.deliveries.size - assert_equal ['foo@bar.de'], last_email.to - end - should 'change mail language depending on recipient language' do issue = FactoryGirl.create(:work_package) user = FactoryGirl.create(:user, mail: 'foo@bar.de', language: 'de') ActionMailer::Base.deliveries.clear with_settings available_languages: ['en', 'de'] do I18n.locale = 'en' - assert UserMailer.work_package_added(user, issue).deliver + assert UserMailer.work_package_added(user, issue, user).deliver assert_equal 1, ActionMailer::Base.deliveries.size mail = last_email assert_equal ['foo@bar.de'], mail.to @@ -346,7 +337,7 @@ class UserMailerTest < ActionMailer::TestCase with_settings available_languages: ['en', 'de'], default_language: 'de' do I18n.locale = 'de' - assert UserMailer.work_package_added(user, issue).deliver + assert UserMailer.work_package_added(user, issue, user).deliver assert_equal 1, ActionMailer::Base.deliveries.size mail = last_email assert_equal ['foo@bar.de'], mail.to @@ -360,7 +351,7 @@ class UserMailerTest < ActionMailer::TestCase def test_news_added user = FactoryGirl.create(:user) news = FactoryGirl.create(:news) - assert UserMailer.news_added(user, news).deliver + assert UserMailer.news_added(user, news, user).deliver end def test_news_comment_added