Skip to content

Commit

Permalink
Fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-burns committed Jun 11, 2010
2 parents 646d282 + 832f46b commit 0142d8b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/shoulda/action_mailer/matchers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'shoulda/action_mailer/matchers/have_sent_email'

module Shoulda # :nodoc:
module ActiveRecord # :nodoc:
module ActionMailer # :nodoc:
# = Matchers for your mailers
#
# This matcher will test that email is sent properly
Expand Down
14 changes: 8 additions & 6 deletions lib/shoulda/action_mailer/matchers/have_sent_email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ def to(recipient)
end

def matches?(subject)
@mail = subject
@subject_failed = !regexp_or_string_match(@mail.subject, @email_subject) if @email_subject
@body_failed = !regexp_or_string_match(@mail.body, @body) if @body
@sender_failed = !regexp_or_string_match_in_array(@mail.from, @sender) if @sender
@recipient_failed = !regexp_or_string_match_in_array(@mail.to, @recipient) if @recipient
::ActionMailer::Base.deliveries.each do |mail|
@subject_failed = !regexp_or_string_match(mail.subject, @email_subject) if @email_subject
@body_failed = !regexp_or_string_match(mail.body, @body) if @body
@sender_failed = !regexp_or_string_match_in_array(mail.from, @sender) if @sender
@recipient_failed = !regexp_or_string_match_in_array(mail.to, @recipient) if @recipient
return true unless anything_failed?
end

!anything_failed?
false
end

def failure_message
Expand Down
24 changes: 12 additions & 12 deletions test/matchers/action_mailer/have_sent_email_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,35 @@ def the_email
end
end
if defined?(AbstractController::Rendering)
@mail = Mailer.the_email
::ActionMailer::Base.deliveries << Mailer.the_email
else
@mail = Mailer.create_the_email
::ActionMailer::Base.deliveries << Mailer.create_the_email
end
end

should "accept based on the subject" do
assert_accepts have_sent_email.with_subject(/is spam$/), @mail
assert_rejects have_sent_email.with_subject(/totally safe/), @mail
assert_accepts have_sent_email.with_subject(/is spam$/), nil
assert_rejects have_sent_email.with_subject(/totally safe/), nil
end

should "accept based on the sender" do
assert_accepts have_sent_email.from('[email protected]'), @mail
assert_rejects have_sent_email.from('[email protected]'), @mail
assert_accepts have_sent_email.from('[email protected]'), nil
assert_rejects have_sent_email.from('[email protected]'), nil
end

should "accept based on the body" do
assert_accepts have_sent_email.with_body(/is spam\./), @mail
assert_rejects have_sent_email.with_body(/totally safe/), @mail
assert_accepts have_sent_email.with_body(/is spam\./), nil
assert_rejects have_sent_email.with_body(/totally safe/), nil
end

should "accept baed on the recipienct" do
assert_accepts have_sent_email.to('[email protected]'), @mail
assert_rejects have_sent_email.to('[email protected]'), @mail
assert_accepts have_sent_email.to('[email protected]'), nil
assert_rejects have_sent_email.to('[email protected]'), nil
end

should "chain" do
assert_accepts have_sent_email.with_subject(/spam/).from('[email protected]').with_body(/spam/).to('[email protected]'), @mail
assert_rejects have_sent_email.with_subject(/ham/).from('[email protected]').with_body(/ham/).to('[email protected]'), @mail
assert_accepts have_sent_email.with_subject(/spam/).from('[email protected]').with_body(/spam/).to('[email protected]'), nil
assert_rejects have_sent_email.with_subject(/ham/).from('[email protected]').with_body(/ham/).to('[email protected]'), nil
end
end
end

0 comments on commit 0142d8b

Please sign in to comment.