summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-03-04 13:28:18 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-03-04 13:28:18 +0000
commit3aaf2b9ed00751d0aa793c98861513ac5302ec10 (patch)
treed497313144509b6bb0a43c2a10e395424549dcfe /test
parentb1d5f42237295895412ff559f3f65a05cd65cf96 (diff)
downloadredmine-3aaf2b9ed00751d0aa793c98861513ac5302ec10.tar.gz
redmine-3aaf2b9ed00751d0aa793c98861513ac5302ec10.zip
Adds helpers for testing email body.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9086 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r--test/functional/files_controller_test.rb2
-rw-r--r--test/functional/issues_controller_test.rb14
-rw-r--r--test/functional/messages_controller_test.rb2
-rw-r--r--test/functional/users_controller_test.rb6
-rw-r--r--test/test_helper.rb20
-rw-r--r--test/unit/mailer_test.rb8
-rw-r--r--test/unit/repository_test.rb4
7 files changed, 38 insertions, 18 deletions
diff --git a/test/functional/files_controller_test.rb b/test/functional/files_controller_test.rb
index e37cc855e..d05557990 100644
--- a/test/functional/files_controller_test.rb
+++ b/test/functional/files_controller_test.rb
@@ -74,7 +74,7 @@ class FilesControllerTest < ActionController::TestCase
mail = ActionMailer::Base.deliveries.last
assert_not_nil mail
assert_equal "[eCookbook] New file", mail.subject
- assert mail.body.include?('testfile.txt')
+ assert_mail_body_match 'testfile.txt', mail
end
def test_create_version_file
diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb
index 168574ebb..d177a71c2 100644
--- a/test/functional/issues_controller_test.rb
+++ b/test/functional/issues_controller_test.rb
@@ -2164,7 +2164,7 @@ class IssuesControllerTest < ActionController::TestCase
mail = ActionMailer::Base.deliveries.last
assert_not_nil mail
assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
- assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
+ assert_mail_body_match "Subject changed from #{old_subject} to #{new_subject}", mail
end
def test_put_update_with_project_change
@@ -2190,7 +2190,7 @@ class IssuesControllerTest < ActionController::TestCase
mail = ActionMailer::Base.deliveries.last
assert_not_nil mail
assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
- assert mail.body.include?("Project changed from eCookbook to OnlineStore")
+ assert_mail_body_match "Project changed from eCookbook to OnlineStore", mail
end
def test_put_update_with_tracker_change
@@ -2215,7 +2215,7 @@ class IssuesControllerTest < ActionController::TestCase
mail = ActionMailer::Base.deliveries.last
assert_not_nil mail
assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
- assert mail.body.include?("Tracker changed from Bug to Feature request")
+ assert_mail_body_match "Tracker changed from Bug to Feature request", mail
end
def test_put_update_with_custom_field_change
@@ -2238,7 +2238,7 @@ class IssuesControllerTest < ActionController::TestCase
mail = ActionMailer::Base.deliveries.last
assert_not_nil mail
- assert mail.body.include?("Searchable field changed from 125 to New custom value")
+ assert_mail_body_match "Searchable field changed from 125 to New custom value", mail
end
def test_put_update_with_multi_custom_field_change
@@ -2281,7 +2281,7 @@ class IssuesControllerTest < ActionController::TestCase
assert_equal 2, j.details.size
mail = ActionMailer::Base.deliveries.last
- assert mail.body.include?("Status changed from New to Assigned")
+ assert_mail_body_match "Status changed from New to Assigned", mail
# subject should contain the new status
assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
end
@@ -2299,7 +2299,7 @@ class IssuesControllerTest < ActionController::TestCase
assert_equal User.anonymous, j.user
mail = ActionMailer::Base.deliveries.last
- assert mail.body.include?(notes)
+ assert_mail_body_match notes, mail
end
def test_put_update_with_note_and_spent_time
@@ -2357,7 +2357,7 @@ class IssuesControllerTest < ActionController::TestCase
assert_equal 59, File.size(attachment.diskfile)
mail = ActionMailer::Base.deliveries.last
- assert mail.body.include?('testfile.txt')
+ assert_mail_body_match 'testfile.txt', mail
end
def test_put_update_with_failure_should_save_attachments
diff --git a/test/functional/messages_controller_test.rb b/test/functional/messages_controller_test.rb
index b24a444d8..70df6f0b5 100644
--- a/test/functional/messages_controller_test.rb
+++ b/test/functional/messages_controller_test.rb
@@ -106,7 +106,7 @@ class MessagesControllerTest < ActionController::TestCase
mail = ActionMailer::Base.deliveries.last
assert_not_nil mail
assert_equal "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] Test created message", mail.subject
- assert mail.body.include?('Message body')
+ assert_mail_body_match 'Message body', mail
# author
assert mail.bcc.include?('jsmith@somenet.foo')
# project member
diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb
index ca805d4a1..11e5acc3c 100644
--- a/test/functional/users_controller_test.rb
+++ b/test/functional/users_controller_test.rb
@@ -191,7 +191,7 @@ class UsersControllerTest < ActionController::TestCase
mail = ActionMailer::Base.deliveries.last
assert_not_nil mail
assert_equal [user.mail], mail.bcc
- assert mail.body.include?('secret')
+ assert_mail_body_match 'secret', mail
end
def test_create_with_preferences
@@ -279,7 +279,7 @@ class UsersControllerTest < ActionController::TestCase
mail = ActionMailer::Base.deliveries.last
assert_not_nil mail
assert_equal ['foo.bar@somenet.foo'], mail.bcc
- assert mail.body.include?(ll('fr', :notice_account_activated))
+ assert_mail_body_match ll('fr', :notice_account_activated), mail
end
def test_update_with_password_change_should_send_a_notification
@@ -293,7 +293,7 @@ class UsersControllerTest < ActionController::TestCase
mail = ActionMailer::Base.deliveries.last
assert_not_nil mail
assert_equal [u.mail], mail.bcc
- assert mail.body.include?('newpass')
+ assert_mail_body_match 'newpass', mail
end
test "put :update with a password change to an AuthSource user switching to Internal authentication" do
diff --git a/test/test_helper.rb b/test/test_helper.rb
index a9eedaba9..a02f70f6b 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -158,6 +158,26 @@ class ActiveSupport::TestCase
assert s.include?(expected), "\"#{expected}\" not found in \"#{s}\""
end
+ def assert_not_include(expected, s)
+ assert !s.include?(expected), "\"#{expected}\" found in \"#{s}\""
+ end
+
+ def assert_mail_body_match(expected, mail)
+ if expected.is_a?(String)
+ assert_include expected, mail.body
+ else
+ assert_match expected, mail.body
+ end
+ end
+
+ def assert_mail_body_no_match(expected, mail)
+ if expected.is_a?(String)
+ assert_not_include expected, mail.body
+ else
+ assert_no_match expected, mail.body
+ end
+ end
+
# Shoulda macros
def self.should_render_404
should_respond_with :not_found
diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb
index 6d652cb23..5607d1636 100644
--- a/test/unit/mailer_test.rb
+++ b/test/unit/mailer_test.rb
@@ -470,7 +470,7 @@ class MailerTest < ActiveSupport::TestCase
assert_equal 1, ActionMailer::Base.deliveries.size
mail = last_email
assert mail.bcc.include?('dlopper@somenet.foo')
- assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
+ assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail
assert_equal '1 issue(s) due in the next 42 days', mail.subject
end
@@ -486,7 +486,7 @@ class MailerTest < ActiveSupport::TestCase
assert_equal 1, ActionMailer::Base.deliveries.size
mail = last_email
assert mail.bcc.include?('dlopper@somenet.foo')
- assert !mail.body.include?('Closed issue')
+ assert_mail_body_no_match 'Closed issue', mail
end
end
@@ -497,7 +497,7 @@ class MailerTest < ActiveSupport::TestCase
assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper
mail = last_email
assert mail.bcc.include?('dlopper@somenet.foo')
- assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
+ assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail
end
def last_email
@@ -515,7 +515,7 @@ class MailerTest < ActiveSupport::TestCase
user.language = 'fr'
Mailer.deliver_account_activated(user)
mail = last_email
- assert mail.body.include?('Votre compte')
+ assert_mail_body_match 'Votre compte', mail
assert_equal :it, current_language
end
diff --git a/test/unit/repository_test.rb b/test/unit/repository_test.rb
index db0620d16..96f0ceeee 100644
--- a/test/unit/repository_test.rb
+++ b/test/unit/repository_test.rb
@@ -176,8 +176,8 @@ class RepositoryTest < ActiveSupport::TestCase
assert_not_nil mail
assert mail.subject.starts_with?(
"[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
- assert mail.body.include?(
- "Status changed from #{old_status} to #{fixed_issue.status}")
+ assert_mail_body_match(
+ "Status changed from #{old_status} to #{fixed_issue.status}", mail)
# ignoring commits referencing an issue of another project
assert_equal [], Issue.find(4).changesets