Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

headers["X-Foo-Count"] = 2 is deprecated properly now

  • Loading branch information...
commit 688368100aade40388e1d6c298e299053363e8e4 1 parent 19fb031
Yehuda Katz wycats authored
31 actionmailer/lib/action_mailer/base.rb
View
@@ -446,6 +446,33 @@ def process(*args) #:nodoc:
super
end
+ class DeprecatedHeaderProxy < ActiveSupport::BasicObject
+ def initialize(message)
+ @message = message
+ end
+
+ def []=(key, value)
+ unless value.is_a?(String)
+ ActiveSupport::Deprecation.warn("Using a non-String object for a header's value is deprecated. " \
+ "You specified #{value.inspect} (a #{value.class}) for #{key}", caller)
+
+ value = value.to_s
+ end
+
+ @message[key] = value
+ end
+
+ def headers(hash = {})
+ hash.each_pair do |k,v|
+ self[k] = v
+ end
+ end
+
+ def method_missing(meth, *args, &block)
+ @message.send(meth, *args, &block)
+ end
+ end
+
# Allows you to pass random and unusual headers to the new +Mail::Message+ object
# which will add them to itself.
#
@@ -462,9 +489,9 @@ def process(*args) #:nodoc:
# X-Special-Domain-Specific-Header: SecretValue
def headers(args=nil)
if args
- @_message.headers(args)
+ DeprecatedHeaderProxy.new(@_message).headers(args)
else
- @_message
+ DeprecatedHeaderProxy.new(@_message)
end
end
5 actionmailer/test/base_test.rb
View
@@ -76,6 +76,11 @@ def teardown
assert_equal("Not SPAM", email['X-SPAM'].decoded)
end
+ test "deprecated non-String custom headers" do
+ email = assert_deprecated { BaseMailer.welcome_with_fixnum_header }
+ assert_equal("2", email['X-SPAM-COUNT'].decoded)
+ end
+
test "can pass random headers in as a hash to mail" do
hash = {'X-Special-Domain-Specific-Header' => "SecretValue",
'In-Reply-To' => '1234@mikel.me.com' }
5 actionmailer/test/mailers/base_mailer.rb
View
@@ -10,6 +10,11 @@ def welcome(hash = {})
mail({:subject => "The first email on new API!"}.merge!(hash))
end
+ def welcome_with_fixnum_header(hash = {})
+ headers['X-SPAM-COUNT'] = 2
+ mail({:template_name => "welcome", :subject => "The first email on new API!"}.merge!(hash))
+ end
+
def welcome_with_headers(hash = {})
headers hash
mail
Please sign in to comment.
Something went wrong with that request. Please try again.