Fixed exceptions when matching arrays of emails against regexps; fixes gh-125 (based on a patch from github.com/phene)
This commit is contained in:
parent
b0692c3978
commit
02520e40c2
|
@ -98,7 +98,7 @@ module Shoulda # :nodoc:
|
|||
def regexp_or_string_match_in_array(an_array, a_regexp_or_string)
|
||||
case a_regexp_or_string
|
||||
when Regexp
|
||||
an_array.detect{|e| e =~ a_regexp_or_string}.any?
|
||||
an_array.any? { |string| string =~ a_regexp_or_string }
|
||||
when String
|
||||
an_array.include?(a_regexp_or_string)
|
||||
end
|
||||
|
|
|
@ -37,12 +37,18 @@ class HaveSentEmailTest < ActiveSupport::TestCase # :nodoc:
|
|||
:message => /Expected sent email with subject/
|
||||
end
|
||||
|
||||
should "accept based on the sender" do
|
||||
should "accept based on a string sender" do
|
||||
assert_accepts have_sent_email.from('do-not-reply@example.com'), nil
|
||||
assert_rejects have_sent_email.from('you@example.com'), nil,
|
||||
:message => /Expected sent email from/
|
||||
end
|
||||
|
||||
should "accept based on a regexp sender" do
|
||||
assert_accepts have_sent_email.from(/@example\.com/), nil
|
||||
assert_rejects have_sent_email.from(/you@/), nil,
|
||||
:message => /Expected sent email from/
|
||||
end
|
||||
|
||||
should "accept based on the body" do
|
||||
assert_accepts have_sent_email.with_body(/is spam\./), nil
|
||||
assert_rejects have_sent_email.with_body(/totally safe/), nil,
|
||||
|
|
Loading…
Reference in New Issue