Permalink
Browse files

Protect body ivar from being clobbered by the mailer template assigns

  • Loading branch information...
1 parent ea609b2 commit 28bf2fa03886e3ea7d873375239395b91b8e530e @josh josh committed Sep 28, 2008
@@ -296,6 +296,9 @@ class Base
@@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
@@ -0,0 +1,2 @@
+body: <%= @body %>
+bar: <%= @bar %>
@@ -273,6 +273,13 @@ def return_path
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 @@ def test_return_path_with_deliver
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
@@ -296,9 +296,9 @@ def _evaluate_assigns_and_ivars #: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

0 comments on commit 28bf2fa

Please sign in to comment.