Skip to content

Commit

Permalink
[#175891978] Fix Spreewald Issue #157: "an email should have been sen…
Browse files Browse the repository at this point in the history
…t with" step behaves incorrectly when not specifying headers
  • Loading branch information
FLeinzi committed Dec 16, 2020
1 parent 6d7c1f8 commit 8185e71
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/spreewald_support/mail_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ def find(raw_data, type = '')
end
end

# Interpret all lines as body if there are no header-link lines
if conditions.blank?
body = [header, body].join("\n\n")
end

filename_method = Rails::VERSION::MAJOR < 3 ? 'original_filename' : 'filename'
matching_header = ActionMailer::Base.deliveries.select do |mail|
[ conditions[:to].nil? || mail.to.include?(resolve_email conditions[:to]),
Expand Down
16 changes: 16 additions & 0 deletions tests/rails-6_capybara-3/app/mailers/spreewald_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,21 @@ def text_email_with_specific_line
email
end

def html_email_for_successful_test_without_header
email
end

def text_email_for_successful_test_without_header
email
end

def html_email_for_failed_test_without_header
email
end

def text_email_for_failed_test_without_header
email
end

end

20 changes: 20 additions & 0 deletions tests/shared/app/controllers/emails_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ def send_text_email_with_specific_line
render_nothing
end

def send_html_email_for_successful_test_without_header
deliver :html_email_for_successful_test_without_header
render_nothing
end

def send_text_email_for_successful_test_without_header
deliver :text_email_for_successful_test_without_header
render_nothing
end

def send_html_email_for_failed_test_without_header
deliver :html_email_for_failed_test_without_header
render_nothing
end

def send_text_email_for_failed_test_without_header
deliver :text_email_for_failed_test_without_header
render_nothing
end

private

def deliver(method_name)
Expand Down
32 changes: 32 additions & 0 deletions tests/shared/app/models/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ def text_email_with_specific_line
email
end

def html_email_for_successful_test_without_header
email
end

def text_email_for_successful_test_without_header
email
end

def html_email_for_failed_test_without_header
email
end

def text_email_for_failed_test_without_header
email
end

else

def email
Expand Down Expand Up @@ -82,6 +98,22 @@ def text_email_with_specific_line
email
end

def html_email_for_successful_test_without_header
email
end

def text_email_for_successful_test_without_header
email
end

def html_email_for_failed_test_without_header
email
end

def text_email_for_failed_test_without_header
email
end

end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
!!!
%html(lang="en" xmlns="http://www.w3.org/1999/xhtml")
%body
%p
Bye
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
!!!
%html(lang="en" xmlns="http://www.w3.org/1999/xhtml")
%body
%p
Hello
%p
Bye
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bye
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Hello

Bye
4 changes: 4 additions & 0 deletions tests/shared/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
get '/emails/send_html_email_with_linebreaks', to: 'emails#send_html_email_with_linebreaks'
get '/emails/send_html_email_with_specific_line', to: 'emails#send_html_email_with_specific_line'
get '/emails/send_text_email_with_specific_line', to: 'emails#send_text_email_with_specific_line'
get '/emails/send_html_email_for_successful_test_without_header', to: 'emails#send_html_email_for_successful_test_without_header'
get '/emails/send_text_email_for_successful_test_without_header', to: 'emails#send_text_email_for_successful_test_without_header'
get '/emails/send_html_email_for_failed_test_without_header', to: 'emails#send_html_email_for_failed_test_without_header'
get '/emails/send_text_email_for_failed_test_without_header', to: 'emails#send_text_email_for_failed_test_without_header'

get '/forms/checkbox_form', to: 'forms#checkbox_form'
get '/forms/disabled_elements', to: 'forms#disabled_elements'
Expand Down
121 changes: 121 additions & 0 deletions tests/shared/features/shared/email_steps.feature
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,127 @@ Feature: Test Spreewald's email steps
'''
"""

# Tests without header
When I clear my emails
And I go to "/emails/send_text_email_for_successful_test_without_header"
Then the following multiline step should succeed:
"""
Then an email should have been sent with:
'''
Hello
Bye
'''
"""
And the following multiline step should succeed:
"""
Then an email should have been sent with:
'''
To: to@example.com
Hello
Bye
'''
"""
But the following multiline step should fail:
"""
Then an email should have been sent with:
'''
To: wrong-guy@example.com
Hello
Bye
'''
"""

When I clear my emails
And I go to "/emails/send_text_email_for_failed_test_without_header"
Then the following multiline step should fail:
"""
Then an email should have been sent with:
'''
Hello
Bye
'''
"""
But the following multiline step should succeed:
"""
Then an email should have been sent with:
'''
Bye
'''
"""
And the following multiline step should succeed:
"""
Then an email should have been sent with:
'''
To: to@example.com
Bye
'''
"""

When I clear my emails
And I go to "/emails/send_html_email_for_successful_test_without_header"
Then the following multiline step should succeed:
"""
Then an email should have been sent with:
'''
Hello
Bye
'''
"""
And the following multiline step should succeed:
"""
Then an email should have been sent with:
'''
To: to@example.com
Hello
Bye
'''
"""
But the following multiline step should fail:
"""
Then an email should have been sent with:
'''
To: wrong-guy@example.com
Hello
Bye
'''
"""

When I clear my emails
And I go to "/emails/send_html_email_for_failed_test_without_header"
Then the following multiline step should fail:
"""
Then an email should have been sent with:
'''
Hello
Bye
'''
"""
But the following multiline step should succeed:
"""
Then an email should have been sent with:
'''
Bye
'''
"""
And the following multiline step should succeed:
"""
Then an email should have been sent with:
'''
To: to@example.com
Bye
'''
"""

Scenario: /^I follow the (first|second|third)? ?link in the e?mail$/ (HTML e-mail body)
When I go to "/emails/send_html_email_with_links"
And I follow the first link in the email
Expand Down

0 comments on commit 8185e71

Please sign in to comment.