aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/test/base_test.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2013-12-02 16:51:13 +0100
committerYves Senn <yves.senn@gmail.com>2013-12-02 16:56:31 +0100
commit23aa94a7b2d51536baa5eb91a8cd50cdd6dfa99e (patch)
treeca9fc16632d39bc638ddb1517ac264b8bfa90e5b /actionmailer/test/base_test.rb
parentd362ee17dbd1a500fc2e0331025845d8d38977e7 (diff)
downloadrails-23aa94a7b2d51536baa5eb91a8cd50cdd6dfa99e.tar.gz
rails-23aa94a7b2d51536baa5eb91a8cd50cdd6dfa99e.tar.bz2
rails-23aa94a7b2d51536baa5eb91a8cd50cdd6dfa99e.zip
`mail()` without arguments is a getter for the current mail.
This behavior is documented in our guides (http://edgeguides.rubyonrails.org/action_mailer_basics.html#action-mailer-callbacks) but was broken in the past. This commit short curcuits the `mail` method if: 1. mail() was previously called 2. no headers are passed 3. no block is passed Closes #13090. /cc @pixeltrix
Diffstat (limited to 'actionmailer/test/base_test.rb')
-rw-r--r--actionmailer/test/base_test.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb
index b74728ae34..c1759d9b92 100644
--- a/actionmailer/test/base_test.rb
+++ b/actionmailer/test/base_test.rb
@@ -671,6 +671,27 @@ class BaseTest < ActiveSupport::TestCase
assert_equal ["robert.pankowecki@gmail.com"], DefaultFromMailer.welcome.from
end
+ test "mail() without arguments serves as getter for the current mail message" do
+ class MailerWithCallback < ActionMailer::Base
+ after_action :a_callback
+
+ def welcome
+ headers('X-Special-Header' => 'special indeed!')
+ mail subject: "subject", body: "hello world", to: ["joe@example.com"]
+ end
+
+ def a_callback
+ mail.to << "jane@example.com"
+ end
+ end
+
+ mail = MailerWithCallback.welcome
+ assert_equal "subject", mail.subject
+ assert_equal ["joe@example.com", "jane@example.com"], mail.to
+ assert_equal "hello world", mail.body.encoded.strip
+ assert_equal "special indeed!", mail["X-Special-Header"].to_s
+ end
+
protected
# Execute the block setting the given values and restoring old values after