Browse files

Make the email integration test less strict

I think this was failing for some people and not others because my email
is in some people's Users table and not others.
  • Loading branch information...
1 parent a4f439e commit 70fc5bb5d2769c9e0d563cefbed944461e8d6d6e @philc philc committed Mar 17, 2013
Showing with 16 additions and 11 deletions.
  1. +1 −1 lib/emails.rb
  2. +15 −10 test/integration/deliver_comment_emails_integration_test.rb
View
2 lib/emails.rb
@@ -58,7 +58,7 @@ def self.send_comment_email(commit, comments)
author = commit.grit_commit.author
user = User.find(:email => author.email)
to << author.email if user && !user.deleted?
- # There shouldn't be deleted users with saved searches, but filter them out in case.
+ # There shouldn't be deleted users with saved searches, but filter them out just in case.
cc = (users_with_saved_searches_matching(commit, :email_comments => true).reject(&:deleted?) +
all_previous_commenters).map(&:email).uniq
to += cc
View
25 test/integration/deliver_comment_emails_integration_test.rb
@@ -10,7 +10,8 @@ class DeliverCommentEmailsIntegrationTest < Scope::TestCase
include IntegrationTestHelper
setup_once do
- commit = test_repo.commits("9f9c5d87316e5f723d0e9c6a03ddd86ce134ac5e")[0]
+ test_commit_id = "9f9c5d87316e5f723d0e9c6a03ddd86ce134ac5e"
+ commit = test_repo.commits(test_commit_id)[0]
Commit.filter(:sha => commit.sha).destroy
@@commit = create_commit(commit, integration_test_user, GitRepo.first(:name => TEST_REPO_NAME))
@@ -26,22 +27,26 @@ class DeliverCommentEmailsIntegrationTest < Scope::TestCase
end
setup do
- @mail_options = []
- stub(Pony).mail { |options| @mail_options << options }
+ @sent_emails = []
+ stub(Pony).mail { |options| @sent_emails << options }
+ # Pretend no one has a saved-search covering this commit, so the comment email recipients are only the
+ # authors and commentors of the commit.
any_instance_of(SavedSearch) do
stub(SavedSearch).matches_commit? { false }
end
end
should "deliver an email containing all comments" do
@@comments.each { |comment| DeliverCommentEmails.perform(comment.id) }
- assert_equal 2, @mail_options.length
- # Deleted user should be ignored.
- expected_emails = [@@commit.grit_commit.author, integration_test_user].map(&:email).sort
- @mail_options.each do |options|
- assert_equal expected_emails, options[:to].sort
- assert options[:subject].include?(@@commit.grit_commit.id_abbrev)
- assert options[:html_body].include?(@@comments.first.text)
+ assert_equal 2, @sent_emails.size
+ @sent_emails.each do |email|
+ # Note that options[:to] may include the author of the test_commit_id (phil.crosby) if he has ever
+ # logged in to this Barkeep instance and has a record in the Users table.
+ assert email[:to].include?(integration_test_user.email)
+ # Deleted user should be ignored.
+ assert_equal false, email[:to].include?(deleted_test_user.email)
+ assert email[:subject].include?(@@commit.grit_commit.id_abbrev)
+ assert email[:html_body].include?(@@comments.first.text)
end
end
end

0 comments on commit 70fc5bb

Please sign in to comment.