Skip to content

Commit

Permalink
[api] fix comment emails
Browse files Browse the repository at this point in the history
  • Loading branch information
coolo committed Dec 16, 2013
1 parent 2178565 commit aa37e9c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 15 deletions.
31 changes: 31 additions & 0 deletions src/api/test/fixtures/event_mailer/another_comment_event
@@ -0,0 +1,31 @@
From: Thor <tschmidt@example.com>
To: Iggy Pop <Iggy@pop.org>,
Johnny Thunders <adrian@example.com>
Message-ID: <test@localhost>
In-Reply-To: obs-request-4@localhost
References: obs-request-4@localhost
Subject: New comment in request 4 by tom: Another Title
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Precedence: bulk
X-Mailer: OBS Notification System
X-OBS-URL: http://localhost
Auto-Submitted: auto-generated
X-OBS-event-type: comment_for_request
X-OBS-Request-Creator: Iggy
X-OBS-Request-Id: 4
X-OBS-Request-State: review
X-OBS-Request-Action-type: submit
X-OBS-Request-Action-target: Apache/BranchPack
X-OBS-Request-Action-source: home:Iggy:branches:kde4/BranchPack

Visit http://localhost/request/show/4

Thor wrote in request 4:
Another Body

--
Configure notifications at http://localhost/user/notifications
Open Build Service (http://localhost/)
4 changes: 3 additions & 1 deletion src/api/test/fixtures/event_mailer/comment_event
@@ -1,5 +1,7 @@
From: Thor <tschmidt@example.com>
To: Iggy Pop <Iggy@pop.org>
To: Iggy Pop <Iggy@pop.org>,
OBS Instance Superuser <root@localhost>,
Johnny Thunders <adrian@example.com>
Message-ID: <test@localhost>
In-Reply-To: obs-request-4@localhost
References: obs-request-4@localhost
Expand Down
22 changes: 8 additions & 14 deletions src/api/test/functional/webui/request_controller_test.rb
Expand Up @@ -265,39 +265,33 @@ def verify_email(fixture_name, myid, email)

# adrian is reviewer, Iggy creator, Admin (fixture) commenter
# tom is commenter *and* author, so doesn't get mail
assert_difference 'ActionMailer::Base.deliveries.size', +3 do
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
fill_in 'title', with: 'Comment Title'
fill_in 'body', with: 'Comment Body'
find_button('Add comment').click
page.must_have_text 'Comment Title'
end

ActionMailer::Base.deliveries.each do |email|
assert_equal 'New comment in request 4 by tom: Comment Title', email.subject
assert_includes %w(Iggy@pop.org adrian@example.com root@localhost), email.to[0]

if email.to[0] =~ %r{Iggy}
verify_email('comment_event', '4', email)
end
end
email = ActionMailer::Base.deliveries.last
assert_equal 'New comment in request 4 by tom: Comment Title', email.subject
verify_email('comment_event', '4', email)

# now check the commenters get no more mails too if unsubscribed
EventSubscription.where(eventtype: 'Event::CommentForRequest', receiver_role: :commenter).delete_all

ActionMailer::Base.deliveries.clear

# adrian is reviewer, Iggy creator, Admin (fixture) commenter
assert_difference 'ActionMailer::Base.deliveries.size', +2 do
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
fill_in 'title', with: 'Another Title'
fill_in 'body', with: 'Another Body'
find_button('Add comment').click
page.must_have_text 'Another Title'
end

ActionMailer::Base.deliveries.each do |email|
assert_equal 'New comment in request 4 by tom: Another Title', email.subject
assert_includes %w(Iggy@pop.org adrian@example.com), email.to[0]
end
email = ActionMailer::Base.deliveries.last
assert_equal 'New comment in request 4 by tom: Another Title', email.subject
verify_email('another_comment_event', '4', email)
end
end

0 comments on commit aa37e9c

Please sign in to comment.