aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-09-28 12:31:45 -0500
committerJoshua Peek <josh@joshpeek.com>2008-09-28 12:31:45 -0500
commit28bf2fa03886e3ea7d873375239395b91b8e530e (patch)
tree0d3d6982867a9c054b1f6f45c285a303d8d28cc8
parentea609b265ffc30cac00bf09a262027f96964ed6f (diff)
downloadrails-28bf2fa03886e3ea7d873375239395b91b8e530e.tar.gz
rails-28bf2fa03886e3ea7d873375239395b91b8e530e.tar.bz2
rails-28bf2fa03886e3ea7d873375239395b91b8e530e.zip
Protect body ivar from being clobbered by the mailer template assigns
-rw-r--r--actionmailer/lib/action_mailer/base.rb3
-rw-r--r--actionmailer/test/fixtures/test_mailer/body_ivar.erb2
-rw-r--r--actionmailer/test/mail_service_test.rb12
-rw-r--r--actionpack/lib/action_view/base.rb4
4 files changed, 19 insertions, 2 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index bfe435550b..043f56ba17 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -296,6 +296,9 @@ module ActionMailer #:nodoc:
@@default_implicit_parts_order = [ "text/html", "text/enriched", "text/plain" ]
cattr_accessor :default_implicit_parts_order
+ cattr_reader :protected_instance_variables
+ @@protected_instance_variables = %w(@body)
+
# Specify the BCC addresses for the message
adv_attr_accessor :bcc
diff --git a/actionmailer/test/fixtures/test_mailer/body_ivar.erb b/actionmailer/test/fixtures/test_mailer/body_ivar.erb
new file mode 100644
index 0000000000..1421e5c908
--- /dev/null
+++ b/actionmailer/test/fixtures/test_mailer/body_ivar.erb
@@ -0,0 +1,2 @@
+body: <%= @body %>
+bar: <%= @bar %> \ No newline at end of file
diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb
index f57c6f3fb8..7f9540c44b 100644
--- a/actionmailer/test/mail_service_test.rb
+++ b/actionmailer/test/mail_service_test.rb
@@ -273,6 +273,13 @@ class TestMailer < ActionMailer::Base
headers "return-path" => "another@somewhere.test"
end
+ def body_ivar(recipient)
+ recipients recipient
+ subject "Body as a local variable"
+ from "test@example.com"
+ body :body => "foo", :bar => "baz"
+ end
+
class <<self
attr_accessor :received_body
end
@@ -926,6 +933,11 @@ EOF
TestMailer.deliver_return_path
assert_match %r{^Return-Path: <another@somewhere.test>}, MockSMTP.deliveries[0][0]
end
+
+ def test_body_is_stored_as_an_ivar
+ mail = TestMailer.create_body_ivar(@recipient)
+ assert_equal "body: foo\nbar: baz", mail.body
+ end
end
end # uses_mocha
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 8c00670087..77015ad06b 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -296,9 +296,9 @@ module ActionView #:nodoc:
@assigns.each { |key, value| instance_variable_set("@#{key}", value) }
if @controller
- variables = @controller.instance_variables
+ variables = @controller.instance_variable_names
variables -= @controller.protected_instance_variables if @controller.respond_to?(:protected_instance_variables)
- variables.each {|name| instance_variable_set(name, @controller.instance_variable_get(name)) }
+ variables.each { |name| instance_variable_set(name, @controller.instance_variable_get(name)) }
end
@assigns_added = true