From 7680d86d5c7c525ca94c41197ef91e49d171e1d6 Mon Sep 17 00:00:00 2001 From: Marcus Mateus Date: Sat, 7 Feb 2009 22:01:29 -0600 Subject: [PATCH] Attempt to ensure tmail gem is correctly autoloaded * NOTE: does not currently ensure utf-8 works properly --- actionmailer/lib/action_mailer/vendor/tmail.rb | 8 ++++++-- actionmailer/test/tmail_autoloader.rb | 19 +++++++++++++++++++ actionmailer/test/tmail_test.rb | 9 +++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 actionmailer/test/tmail_autoloader.rb diff --git a/actionmailer/lib/action_mailer/vendor/tmail.rb b/actionmailer/lib/action_mailer/vendor/tmail.rb index 51d36cd..a8f29a5 100644 --- a/actionmailer/lib/action_mailer/vendor/tmail.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail.rb @@ -7,11 +7,15 @@ rescue Gem::LoadError $:.unshift "#{File.dirname(__FILE__)}/tmail-1.2.3" end +# Define the TMail module to avoid autoload failure w/ uninitialized constant TMail (avoid auto-load re-entry?) module TMail end require 'tmail' -silence_warnings do - TMail::Encoder.const_set("MAX_LINE_LEN", 200) +# TODO Somehow avoid setting this until tmail is fully loaded, but always set it +if defined? TMail::Encoder + silence_warnings do + TMail::Encoder.const_set("MAX_LINE_LEN", 200) + end end diff --git a/actionmailer/test/tmail_autoloader.rb b/actionmailer/test/tmail_autoloader.rb new file mode 100644 index 0000000..0550c03 --- /dev/null +++ b/actionmailer/test/tmail_autoloader.rb @@ -0,0 +1,19 @@ +require 'abstract_unit' + +RAILS_ENV = 'test' + +class TMailMailTest < Test::Unit::TestCase + + def test_tmail_gem_is_autoloaded_if_present + # require tmail before first use of TMail constant + require 'tmail' + assert_nothing_raised do + m = TMail::Mail.new + end + # Ensure large constant value was set for utf-8 support + # test_multiple_utf8_recipients would catch this, + # if not set and tmail loaded from gem + assert_equal 200, TMail::Encoder::MAX_LINE_LEN + end +end + diff --git a/actionmailer/test/tmail_test.rb b/actionmailer/test/tmail_test.rb index 718990e..44bd615 100644 --- a/actionmailer/test/tmail_test.rb +++ b/actionmailer/test/tmail_test.rb @@ -19,4 +19,13 @@ class TMailMailTest < Test::Unit::TestCase assert_equal 1902, mail.attachments.first.length assert_equal "application/pkcs7-signature", mail.attachments.last.content_type end + + def test_tmail_gem_autoloading + # The TMail gem '~> 1.2.3' must be installed for this test to have any effect + # Ideally we would just unload TMail and reload it, but unloading a library + # is not currently supported in Ruby... at least I'm not aware of a way. + status = `cd #{File.dirname(__FILE__)}; ruby -Iabstract_unit.rb tmail_autoloader.rb` + assert_match(/0 failures, 0 errors/, status) + end end + -- 1.6.0.2