From 8cbf825425dc8ad3770881ea4e100b9023c69ce2 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 14 Oct 2009 19:50:06 -0500 Subject: Rename Orchestra to Notifications [#3321 state:resolved] --- actionmailer/lib/action_mailer/base.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'actionmailer') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index b3005c2e5e..d8b08116eb 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -394,7 +394,7 @@ module ActionMailer #:nodoc: def controller_path self.class.controller_path end - + def formats @template.formats end @@ -481,7 +481,7 @@ module ActionMailer #:nodoc: # Initialize the mailer via the given +method_name+. The body will be # rendered and a new TMail::Mail object created. def create!(method_name, *parameters) #:nodoc: - ActiveSupport::Orchestra.instrument(:create_mail, :name => method_name) do + ActiveSupport::Notifications.instrument(:create_mail, :name => method_name) do initialize_defaults(method_name) __send__(method_name, *parameters) @@ -550,7 +550,7 @@ module ActionMailer #:nodoc: logger.debug "\n#{mail.encoded}" end - ActiveSupport::Orchestra.instrument(:deliver_mail, :mail => @mail) do + ActiveSupport::Notifications.instrument(:deliver_mail, :mail => @mail) do begin __send__("perform_delivery_#{delivery_method}", mail) if perform_deliveries rescue Exception => e # Net::SMTP errors or sendmail pipe errors @@ -583,9 +583,9 @@ module ActionMailer #:nodoc: if template.respond_to?(:mime_type) @current_template_content_type = template.mime_type && template.mime_type.to_sym.to_s end - + @template = initialize_template_class(body) - layout = _pick_layout(layout, true) unless + layout = _pick_layout(layout, true) unless ActionController::Base.exempt_from_layout.include?(template.handler) @template._render_template(template, layout, {}) ensure @@ -600,16 +600,16 @@ module ActionMailer #:nodoc: def render(opts) layout, file = opts.delete(:layout), opts[:file] - + begin @template = initialize_template_class(opts.delete(:body)) - + if file prefix = mailer_name unless file =~ /\// template = view_paths.find(file, {:formats => formats}, prefix) end - layout = _pick_layout(layout, + layout = _pick_layout(layout, !template || ActionController::Base.exempt_from_layout.include?(template.handler)) if template @@ -648,7 +648,7 @@ module ActionMailer #:nodoc: def sort_parts(parts, order = []) order = order.collect { |s| s.downcase } - + parts = parts.sort do |a, b| a_ct = a.content_type.downcase b_ct = b.content_type.downcase @@ -689,7 +689,7 @@ module ActionMailer #:nodoc: headers.each { |k, v| m[k] = v } real_content_type, ctype_attrs = parse_content_type - + if @parts.empty? m.set_content_type(real_content_type, nil, ctype_attrs) m.body = normalize_new_lines(body) -- cgit v1.2.3 From 5b8e6279acaa46f22118122c49350e1b08c7371a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 14 Oct 2009 20:59:33 -0700 Subject: AV expects options[:locals] to be a Hash --- actionmailer/lib/action_mailer/base.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionmailer') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index d8b08116eb..24be66d197 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -599,6 +599,7 @@ module ActionMailer #:nodoc: end def render(opts) + opts[:locals] ||= {} layout, file = opts.delete(:layout), opts[:file] begin -- cgit v1.2.3 From 4484f0bccf1b02ff1d05d7310afe2e572befce46 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 14 Oct 2009 20:59:45 -0700 Subject: Don't push siblings on load path if using bundled env --- actionmailer/test/abstract_unit.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'actionmailer') diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index 3d4d0fb995..69af5d90a9 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -1,9 +1,15 @@ +bundled = "#{File.dirname(__FILE__)}/../vendor/gems/environment" +if File.exist?("#{bundled}.rb") + require bundled +else + $:.unshift "#{File.dirname(__FILE__)}/../../activesupport/lib" + $:.unshift "#{File.dirname(__FILE__)}/../../actionpack/lib" +end + require 'rubygems' require 'test/unit' $:.unshift "#{File.dirname(__FILE__)}/../lib" -$:.unshift "#{File.dirname(__FILE__)}/../../activesupport/lib" -$:.unshift "#{File.dirname(__FILE__)}/../../actionpack/lib" require 'action_mailer' require 'action_mailer/test_case' -- cgit v1.2.3 From d5de94d6b73f4f73acacc79ba17ebf78a107834e Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 15 Oct 2009 00:21:55 -0700 Subject: Fix AM tests by configuring AV --- actionmailer/test/abstract_unit.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionmailer') diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index 69af5d90a9..a226054194 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -20,6 +20,8 @@ ActiveSupport::Deprecation.debug = true ActionView::Template.register_template_handler :haml, lambda { |template| "Look its HAML!".inspect } ActionView::Template.register_template_handler :bak, lambda { |template| "Lame backup".inspect } +ActionView::Base.config = { :assets_dir => '/nowhere' } + $:.unshift "#{File.dirname(__FILE__)}/fixtures/helpers" FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures') -- cgit v1.2.3 From 8b340ab2f62bac2af9d5917e296bb4101530282a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 15 Oct 2009 18:06:15 -0300 Subject: Revert "Rename Orchestra to Notifications [#3321 state:resolved]" This reverts commit 8cbf825425dc8ad3770881ea4e100b9023c69ce2. --- actionmailer/lib/action_mailer/base.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'actionmailer') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 24be66d197..c0c04af51c 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -394,7 +394,7 @@ module ActionMailer #:nodoc: def controller_path self.class.controller_path end - + def formats @template.formats end @@ -481,7 +481,7 @@ module ActionMailer #:nodoc: # Initialize the mailer via the given +method_name+. The body will be # rendered and a new TMail::Mail object created. def create!(method_name, *parameters) #:nodoc: - ActiveSupport::Notifications.instrument(:create_mail, :name => method_name) do + ActiveSupport::Orchestra.instrument(:create_mail, :name => method_name) do initialize_defaults(method_name) __send__(method_name, *parameters) @@ -550,7 +550,7 @@ module ActionMailer #:nodoc: logger.debug "\n#{mail.encoded}" end - ActiveSupport::Notifications.instrument(:deliver_mail, :mail => @mail) do + ActiveSupport::Orchestra.instrument(:deliver_mail, :mail => @mail) do begin __send__("perform_delivery_#{delivery_method}", mail) if perform_deliveries rescue Exception => e # Net::SMTP errors or sendmail pipe errors @@ -583,9 +583,9 @@ module ActionMailer #:nodoc: if template.respond_to?(:mime_type) @current_template_content_type = template.mime_type && template.mime_type.to_sym.to_s end - + @template = initialize_template_class(body) - layout = _pick_layout(layout, true) unless + layout = _pick_layout(layout, true) unless ActionController::Base.exempt_from_layout.include?(template.handler) @template._render_template(template, layout, {}) ensure @@ -601,16 +601,16 @@ module ActionMailer #:nodoc: def render(opts) opts[:locals] ||= {} layout, file = opts.delete(:layout), opts[:file] - + begin @template = initialize_template_class(opts.delete(:body)) - + if file prefix = mailer_name unless file =~ /\// template = view_paths.find(file, {:formats => formats}, prefix) end - layout = _pick_layout(layout, + layout = _pick_layout(layout, !template || ActionController::Base.exempt_from_layout.include?(template.handler)) if template @@ -649,7 +649,7 @@ module ActionMailer #:nodoc: def sort_parts(parts, order = []) order = order.collect { |s| s.downcase } - + parts = parts.sort do |a, b| a_ct = a.content_type.downcase b_ct = b.content_type.downcase @@ -690,7 +690,7 @@ module ActionMailer #:nodoc: headers.each { |k, v| m[k] = v } real_content_type, ctype_attrs = parse_content_type - + if @parts.empty? m.set_content_type(real_content_type, nil, ctype_attrs) m.body = normalize_new_lines(body) -- cgit v1.2.3 From e1490d4e4c60211173d51e7b21c16dbe4c2d942a Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Thu, 15 Oct 2009 14:41:59 -0700 Subject: Change config implementation in AV slightly --- actionmailer/test/abstract_unit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionmailer') diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index a226054194..7843623996 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -20,7 +20,7 @@ ActiveSupport::Deprecation.debug = true ActionView::Template.register_template_handler :haml, lambda { |template| "Look its HAML!".inspect } ActionView::Template.register_template_handler :bak, lambda { |template| "Lame backup".inspect } -ActionView::Base.config = { :assets_dir => '/nowhere' } +ActionView::Base::DEFAULT_CONFIG = { :assets_dir => '/nowhere' } $:.unshift "#{File.dirname(__FILE__)}/fixtures/helpers" -- cgit v1.2.3 From 2d7abe245e7a2b1717e48ef550e4083318fd7ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 15 Oct 2009 18:51:51 -0300 Subject: Renamed Orchestra to Notifications once again [#3321 state:resolved] --- actionmailer/lib/action_mailer/base.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionmailer') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index c0c04af51c..df3bfb3620 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -481,7 +481,7 @@ module ActionMailer #:nodoc: # Initialize the mailer via the given +method_name+. The body will be # rendered and a new TMail::Mail object created. def create!(method_name, *parameters) #:nodoc: - ActiveSupport::Orchestra.instrument(:create_mail, :name => method_name) do + ActiveSupport::Notifications.instrument(:create_mail, :name => method_name) do initialize_defaults(method_name) __send__(method_name, *parameters) @@ -550,7 +550,7 @@ module ActionMailer #:nodoc: logger.debug "\n#{mail.encoded}" end - ActiveSupport::Orchestra.instrument(:deliver_mail, :mail => @mail) do + ActiveSupport::Notifications.instrument(:deliver_mail, :mail => @mail) do begin __send__("perform_delivery_#{delivery_method}", mail) if perform_deliveries rescue Exception => e # Net::SMTP errors or sendmail pipe errors -- cgit v1.2.3 From 6094e6516951444f8c3d6bb31f171af9fe96a02f Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 16 Oct 2009 13:56:59 -0500 Subject: We won't be publishing tars and zips anymore --- actionmailer/Rakefile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'actionmailer') diff --git a/actionmailer/Rakefile b/actionmailer/Rakefile index a756f35ee8..8a863705bb 100644 --- a/actionmailer/Rakefile +++ b/actionmailer/Rakefile @@ -50,19 +50,17 @@ spec = eval(File.read('actionmailer.gemspec')) Rake::GemPackageTask.new(spec) do |p| p.gem_spec = spec - p.need_tar = true - p.need_zip = true end desc "Publish the API documentation" -task :pgem => [:package] do +task :pgem => [:package] do require 'rake/contrib/sshpublisher' Rake::SshFilePublisher.new("gems.rubyonrails.org", "/u/sites/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload `ssh gems.rubyonrails.org '/u/sites/gems/gemupdate.sh'` end desc "Publish the API documentation" -task :pdoc => [:rdoc] do +task :pdoc => [:rdoc] do require 'rake/contrib/sshpublisher' Rake::SshDirPublisher.new("wrath.rubyonrails.org", "public_html/am", "doc").upload end -- cgit v1.2.3 From 3ccaabc6c6e7cc86084820a10202589e240c81ad Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 18 Oct 2009 10:39:21 -0500 Subject: Need to use "use_controllers" for nonexistent controller in AM test --- actionmailer/test/url_test.rb | 44 ++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'actionmailer') diff --git a/actionmailer/test/url_test.rb b/actionmailer/test/url_test.rb index 71286bd1cf..2224f6321c 100644 --- a/actionmailer/test/url_test.rb +++ b/actionmailer/test/url_test.rb @@ -1,9 +1,9 @@ require 'abstract_unit' class TestMailer < ActionMailer::Base - + default_url_options[:host] = 'www.basecamphq.com' - + def signed_up_with_url(recipient) @recipients = recipient @subject = "[Signed up] Welcome #{recipient}" @@ -52,25 +52,27 @@ class ActionMailerUrlTest < Test::Unit::TestCase end def test_signed_up_with_url - ActionController::Routing::Routes.draw do |map| - map.connect ':controller/:action/:id' - map.welcome 'welcome', :controller=>"foo", :action=>"bar" - end + ActionController::Routing.use_controllers! ['welcome'] do + ActionController::Routing::Routes.draw do |map| + map.connect ':controller/:action/:id' + map.welcome 'welcome', :controller=>"foo", :action=>"bar" + end - expected = new_mail - expected.to = @recipient - expected.subject = "[Signed up] Welcome #{@recipient}" - expected.body = "Hello there, \n\nMr. #{@recipient}. Please see our greeting at http://example.com/welcome/greeting http://www.basecamphq.com/welcome\n\n\"Somelogo\"" - expected.from = "system@loudthinking.com" - expected.date = Time.local(2004, 12, 12) - - created = nil - assert_nothing_raised { created = TestMailer.create_signed_up_with_url(@recipient) } - assert_not_nil created - assert_equal expected.encoded, created.encoded - - assert_nothing_raised { TestMailer.deliver_signed_up_with_url(@recipient) } - assert_not_nil ActionMailer::Base.deliveries.first - assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded + expected = new_mail + expected.to = @recipient + expected.subject = "[Signed up] Welcome #{@recipient}" + expected.body = "Hello there, \n\nMr. #{@recipient}. Please see our greeting at http://example.com/welcome/greeting http://www.basecamphq.com/welcome\n\n\"Somelogo\"" + expected.from = "system@loudthinking.com" + expected.date = Time.local(2004, 12, 12) + + created = nil + assert_nothing_raised { created = TestMailer.create_signed_up_with_url(@recipient) } + assert_not_nil created + assert_equal expected.encoded, created.encoded + + assert_nothing_raised { TestMailer.deliver_signed_up_with_url(@recipient) } + assert_not_nil ActionMailer::Base.deliveries.first + assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded + end end end -- cgit v1.2.3 From 16d245e79645954c20cb0a11ddaf447dc1ba1744 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 19 Oct 2009 19:25:52 -0700 Subject: Missed Gemfile commits --- actionmailer/Gemfile | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 actionmailer/Gemfile (limited to 'actionmailer') diff --git a/actionmailer/Gemfile b/actionmailer/Gemfile new file mode 100644 index 0000000000..5dec362d57 --- /dev/null +++ b/actionmailer/Gemfile @@ -0,0 +1,9 @@ +Gem.sources.each { |uri| source uri } +sibling = "#{File.dirname(__FILE__)}/.." + +gem "activesupport", "3.0.pre", :vendored_at => "#{sibling}/activesupport" +gem "activemodel", "3.0.pre", :vendored_at => "#{sibling}/activemodel" +gem "actionpack", "3.0.pre", :vendored_at => "#{sibling}/actionpack" +gem "mocha" + +#disable_system_gems -- cgit v1.2.3 From e994bf0c810925ccdbe08cff1774b2c0865e491d Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 20 Oct 2009 09:27:06 -0500 Subject: Add rackmount to actionmailer gemspec --- actionmailer/Gemfile | 1 + 1 file changed, 1 insertion(+) (limited to 'actionmailer') diff --git a/actionmailer/Gemfile b/actionmailer/Gemfile index 5dec362d57..430b32e8ca 100644 --- a/actionmailer/Gemfile +++ b/actionmailer/Gemfile @@ -4,6 +4,7 @@ sibling = "#{File.dirname(__FILE__)}/.." gem "activesupport", "3.0.pre", :vendored_at => "#{sibling}/activesupport" gem "activemodel", "3.0.pre", :vendored_at => "#{sibling}/activemodel" gem "actionpack", "3.0.pre", :vendored_at => "#{sibling}/actionpack" +gem "rack-mount", :git => "git://github.com/josh/rack-mount.git" gem "mocha" #disable_system_gems -- cgit v1.2.3 From 4f6d6f7031a88b647814fc0154e6b69b636dc912 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Tue, 20 Oct 2009 16:33:54 -0700 Subject: Have all the tests running off a single Gemfile --- actionmailer/Gemfile | 10 ---------- actionmailer/test/abstract_unit.rb | 14 +++++++------- 2 files changed, 7 insertions(+), 17 deletions(-) delete mode 100644 actionmailer/Gemfile (limited to 'actionmailer') diff --git a/actionmailer/Gemfile b/actionmailer/Gemfile deleted file mode 100644 index 430b32e8ca..0000000000 --- a/actionmailer/Gemfile +++ /dev/null @@ -1,10 +0,0 @@ -Gem.sources.each { |uri| source uri } -sibling = "#{File.dirname(__FILE__)}/.." - -gem "activesupport", "3.0.pre", :vendored_at => "#{sibling}/activesupport" -gem "activemodel", "3.0.pre", :vendored_at => "#{sibling}/activemodel" -gem "actionpack", "3.0.pre", :vendored_at => "#{sibling}/actionpack" -gem "rack-mount", :git => "git://github.com/josh/rack-mount.git" -gem "mocha" - -#disable_system_gems diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index 7843623996..fcbaa9e186 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -1,15 +1,15 @@ -bundled = "#{File.dirname(__FILE__)}/../vendor/gems/environment" -if File.exist?("#{bundled}.rb") - require bundled -else - $:.unshift "#{File.dirname(__FILE__)}/../../activesupport/lib" - $:.unshift "#{File.dirname(__FILE__)}/../../actionpack/lib" +root = File.expand_path('../../..', __FILE__) +begin + require "#{root}/vendor/gems/environment" +rescue LoadError + $:.unshift("#{root}/activesupport/lib") + $:.unshift("#{root}/actionpack/lib") + $:.unshift("#{root}/actionmailer/lib") end require 'rubygems' require 'test/unit' -$:.unshift "#{File.dirname(__FILE__)}/../lib" require 'action_mailer' require 'action_mailer/test_case' -- cgit v1.2.3 From f4f76772fb5c25357a54baaa9cd20f7e9a1cd653 Mon Sep 17 00:00:00 2001 From: Matthew Rudy Jacobs Date: Wed, 28 Oct 2009 09:17:59 +0000 Subject: abstract all of the ActionMailer delivery methods into their own classes. thereby the following are equivalent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.delivery_method = ActionMailer::DeliveryMethod::Smtp we could equally set our own custom object as long as it provides the instance method :perform_delivery(mail) eg. class MySmsDeliveryMethod def perform_delivery(mail) Sms.send(mail['to'], mail['body']) end end MySmsMailer.delivery_method = MySmsDeliveryMethod.new Signed-off-by: José Valim --- actionmailer/Rakefile | 1 + actionmailer/lib/action_mailer.rb | 1 + actionmailer/lib/action_mailer/base.rb | 75 ++++------------------ actionmailer/lib/action_mailer/delivery_method.rb | 58 +++++++++++++++++ .../lib/action_mailer/delivery_method/file.rb | 21 ++++++ .../lib/action_mailer/delivery_method/sendmail.rb | 22 +++++++ .../lib/action_mailer/delivery_method/smtp.rb | 31 +++++++++ .../lib/action_mailer/delivery_method/test.rb | 12 ++++ actionmailer/test/delivery_method_test.rb | 36 +++++++++-- actionmailer/test/mail_service_test.rb | 2 +- actionmailer/test/test_helper_test.rb | 2 +- 11 files changed, 193 insertions(+), 68 deletions(-) create mode 100644 actionmailer/lib/action_mailer/delivery_method.rb create mode 100644 actionmailer/lib/action_mailer/delivery_method/file.rb create mode 100644 actionmailer/lib/action_mailer/delivery_method/sendmail.rb create mode 100644 actionmailer/lib/action_mailer/delivery_method/smtp.rb create mode 100644 actionmailer/lib/action_mailer/delivery_method/test.rb (limited to 'actionmailer') diff --git a/actionmailer/Rakefile b/actionmailer/Rakefile index 8a863705bb..96c84b986e 100644 --- a/actionmailer/Rakefile +++ b/actionmailer/Rakefile @@ -44,6 +44,7 @@ Rake::RDocTask.new { |rdoc| rdoc.rdoc_files.include('README', 'CHANGELOG') rdoc.rdoc_files.include('lib/action_mailer.rb') rdoc.rdoc_files.include('lib/action_mailer/*.rb') + rdoc.rdoc_files.include('lib/action_mailer/delivery_method/*.rb') } spec = eval(File.read('actionmailer.gemspec')) diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index a427376579..71dc1c6eb8 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -33,6 +33,7 @@ module ActionMailer autoload :AdvAttrAccessor, 'action_mailer/adv_attr_accessor' autoload :Base, 'action_mailer/base' + autoload :DeliveryMethod, 'action_mailer/delivery_method' autoload :Helpers, 'action_mailer/helpers' autoload :Part, 'action_mailer/part' autoload :PartContainer, 'action_mailer/part_container' diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index df3bfb3620..898356075f 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -1,5 +1,3 @@ -require 'tmpdir' - require "active_support/core_ext/class" # Use the old layouts until actionmailer gets refactored require "action_controller/legacy/layout" @@ -232,7 +230,7 @@ module ActionMailer #:nodoc: # * raise_delivery_errors - Whether or not errors should be raised if the email fails to be delivered. # # * delivery_method - Defines a delivery method. Possible values are :smtp (default), :sendmail, :test, - # and :file. + # and :file. Or you may provide a custom delivery method object eg. MyOwnDeliveryMethodClass.new # # * perform_deliveries - Determines whether deliver_* methods are actually carried out. By default they are, # but this can be turned off to help functional testing. @@ -270,35 +268,21 @@ module ActionMailer #:nodoc: cattr_accessor :logger - @@smtp_settings = { - :address => "localhost", - :port => 25, - :domain => 'localhost.localdomain', - :user_name => nil, - :password => nil, - :authentication => nil, - :enable_starttls_auto => true, - } - cattr_accessor :smtp_settings - - @@sendmail_settings = { - :location => '/usr/sbin/sendmail', - :arguments => '-i -t' - } - cattr_accessor :sendmail_settings - - @@file_settings = { - :location => defined?(Rails) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails" - } - - cattr_accessor :file_settings + class << self + delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::File, :prefix => :file + delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::Sendmail, :prefix => :sendmail + delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::Smtp, :prefix => :smtp + + def delivery_method=(method_name) + @delivery_method = ActionMailer::DeliveryMethod.lookup_method(method_name) + end + end + self.delivery_method = :smtp + superclass_delegating_reader :delivery_method @@raise_delivery_errors = true cattr_accessor :raise_delivery_errors - superclass_delegating_accessor :delivery_method - self.delivery_method = :smtp - @@perform_deliveries = true cattr_accessor :perform_deliveries @@ -552,7 +536,7 @@ module ActionMailer #:nodoc: ActiveSupport::Notifications.instrument(:deliver_mail, :mail => @mail) do begin - __send__("perform_delivery_#{delivery_method}", mail) if perform_deliveries + self.delivery_method.perform_delivery(mail) if perform_deliveries rescue Exception => e # Net::SMTP errors or sendmail pipe errors raise e if raise_delivery_errors end @@ -720,39 +704,6 @@ module ActionMailer #:nodoc: @mail = m end - def perform_delivery_smtp(mail) - destinations = mail.destinations - mail.ready_to_send - sender = (mail['return-path'] && mail['return-path'].spec) || mail['from'] - - smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port]) - smtp.enable_starttls_auto if smtp_settings[:enable_starttls_auto] && smtp.respond_to?(:enable_starttls_auto) - smtp.start(smtp_settings[:domain], smtp_settings[:user_name], smtp_settings[:password], - smtp_settings[:authentication]) do |smtp| - smtp.sendmail(mail.encoded, sender, destinations) - end - end - - def perform_delivery_sendmail(mail) - sendmail_args = sendmail_settings[:arguments] - sendmail_args += " -f \"#{mail['return-path']}\"" if mail['return-path'] - IO.popen("#{sendmail_settings[:location]} #{sendmail_args}","w+") do |sm| - sm.print(mail.encoded.gsub(/\r/, '')) - sm.flush - end - end - - def perform_delivery_test(mail) - deliveries << mail - end - - def perform_delivery_file(mail) - FileUtils.mkdir_p file_settings[:location] - - (mail.to + mail.cc + mail.bcc).uniq.each do |to| - File.open(File.join(file_settings[:location], to), 'a') { |f| f.write(mail) } - end - end end Base.class_eval do diff --git a/actionmailer/lib/action_mailer/delivery_method.rb b/actionmailer/lib/action_mailer/delivery_method.rb new file mode 100644 index 0000000000..ffba3c418c --- /dev/null +++ b/actionmailer/lib/action_mailer/delivery_method.rb @@ -0,0 +1,58 @@ +require "active_support/core_ext/class" +module ActionMailer + module DeliveryMethod + + autoload :File, 'action_mailer/delivery_method/file' + autoload :Sendmail, 'action_mailer/delivery_method/sendmail' + autoload :Smtp, 'action_mailer/delivery_method/smtp' + autoload :Test, 'action_mailer/delivery_method/test' + + # Creates a new DeliveryMethod object according to the given options. + # + # If no arguments are passed to this method, then a new + # ActionMailer::DeliveryMethod::Stmp object will be returned. + # + # If you pass a Symbol as the first argument, then a corresponding + # delivery method class under the ActionMailer::DeliveryMethod namespace + # will be created. + # For example: + # + # ActionMailer::DeliveryMethod.lookup_method(:sendmail) + # # => returns a new ActionMailer::DeliveryMethod::Sendmail object + # + # If the first argument is not a Symbol, then it will simply be returned: + # + # ActionMailer::DeliveryMethod.lookup_method(MyOwnDeliveryMethod.new) + # # => returns MyOwnDeliveryMethod.new + def self.lookup_method(delivery_method) + case delivery_method + when Symbol + method_name = delivery_method.to_s.camelize + method_class = ActionMailer::DeliveryMethod.const_get(method_name) + method_class.new() + when nil + Smtp.new + else + delivery_method + end + end + + # An abstract delivery method class. There are multiple delivery method + # classes, documented under + # See the classes under the ActionMailer::DeliveryMethod, e.g. + # ActionMailer::DeliveryMethod::Smtp. + # Smtp is the default delivery method for production + # while Test is used in testing. + # + # each delivery method exposes just one method + # + # delivery_method = ActionMailer::DeliveryMethod::Smtp.new + # + # delivery_method.perform_delivery(mail) # send the mail via smtp + class Method + superclass_delegating_accessor :settings + self.settings = {} + end + + end +end diff --git a/actionmailer/lib/action_mailer/delivery_method/file.rb b/actionmailer/lib/action_mailer/delivery_method/file.rb new file mode 100644 index 0000000000..8807a05221 --- /dev/null +++ b/actionmailer/lib/action_mailer/delivery_method/file.rb @@ -0,0 +1,21 @@ +require 'tmpdir' +module ActionMailer + module DeliveryMethod + + # A delivery method implementation which writes all mails to a file. + class File < Method + + self.settings = { + :location => defined?(Rails) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails" + } + + def perform_delivery(mail) + FileUtils.mkdir_p settings[:location] + + (mail.to + mail.cc + mail.bcc).uniq.each do |to| + ::File.open(::File.join(settings[:location], to), 'a') { |f| f.write(mail) } + end + end + end + end +end diff --git a/actionmailer/lib/action_mailer/delivery_method/sendmail.rb b/actionmailer/lib/action_mailer/delivery_method/sendmail.rb new file mode 100644 index 0000000000..34e03b8060 --- /dev/null +++ b/actionmailer/lib/action_mailer/delivery_method/sendmail.rb @@ -0,0 +1,22 @@ +module ActionMailer + module DeliveryMethod + + # A delivery method implementation which sends via sendmail. + class Sendmail < Method + + self.settings = { + :location => '/usr/sbin/sendmail', + :arguments => '-i -t' + } + + def perform_delivery(mail) + sendmail_args = settings[:arguments] + sendmail_args += " -f \"#{mail['return-path']}\"" if mail['return-path'] + IO.popen("#{settings[:location]} #{sendmail_args}","w+") do |sm| + sm.print(mail.encoded.gsub(/\r/, '')) + sm.flush + end + end + end + end +end diff --git a/actionmailer/lib/action_mailer/delivery_method/smtp.rb b/actionmailer/lib/action_mailer/delivery_method/smtp.rb new file mode 100644 index 0000000000..e39f97330c --- /dev/null +++ b/actionmailer/lib/action_mailer/delivery_method/smtp.rb @@ -0,0 +1,31 @@ +module ActionMailer + module DeliveryMethod + + # A delivery method implementation which sends via smtp. + class Smtp < Method + + self.settings = { + :address => "localhost", + :port => 25, + :domain => 'localhost.localdomain', + :user_name => nil, + :password => nil, + :authentication => nil, + :enable_starttls_auto => true, + } + + def perform_delivery(mail) + destinations = mail.destinations + mail.ready_to_send + sender = (mail['return-path'] && mail['return-path'].spec) || mail['from'] + + smtp = Net::SMTP.new(settings[:address], settings[:port]) + smtp.enable_starttls_auto if settings[:enable_starttls_auto] && smtp.respond_to?(:enable_starttls_auto) + smtp.start(settings[:domain], settings[:user_name], settings[:password], + settings[:authentication]) do |smtp| + smtp.sendmail(mail.encoded, sender, destinations) + end + end + end + end +end diff --git a/actionmailer/lib/action_mailer/delivery_method/test.rb b/actionmailer/lib/action_mailer/delivery_method/test.rb new file mode 100644 index 0000000000..e63e0abbb8 --- /dev/null +++ b/actionmailer/lib/action_mailer/delivery_method/test.rb @@ -0,0 +1,12 @@ +module ActionMailer + module DeliveryMethod + + # A delivery method implementation designed for testing, which just appends each record to the :deliveries array + class Test < Method + + def perform_delivery(mail) + ActionMailer::Base.deliveries << mail + end + end + end +end diff --git a/actionmailer/test/delivery_method_test.rb b/actionmailer/test/delivery_method_test.rb index 1b8c3ba523..8f8c6b0275 100644 --- a/actionmailer/test/delivery_method_test.rb +++ b/actionmailer/test/delivery_method_test.rb @@ -11,6 +11,21 @@ class FileDeliveryMethodMailer < ActionMailer::Base self.delivery_method = :file end +class CustomDeliveryMethod + attr_accessor :custom_deliveries + def initialize() + @customer_deliveries = [] + end + + def self.perform_delivery(mail) + self.custom_deliveries << mail + end +end + +class CustomerDeliveryMailer < ActionMailer::Base + self.delivery_method = CustomDeliveryMethod.new +end + class ActionMailerBase_delivery_method_Test < Test::Unit::TestCase def setup set_delivery_method :smtp @@ -21,7 +36,7 @@ class ActionMailerBase_delivery_method_Test < Test::Unit::TestCase end def test_should_be_the_default_smtp - assert_equal :smtp, ActionMailer::Base.delivery_method + assert_instance_of ActionMailer::DeliveryMethod::Smtp, ActionMailer::Base.delivery_method end end @@ -35,7 +50,7 @@ class DefaultDeliveryMethodMailer_delivery_method_Test < Test::Unit::TestCase end def test_should_be_the_default_smtp - assert_equal :smtp, DefaultDeliveryMethodMailer.delivery_method + assert_instance_of ActionMailer::DeliveryMethod::Smtp, DefaultDeliveryMethodMailer.delivery_method end end @@ -49,7 +64,7 @@ class NonDefaultDeliveryMethodMailer_delivery_method_Test < Test::Unit::TestCase end def test_should_be_the_set_delivery_method - assert_equal :sendmail, NonDefaultDeliveryMethodMailer.delivery_method + assert_instance_of ActionMailer::DeliveryMethod::Sendmail, NonDefaultDeliveryMethodMailer.delivery_method end end @@ -63,7 +78,7 @@ class FileDeliveryMethodMailer_delivery_method_Test < Test::Unit::TestCase end def test_should_be_the_set_delivery_method - assert_equal :file, FileDeliveryMethodMailer.delivery_method + assert_instance_of ActionMailer::DeliveryMethod::File, FileDeliveryMethodMailer.delivery_method end def test_should_default_location_to_the_tmpdir @@ -71,3 +86,16 @@ class FileDeliveryMethodMailer_delivery_method_Test < Test::Unit::TestCase end end +class CustomDeliveryMethodMailer_delivery_method_Test < Test::Unit::TestCase + def setup + set_delivery_method :smtp + end + + def teardown + restore_delivery_method + end + + def test_should_be_the_set_delivery_method + assert_instance_of CustomDeliveryMethod, CustomerDeliveryMailer.delivery_method + end +end diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index 5584afa8be..802c2b37d4 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -554,7 +554,7 @@ class ActionMailerTest < Test::Unit::TestCase def test_doesnt_raise_errors_when_raise_delivery_errors_is_false ActionMailer::Base.raise_delivery_errors = false - TestMailer.any_instance.expects(:perform_delivery_test).raises(Exception) + TestMailer.delivery_method.expects(:perform_delivery).raises(Exception) assert_nothing_raised { TestMailer.deliver_signed_up(@recipient) } end diff --git a/actionmailer/test/test_helper_test.rb b/actionmailer/test/test_helper_test.rb index 65b07a71b8..a9f83f555b 100644 --- a/actionmailer/test/test_helper_test.rb +++ b/actionmailer/test/test_helper_test.rb @@ -10,7 +10,7 @@ end class TestHelperMailerTest < ActionMailer::TestCase def test_setup_sets_right_action_mailer_options - assert_equal :test, ActionMailer::Base.delivery_method + assert_instance_of ActionMailer::DeliveryMethod::Test, ActionMailer::Base.delivery_method assert ActionMailer::Base.perform_deliveries assert_equal [], ActionMailer::Base.deliveries end -- cgit v1.2.3 From a9751a7034c5a2a49fd90e9f79ad5fcae103487b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 17 Oct 2009 10:31:11 -0300 Subject: Refactor ActionMailer layout and remove legacy one. --- actionmailer/lib/action_mailer/base.rb | 42 ++++++++++------------ actionmailer/lib/action_mailer/delivery_method.rb | 17 +++++---- .../lib/action_mailer/delivery_method/file.rb | 2 +- .../lib/action_mailer/delivery_method/sendmail.rb | 2 +- .../lib/action_mailer/delivery_method/smtp.rb | 2 +- .../lib/action_mailer/delivery_method/test.rb | 2 +- 6 files changed, 31 insertions(+), 36 deletions(-) (limited to 'actionmailer') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 898356075f..29afa2692a 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -1,6 +1,4 @@ -require "active_support/core_ext/class" -# Use the old layouts until actionmailer gets refactored -require "action_controller/legacy/layout" +require 'active_support/core_ext/class' module ActionMailer #:nodoc: # Action Mailer allows you to send email from your application using a mailer model and views. @@ -254,11 +252,12 @@ module ActionMailer #:nodoc: # +implicit_parts_order+. class Base include AdvAttrAccessor, PartContainer, Quoting, Utils - extend AbstractController::RenderingController + + include AbstractController::RenderingController + include AbstractController::Layouts if Object.const_defined?(:ActionController) include ActionController::UrlWriter - include ActionController::Layout end private_class_method :new #:nodoc: @@ -569,8 +568,7 @@ module ActionMailer #:nodoc: end @template = initialize_template_class(body) - layout = _pick_layout(layout, true) unless - ActionController::Base.exempt_from_layout.include?(template.handler) + layout = _layout_for_option(:default, :formats => formats) @template._render_template(template, layout, {}) ensure @current_template_content_type = nil @@ -583,25 +581,23 @@ module ActionMailer #:nodoc: end def render(opts) + file = opts[:file] opts[:locals] ||= {} - layout, file = opts.delete(:layout), opts[:file] - - begin - @template = initialize_template_class(opts.delete(:body)) - - if file - prefix = mailer_name unless file =~ /\// - template = view_paths.find(file, {:formats => formats}, prefix) - end - layout = _pick_layout(layout, - !template || ActionController::Base.exempt_from_layout.include?(template.handler)) + @template = initialize_template_class(opts.delete(:body)) - if template - @template._render_template(template, layout, opts) - elsif inline = opts[:inline] - @template._render_inline(inline, layout, opts) - end + if file + prefix = mailer_name unless file =~ /\// + template = view_paths.find(file, {:formats => formats}, prefix) + end + + layout = opts.key?(:layout) ? opts.delete(:layout) : :default + layout = _layout_for_option(layout, :formats => formats) + + if template + @template._render_template(template, layout, opts) + elsif inline = opts[:inline] + @template._render_inline(inline, layout, opts) end end diff --git a/actionmailer/lib/action_mailer/delivery_method.rb b/actionmailer/lib/action_mailer/delivery_method.rb index ffba3c418c..29a51afdc3 100644 --- a/actionmailer/lib/action_mailer/delivery_method.rb +++ b/actionmailer/lib/action_mailer/delivery_method.rb @@ -2,10 +2,10 @@ require "active_support/core_ext/class" module ActionMailer module DeliveryMethod - autoload :File, 'action_mailer/delivery_method/file' + autoload :File, 'action_mailer/delivery_method/file' autoload :Sendmail, 'action_mailer/delivery_method/sendmail' - autoload :Smtp, 'action_mailer/delivery_method/smtp' - autoload :Test, 'action_mailer/delivery_method/test' + autoload :Smtp, 'action_mailer/delivery_method/smtp' + autoload :Test, 'action_mailer/delivery_method/test' # Creates a new DeliveryMethod object according to the given options. # @@ -27,18 +27,17 @@ module ActionMailer def self.lookup_method(delivery_method) case delivery_method when Symbol - method_name = delivery_method.to_s.camelize + method_name = delivery_method.to_s.camelize method_class = ActionMailer::DeliveryMethod.const_get(method_name) - method_class.new() - when nil + method_class.new + when nil # default Smtp.new else delivery_method end end - # An abstract delivery method class. There are multiple delivery method - # classes, documented under + # An abstract delivery method class. There are multiple delivery method classes. # See the classes under the ActionMailer::DeliveryMethod, e.g. # ActionMailer::DeliveryMethod::Smtp. # Smtp is the default delivery method for production @@ -47,8 +46,8 @@ module ActionMailer # each delivery method exposes just one method # # delivery_method = ActionMailer::DeliveryMethod::Smtp.new - # # delivery_method.perform_delivery(mail) # send the mail via smtp + # class Method superclass_delegating_accessor :settings self.settings = {} diff --git a/actionmailer/lib/action_mailer/delivery_method/file.rb b/actionmailer/lib/action_mailer/delivery_method/file.rb index 8807a05221..587ae37ffa 100644 --- a/actionmailer/lib/action_mailer/delivery_method/file.rb +++ b/actionmailer/lib/action_mailer/delivery_method/file.rb @@ -1,10 +1,10 @@ require 'tmpdir' + module ActionMailer module DeliveryMethod # A delivery method implementation which writes all mails to a file. class File < Method - self.settings = { :location => defined?(Rails) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails" } diff --git a/actionmailer/lib/action_mailer/delivery_method/sendmail.rb b/actionmailer/lib/action_mailer/delivery_method/sendmail.rb index 34e03b8060..db55af79f1 100644 --- a/actionmailer/lib/action_mailer/delivery_method/sendmail.rb +++ b/actionmailer/lib/action_mailer/delivery_method/sendmail.rb @@ -3,7 +3,6 @@ module ActionMailer # A delivery method implementation which sends via sendmail. class Sendmail < Method - self.settings = { :location => '/usr/sbin/sendmail', :arguments => '-i -t' @@ -18,5 +17,6 @@ module ActionMailer end end end + end end diff --git a/actionmailer/lib/action_mailer/delivery_method/smtp.rb b/actionmailer/lib/action_mailer/delivery_method/smtp.rb index e39f97330c..86b0ae8329 100644 --- a/actionmailer/lib/action_mailer/delivery_method/smtp.rb +++ b/actionmailer/lib/action_mailer/delivery_method/smtp.rb @@ -1,6 +1,5 @@ module ActionMailer module DeliveryMethod - # A delivery method implementation which sends via smtp. class Smtp < Method @@ -27,5 +26,6 @@ module ActionMailer end end end + end end diff --git a/actionmailer/lib/action_mailer/delivery_method/test.rb b/actionmailer/lib/action_mailer/delivery_method/test.rb index e63e0abbb8..6e3239d52a 100644 --- a/actionmailer/lib/action_mailer/delivery_method/test.rb +++ b/actionmailer/lib/action_mailer/delivery_method/test.rb @@ -3,10 +3,10 @@ module ActionMailer # A delivery method implementation designed for testing, which just appends each record to the :deliveries array class Test < Method - def perform_delivery(mail) ActionMailer::Base.deliveries << mail end end + end end -- cgit v1.2.3 From 684c2dc20801b7fcc941ec9478d33d3bf7c74551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 18 Oct 2009 20:20:14 -0200 Subject: Remove ActionMailer helpers and rely on AbstractController one. --- actionmailer/lib/action_mailer.rb | 1 - actionmailer/lib/action_mailer/base.rb | 30 ++++---- actionmailer/lib/action_mailer/helpers.rb | 114 ------------------------------ actionmailer/test/mail_service_test.rb | 10 ++- 4 files changed, 21 insertions(+), 134 deletions(-) delete mode 100644 actionmailer/lib/action_mailer/helpers.rb (limited to 'actionmailer') diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index 71dc1c6eb8..8d99d36b36 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -34,7 +34,6 @@ module ActionMailer autoload :AdvAttrAccessor, 'action_mailer/adv_attr_accessor' autoload :Base, 'action_mailer/base' autoload :DeliveryMethod, 'action_mailer/delivery_method' - autoload :Helpers, 'action_mailer/helpers' autoload :Part, 'action_mailer/part' autoload :PartContainer, 'action_mailer/part_container' autoload :Quoting, 'action_mailer/quoting' diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 29afa2692a..d01120d0d8 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -256,6 +256,9 @@ module ActionMailer #:nodoc: include AbstractController::RenderingController include AbstractController::Layouts + include AbstractController::Helpers + helper MailHelper + if Object.const_defined?(:ActionController) include ActionController::UrlWriter end @@ -442,6 +445,7 @@ module ActionMailer #:nodoc: self.view_paths && self.view_paths.first end + # Should template root overwrite the whole view_paths? def template_root=(root) self.view_paths = ActionView::Base.process_view_paths(root) end @@ -470,6 +474,11 @@ module ActionMailer #:nodoc: # If an explicit, textual body has not been set, we check assumptions. unless String === @body + # TODO Hax + @body.each do |k, v| + instance_variable_set(:"@#{k}", v) + end + # First, we look to see if there are any likely templates that match, # which include the content-type in their file name (i.e., # "the_template_file.text.html.erb", etc.). Only do this if parts @@ -480,7 +489,7 @@ module ActionMailer #:nodoc: :content_type => template.mime_type ? template.mime_type.to_s : "text/plain", :disposition => "inline", :charset => charset, - :body => render_template(template, @body) + :body => render_to_string(:_template => template) ) end @@ -562,16 +571,10 @@ module ActionMailer #:nodoc: @sent_on ||= Time.now end - def render_template(template, body) - if template.respond_to?(:mime_type) - @current_template_content_type = template.mime_type && template.mime_type.to_sym.to_s - end - - @template = initialize_template_class(body) - layout = _layout_for_option(:default, :formats => formats) - @template._render_template(template, layout, {}) - ensure - @current_template_content_type = nil + def _determine_template(options) + super + layout = options.key?(:layout) ? options[:layout] : :default + options[:_layout] = _layout_for_option(layout, options[:_template].details) end def render_message(method_name, body) @@ -701,9 +704,4 @@ module ActionMailer #:nodoc: end end - - Base.class_eval do - include Helpers - helper MailHelper - end end diff --git a/actionmailer/lib/action_mailer/helpers.rb b/actionmailer/lib/action_mailer/helpers.rb deleted file mode 100644 index ecd8f0f5b6..0000000000 --- a/actionmailer/lib/action_mailer/helpers.rb +++ /dev/null @@ -1,114 +0,0 @@ -require 'active_support/dependencies' - -module ActionMailer - module Helpers #:nodoc: - def self.included(base) #:nodoc: - # Initialize the base module to aggregate its helpers. - base.class_inheritable_accessor :master_helper_module - base.master_helper_module = Module.new - - # Extend base with class methods to declare helpers. - base.extend(ClassMethods) - - base.class_eval do - # Wrap inherited to create a new master helper module for subclasses. - class << self - alias_method_chain :inherited, :helper - end - - # Wrap initialize_template_class to extend new template class - # instances with the master helper module. - alias_method_chain :initialize_template_class, :helper - end - end - - module ClassMethods - # Makes all the (instance) methods in the helper module available to templates rendered through this controller. - # See ActionView::Helpers (link:classes/ActionView/Helpers.html) for more about making your own helper modules - # available to the templates. - def add_template_helper(helper_module) #:nodoc: - master_helper_module.module_eval "include #{helper_module}" - end - - # Declare a helper: - # helper :foo - # requires 'foo_helper' and includes FooHelper in the template class. - # helper FooHelper - # includes FooHelper in the template class. - # helper { def foo() "#{bar} is the very best" end } - # evaluates the block in the template class, adding method +foo+. - # helper(:three, BlindHelper) { def mice() 'mice' end } - # does all three. - def helper(*args, &block) - args.flatten.each do |arg| - case arg - when Module - add_template_helper(arg) - when String, Symbol - file_name = arg.to_s.underscore + '_helper' - class_name = file_name.camelize - - require_dependency(file_name, "Missing helper file helpers/%s.rb") - # begin - # require_dependency(file_name) - # rescue LoadError => load_error - # requiree = / -- (.*?)(\.rb)?$/.match(load_error.message).to_a[1] - # msg = (requiree == file_name) ? "Missing helper file helpers/#{file_name}.rb" : "Can't load file: #{requiree}" - # raise LoadError.new(msg).copy_blame!(load_error) - # end - - add_template_helper(class_name.constantize) - else - raise ArgumentError, 'helper expects String, Symbol, or Module argument' - end - end - - # Evaluate block in template class if given. - master_helper_module.module_eval(&block) if block_given? - end - - # Declare a controller method as a helper. For example, - # helper_method :link_to - # def link_to(name, options) ... end - # makes the link_to controller method available in the view. - def helper_method(*methods) - methods.flatten.each do |method| - master_helper_module.module_eval <<-end_eval - def #{method}(*args, &block) - controller.__send__(%(#{method}), *args, &block) - end - end_eval - end - end - - # Declare a controller attribute as a helper. For example, - # helper_attr :name - # attr_accessor :name - # makes the name and name= controller methods available in the view. - # The is a convenience wrapper for helper_method. - def helper_attr(*attrs) - attrs.flatten.each { |attr| helper_method(attr, "#{attr}=") } - end - - private - def inherited_with_helper(child) - inherited_without_helper(child) - begin - child.master_helper_module = Module.new - child.master_helper_module.__send__(:include, master_helper_module) - child.helper child.name.to_s.underscore - rescue MissingSourceFile => e - raise unless e.is_missing?("#{child.name.to_s.underscore}_helper") - end - end - end - - private - # Extend the template class instance with our controller's helper module. - def initialize_template_class_with_helper(assigns) - initialize_template_class_without_helper(assigns).tap do |template| - template.extend self.class.master_helper_module - end - end - end -end diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index 802c2b37d4..680fe283bd 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -1,5 +1,6 @@ # encoding: utf-8 require 'abstract_unit' +require 'active_support/testing/pending' class FunkyPathMailer < ActionMailer::Base self.template_root = "#{File.dirname(__FILE__)}/fixtures/path.with.dots" @@ -279,7 +280,7 @@ class TestMailer < ActionMailer::Base body :body => "foo", :bar => "baz" end - class < Date: Sun, 18 Oct 2009 22:52:36 -0200 Subject: Move all render and layout pieces required in ActionMailer from ActionController to AbstractController. --- actionmailer/lib/action_mailer/base.rb | 168 ++++++++++++++------------------- actionmailer/test/mail_render_test.rb | 15 ++- 2 files changed, 84 insertions(+), 99 deletions(-) (limited to 'actionmailer') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index d01120d0d8..3009d8cdfc 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -376,13 +376,19 @@ module ActionMailer #:nodoc: # The mail object instance referenced by this mailer. attr_reader :mail attr_reader :template_name, :default_template_name, :action_name + attr_internal :response_body def controller_path self.class.controller_path end - + def formats - @template.formats + [:"*/*"] + end + + # Refactor out all mailer_name + def _prefix + mailer_name end class << self @@ -468,67 +474,68 @@ module ActionMailer #:nodoc: # Initialize the mailer via the given +method_name+. The body will be # rendered and a new TMail::Mail object created. def create!(method_name, *parameters) #:nodoc: - ActiveSupport::Notifications.instrument(:create_mail, :name => method_name) do - initialize_defaults(method_name) - __send__(method_name, *parameters) + initialize_defaults(method_name) + __send__(method_name, *parameters) + + # Check if render was called. + @body = self.response_body if @body.is_a?(Hash) && @body.empty? - # If an explicit, textual body has not been set, we check assumptions. - unless String === @body - # TODO Hax + # If an explicit, textual body has not been set, we check assumptions. + unless String === @body + # TODO Fix me. Deprecate assigns to be given as a :body hash + if @body.is_a?(Hash) @body.each do |k, v| instance_variable_set(:"@#{k}", v) end - - # First, we look to see if there are any likely templates that match, - # which include the content-type in their file name (i.e., - # "the_template_file.text.html.erb", etc.). Only do this if parts - # have not already been specified manually. - # if @parts.empty? - template_root.find_all(@template, {}, template_path).each do |template| - @parts << Part.new( - :content_type => template.mime_type ? template.mime_type.to_s : "text/plain", - :disposition => "inline", - :charset => charset, - :body => render_to_string(:_template => template) - ) - end - - if @parts.size > 1 - @content_type = "multipart/alternative" if @content_type !~ /^multipart/ - @parts = sort_parts(@parts, @implicit_parts_order) - end - # end - - # Then, if there were such templates, we check to see if we ought to - # also render a "normal" template (without the content type). If a - # normal template exists (or if there were no implicit parts) we render - # it. - # ==== - # TODO: Revisit this - # template_exists = @parts.empty? - # template_exists ||= template_root.find("#{mailer_name}/#{@template}") - # @body = render_message(@template, @body) if template_exists - - # Finally, if there are other message parts and a textual body exists, - # we shift it onto the front of the parts and set the body to nil (so - # that create_mail doesn't try to render it in addition to the parts). - # ==== - # TODO: Revisit this - # if !@parts.empty? && String === @body - # @parts.unshift Part.new(:charset => charset, :body => @body) - # @body = nil - # end end - # If this is a multipart e-mail add the mime_version if it is not - # already set. - @mime_version ||= "1.0" if !@parts.empty? + # First, we look to see if there are any likely templates that match, + # which include the content-type in their file name (i.e., + # "the_template_file.text.html.erb", etc.). Only do this if parts + # have not already been specified manually. + # if @parts.empty? + template_root.find_all(@template, {}, template_path).each do |template| + @parts << Part.new( + :content_type => template.mime_type ? template.mime_type.to_s : "text/plain", + :disposition => "inline", + :charset => charset, + :body => render_to_body(:_template => template) + ) + end - # build the mail object itself - @mail = create_mail + if @parts.size > 1 + @content_type = "multipart/alternative" if @content_type !~ /^multipart/ + @parts = sort_parts(@parts, @implicit_parts_order) + end + # end + + # Then, if there were such templates, we check to see if we ought to + # also render a "normal" template (without the content type). If a + # normal template exists (or if there were no implicit parts) we render + # it. + # ==== + # TODO: Revisit this + # template_exists = @parts.empty? + # template_exists ||= template_root.find("#{mailer_name}/#{@template}") + # @body = render_message(@template, @body) if template_exists + + # Finally, if there are other message parts and a textual body exists, + # we shift it onto the front of the parts and set the body to nil (so + # that create_mail doesn't try to render it in addition to the parts). + # ==== + # TODO: Revisit this + # if !@parts.empty? && String === @body + # @parts.unshift Part.new(:charset => charset, :body => @body) + # @body = nil + # end end - @mail + # If this is a multipart e-mail add the mime_version if it is not + # already set. + @mime_version ||= "1.0" if !@parts.empty? + + # build the mail object itself + @mail = create_mail end # Delivers a TMail::Mail object. By default, it delivers the cached mail @@ -537,7 +544,7 @@ module ActionMailer #:nodoc: def deliver!(mail = @mail) raise "no mail object available for delivery!" unless mail - unless logger.nil? + if logger logger.info "Sent mail to #{Array(recipients).join(', ')}" logger.debug "\n#{mail.encoded}" end @@ -571,45 +578,16 @@ module ActionMailer #:nodoc: @sent_on ||= Time.now end - def _determine_template(options) - super - layout = options.key?(:layout) ? options[:layout] : :default - options[:_layout] = _layout_for_option(layout, options[:_template].details) - end - - def render_message(method_name, body) - render :file => method_name, :body => body - ensure - @current_template_content_type = nil - end - - def render(opts) - file = opts[:file] - opts[:locals] ||= {} - - @template = initialize_template_class(opts.delete(:body)) - - if file - prefix = mailer_name unless file =~ /\// - template = view_paths.find(file, {:formats => formats}, prefix) + def render(*args) + # TODO Fix me. Deprecate assigns to be given as a :body hash + options = args.last.is_a?(Hash) ? args.last : {} + if options[:body] + options.delete(:body).each do |k, v| + instance_variable_set(:"@#{k}", v) + end end - layout = opts.key?(:layout) ? opts.delete(:layout) : :default - layout = _layout_for_option(layout, :formats => formats) - - if template - @template._render_template(template, layout, opts) - elsif inline = opts[:inline] - @template._render_inline(inline, layout, opts) - end - end - - def default_template_format - if @current_template_content_type - Mime::Type.lookup(@current_template_content_type).to_sym - else - :html - end + super end def template_root @@ -624,12 +602,6 @@ module ActionMailer #:nodoc: "#{mailer_name}" end - def initialize_template_class(assigns) - template = ActionView::Base.new(self.class.view_paths, assigns, self) - template.formats = [default_template_format] - template - end - def sort_parts(parts, order = []) order = order.collect { |s| s.downcase } diff --git a/actionmailer/test/mail_render_test.rb b/actionmailer/test/mail_render_test.rb index 45811612eb..3f66fb1e43 100644 --- a/actionmailer/test/mail_render_test.rb +++ b/actionmailer/test/mail_render_test.rb @@ -12,7 +12,15 @@ class RenderMailer < ActionMailer::Base recipients recipient subject "using helpers" from "tester@example.com" - body render(:file => "signed_up", :body => { :recipient => recipient }) + body render(:file => "templates/signed_up", :body => { :recipient => recipient }) + end + + def implicit_body(recipient) + recipients recipient + subject "using helpers" + from "tester@example.com" + + render(:template => "templates/signed_up", :body => { :recipient => recipient }) end def rxml_template(recipient) @@ -69,6 +77,11 @@ class RenderHelperTest < Test::Unit::TestCase restore_delivery_method end + def test_implicit_body + mail = RenderMailer.create_implicit_body(@recipient) + assert_equal "Hello there, \n\nMr. test@localhost", mail.body.strip + end + def test_inline_template mail = RenderMailer.create_inline_template(@recipient) assert_equal "Hello, Earth", mail.body.strip -- cgit v1.2.3 From 03960048616593c249745d1e321dbcc7f0483c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 21 Oct 2009 17:47:10 -0200 Subject: Add some basic render_test to AbstractController. --- actionmailer/lib/action_mailer/base.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'actionmailer') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 3009d8cdfc..e3690577e1 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -386,11 +386,6 @@ module ActionMailer #:nodoc: [:"*/*"] end - # Refactor out all mailer_name - def _prefix - mailer_name - end - class << self attr_writer :mailer_name -- cgit v1.2.3 From 418c3f801cd436f011b37fe69059073e69e05084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 21 Oct 2009 21:05:55 -0200 Subject: Another refactoring on AM. body is deprecated, use render instead. --- actionmailer/lib/action_mailer.rb | 1 + actionmailer/lib/action_mailer/base.rb | 152 ++++++---------------- actionmailer/lib/action_mailer/deprecated_body.rb | 44 +++++++ actionmailer/test/mail_service_test.rb | 8 +- 4 files changed, 90 insertions(+), 115 deletions(-) create mode 100644 actionmailer/lib/action_mailer/deprecated_body.rb (limited to 'actionmailer') diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index 8d99d36b36..23f04a11ba 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -32,6 +32,7 @@ module ActionMailer end autoload :AdvAttrAccessor, 'action_mailer/adv_attr_accessor' + autoload :DeprecatedBody, 'action_mailer/deprecated_body' autoload :Base, 'action_mailer/base' autoload :DeliveryMethod, 'action_mailer/delivery_method' autoload :Part, 'action_mailer/part' diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index e3690577e1..3d71ba5a14 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -263,6 +263,8 @@ module ActionMailer #:nodoc: include ActionController::UrlWriter end + include ActionMailer::DeprecatedBody + private_class_method :new #:nodoc: class_inheritable_accessor :view_paths @@ -304,16 +306,11 @@ module ActionMailer #:nodoc: cattr_accessor :default_implicit_parts_order cattr_reader :protected_instance_variables - @@protected_instance_variables = %w(@body) + @@protected_instance_variables = [] # Specify the BCC addresses for the message adv_attr_accessor :bcc - # Define the body of the message. This is either a Hash (in which case it - # specifies the variables to pass to the template when it is rendered), - # or a string, in which case it specifies the actual text of the message. - adv_attr_accessor :body - # Specify the CC addresses for the message. adv_attr_accessor :cc @@ -358,33 +355,27 @@ module ActionMailer #:nodoc: # have multiple mailer methods share the same template. adv_attr_accessor :template + # The mail and action_name instances referenced by this mailer. + attr_reader :mail, :action_name + + # Where the response body is stored. + attr_internal :response_body + # Override the mailer name, which defaults to an inflected version of the # mailer's class name. If you want to use a template in a non-standard # location, you can use this to specify that location. + attr_writer :mailer_name + def mailer_name(value = nil) if value - self.mailer_name = value + @mailer_name = value else - self.class.mailer_name + @mailer_name || self.class.mailer_name end end - def mailer_name=(value) - self.class.mailer_name = value - end - - # The mail object instance referenced by this mailer. - attr_reader :mail - attr_reader :template_name, :default_template_name, :action_name - attr_internal :response_body - - def controller_path - self.class.controller_path - end - - def formats - [:"*/*"] - end + # Alias controller_path to mailer_name so render :partial in views work. + alias :controller_path :mailer_name class << self attr_writer :mailer_name @@ -393,10 +384,6 @@ module ActionMailer #:nodoc: @mailer_name ||= name.underscore end - # for ActionView compatibility - alias_method :controller_name, :mailer_name - alias_method :controller_path, :mailer_name - def respond_to?(method_symbol, include_private = false) #:nodoc: matches_dynamic_method?(method_symbol) || super end @@ -472,58 +459,8 @@ module ActionMailer #:nodoc: initialize_defaults(method_name) __send__(method_name, *parameters) - # Check if render was called. - @body = self.response_body if @body.is_a?(Hash) && @body.empty? - - # If an explicit, textual body has not been set, we check assumptions. - unless String === @body - # TODO Fix me. Deprecate assigns to be given as a :body hash - if @body.is_a?(Hash) - @body.each do |k, v| - instance_variable_set(:"@#{k}", v) - end - end - - # First, we look to see if there are any likely templates that match, - # which include the content-type in their file name (i.e., - # "the_template_file.text.html.erb", etc.). Only do this if parts - # have not already been specified manually. - # if @parts.empty? - template_root.find_all(@template, {}, template_path).each do |template| - @parts << Part.new( - :content_type => template.mime_type ? template.mime_type.to_s : "text/plain", - :disposition => "inline", - :charset => charset, - :body => render_to_body(:_template => template) - ) - end - - if @parts.size > 1 - @content_type = "multipart/alternative" if @content_type !~ /^multipart/ - @parts = sort_parts(@parts, @implicit_parts_order) - end - # end - - # Then, if there were such templates, we check to see if we ought to - # also render a "normal" template (without the content type). If a - # normal template exists (or if there were no implicit parts) we render - # it. - # ==== - # TODO: Revisit this - # template_exists = @parts.empty? - # template_exists ||= template_root.find("#{mailer_name}/#{@template}") - # @body = render_message(@template, @body) if template_exists - - # Finally, if there are other message parts and a textual body exists, - # we shift it onto the front of the parts and set the body to nil (so - # that create_mail doesn't try to render it in addition to the parts). - # ==== - # TODO: Revisit this - # if !@parts.empty? && String === @body - # @parts.unshift Part.new(:charset => charset, :body => @body) - # @body = nil - # end - end + # Create e-mail parts + create_parts # If this is a multipart e-mail add the mime_version if it is not # already set. @@ -556,6 +493,7 @@ module ActionMailer #:nodoc: end private + # Set up the default values for the various instance variables of this # mailer. Subclasses may override this method to provide different # defaults. @@ -568,38 +506,42 @@ module ActionMailer #:nodoc: @mailer_name ||= self.class.name.underscore @parts ||= [] @headers ||= {} - @body ||= {} @mime_version = @@default_mime_version.dup if @@default_mime_version @sent_on ||= Time.now - end - def render(*args) - # TODO Fix me. Deprecate assigns to be given as a :body hash - options = args.last.is_a?(Hash) ? args.last : {} - if options[:body] - options.delete(:body).each do |k, v| - instance_variable_set(:"@#{k}", v) - end - end - - super + super # Run deprecation hooks end - def template_root - self.class.template_root - end + def create_parts + super # Run deprecation hooks - def template_root=(root) - self.class.template_root = root - end + if String === response_body + @parts.unshift Part.new( + :content_type => "text/plain", + :disposition => "inline", + :charset => charset, + :body => response_body + ) + else + self.class.template_root.find_all(@template, {}, mailer_name).each do |template| + @parts << Part.new( + :content_type => template.mime_type ? template.mime_type.to_s : "text/plain", + :disposition => "inline", + :charset => charset, + :body => render_to_body(:_template => template) + ) + end - def template_path - "#{mailer_name}" + if @parts.size > 1 + @content_type = "multipart/alternative" if @content_type !~ /^multipart/ + @parts = sort_parts(@parts, @implicit_parts_order) + end + end end def sort_parts(parts, order = []) order = order.collect { |s| s.downcase } - + parts = parts.sort do |a, b| a_ct = a.content_type.downcase b_ct = b.content_type.downcase @@ -648,14 +590,6 @@ module ActionMailer #:nodoc: m.set_content_type(real_content_type, nil, ctype_attrs) m.body = normalize_new_lines(@parts.first.body) else - if String === body - part = TMail::Mail.new - part.body = normalize_new_lines(body) - part.set_content_type(real_content_type, nil, ctype_attrs) - part.set_content_disposition "inline" - m.parts << part - end - @parts.each do |p| part = (TMail::Mail === p ? p : p.to_mail(self)) m.parts << part diff --git a/actionmailer/lib/action_mailer/deprecated_body.rb b/actionmailer/lib/action_mailer/deprecated_body.rb new file mode 100644 index 0000000000..982f098bc5 --- /dev/null +++ b/actionmailer/lib/action_mailer/deprecated_body.rb @@ -0,0 +1,44 @@ +module ActionMailer + # TODO Remove this module all together in a next release. Ensure that super + # hooks in ActionMailer::Base are removed as well. + module DeprecatedBody + def self.included(base) + base.class_eval do + # Define the body of the message. This is either a Hash (in which case it + # specifies the variables to pass to the template when it is rendered), + # or a string, in which case it specifies the actual text of the message. + adv_attr_accessor :body + end + end + + def initialize_defaults(method_name) + @body ||= {} + end + + def create_parts + if String === @body + ActiveSupport::Deprecation.warn('body is deprecated. To set the body with a text ' << + 'call render(:text => "body").', caller[7,1]) + self.response_body = @body + elsif @body.is_a?(Hash) && !@body.empty? + ActiveSupport::Deprecation.warn('body is deprecated. To set assigns simply ' << + 'use instance variables', caller[7,1]) + @body.each { |k, v| instance_variable_set(:"@#{k}", v) } + end + end + + def render(*args) + options = args.last.is_a?(Hash) ? args.last : {} + if options[:body] + ActiveSupport::Deprecation.warn(':body is deprecated. To set assigns simply ' << + 'use instance variables', caller[0,1]) + + options.delete(:body).each do |k, v| + instance_variable_set(:"@#{k}", v) + end + end + + super + end + end +end diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index 680fe283bd..cda394d926 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -1,6 +1,5 @@ # encoding: utf-8 require 'abstract_unit' -require 'active_support/testing/pending' class FunkyPathMailer < ActionMailer::Base self.template_root = "#{File.dirname(__FILE__)}/fixtures/path.with.dots" @@ -291,7 +290,6 @@ end class ActionMailerTest < Test::Unit::TestCase include ActionMailer::Quoting - include ActiveSupport::Testing::Pending def encode( text, charset="utf-8" ) quoted_printable( text, charset ) @@ -979,10 +977,8 @@ EOF end def test_body_is_stored_as_an_ivar - pending "needs attr_internal on @body" do - mail = TestMailer.create_body_ivar(@recipient) - assert_equal "body: foo\nbar: baz", mail.body - end + mail = TestMailer.create_body_ivar(@recipient) + assert_equal "body: foo\nbar: baz", mail.body end def test_starttls_is_enabled_if_supported -- cgit v1.2.3 From e9667ad1f0e74694d9df16fa2819a1679ee21e23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 21 Oct 2009 21:26:10 -0200 Subject: Make tests run without deprecation warning (just one left). --- actionmailer/lib/action_mailer/deprecated_body.rb | 4 +- actionmailer/test/mail_helper_test.rb | 21 ++-- actionmailer/test/mail_layout_test.rb | 8 +- actionmailer/test/mail_render_test.rb | 15 ++- actionmailer/test/mail_service_test.rb | 137 ++++++++++++---------- actionmailer/test/test_helper_test.rb | 4 +- 6 files changed, 110 insertions(+), 79 deletions(-) (limited to 'actionmailer') diff --git a/actionmailer/lib/action_mailer/deprecated_body.rb b/actionmailer/lib/action_mailer/deprecated_body.rb index 982f098bc5..50ff262432 100644 --- a/actionmailer/lib/action_mailer/deprecated_body.rb +++ b/actionmailer/lib/action_mailer/deprecated_body.rb @@ -18,11 +18,11 @@ module ActionMailer def create_parts if String === @body ActiveSupport::Deprecation.warn('body is deprecated. To set the body with a text ' << - 'call render(:text => "body").', caller[7,1]) + 'call render(:text => "body").', caller[0,10]) self.response_body = @body elsif @body.is_a?(Hash) && !@body.empty? ActiveSupport::Deprecation.warn('body is deprecated. To set assigns simply ' << - 'use instance variables', caller[7,1]) + 'use instance variables', caller[0,10]) @body.each { |k, v| instance_variable_set(:"@#{k}", v) } end end diff --git a/actionmailer/test/mail_helper_test.rb b/actionmailer/test/mail_helper_test.rb index e94aeff074..f8b002e0a7 100644 --- a/actionmailer/test/mail_helper_test.rb +++ b/actionmailer/test/mail_helper_test.rb @@ -20,28 +20,29 @@ class HelperMailer < ActionMailer::Base recipients recipient subject "using helpers" from "tester@example.com" - self.body = { :text => "emphasize me!" } + + @text = "emphasize me!" end def use_mail_helper(recipient) recipients recipient subject "using mailing helpers" from "tester@example.com" - self.body = { :text => - "But soft! What light through yonder window breaks? It is the east, " + - "and Juliet is the sun. Arise, fair sun, and kill the envious moon, " + - "which is sick and pale with grief that thou, her maid, art far more " + - "fair than she. Be not her maid, for she is envious! Her vestal " + - "livery is but sick and green, and none but fools do wear it. Cast " + - "it off!" - } + + @text = "But soft! What light through yonder window breaks? It is the east, " + + "and Juliet is the sun. Arise, fair sun, and kill the envious moon, " + + "which is sick and pale with grief that thou, her maid, art far more " + + "fair than she. Be not her maid, for she is envious! Her vestal " + + "livery is but sick and green, and none but fools do wear it. Cast " + + "it off!" end def use_helper_method(recipient) recipients recipient subject "using helpers" from "tester@example.com" - self.body = { :text => "emphasize me!" } + + @text = "emphasize me!" end private diff --git a/actionmailer/test/mail_layout_test.rb b/actionmailer/test/mail_layout_test.rb index 50901f52ec..f37c26ff69 100644 --- a/actionmailer/test/mail_layout_test.rb +++ b/actionmailer/test/mail_layout_test.rb @@ -11,14 +11,18 @@ class AutoLayoutMailer < ActionMailer::Base recipients recipient subject "You have a mail" from "tester@example.com" - body render(:inline => "Hello, <%= @world %>", :layout => 'spam', :body => { :world => "Earth" }) + + @world = "Earth" + render(:inline => "Hello, <%= @world %>", :layout => 'spam') end def nolayout(recipient) recipients recipient subject "You have a mail" from "tester@example.com" - body render(:inline => "Hello, <%= @world %>", :layout => false, :body => { :world => "Earth" }) + + @world = "Earth" + render(:inline => "Hello, <%= @world %>", :layout => false) end def multipart(recipient, type = nil) diff --git a/actionmailer/test/mail_render_test.rb b/actionmailer/test/mail_render_test.rb index 3f66fb1e43..514f7ed798 100644 --- a/actionmailer/test/mail_render_test.rb +++ b/actionmailer/test/mail_render_test.rb @@ -5,14 +5,18 @@ class RenderMailer < ActionMailer::Base recipients recipient subject "using helpers" from "tester@example.com" - body render(:inline => "Hello, <%= @world %>", :body => { :world => "Earth" }) + + @world = "Earth" + render :inline => "Hello, <%= @world %>" end def file_template(recipient) recipients recipient subject "using helpers" from "tester@example.com" - body render(:file => "templates/signed_up", :body => { :recipient => recipient }) + + @recipient = recipient + render :file => "templates/signed_up" end def implicit_body(recipient) @@ -20,7 +24,8 @@ class RenderMailer < ActionMailer::Base subject "using helpers" from "tester@example.com" - render(:template => "templates/signed_up", :body => { :recipient => recipient }) + @recipient = recipient + render :template => "templates/signed_up" end def rxml_template(recipient) @@ -39,7 +44,9 @@ class RenderMailer < ActionMailer::Base recipients recipient subject "Including another template in the one being rendered" from "tester@example.com" - body render(:inline => "Hello, <%= render \"subtemplate\" %>", :body => { :world => "Earth" }) + + @world = "Earth" + render :inline => "Hello, <%= render \"subtemplate\" %>" end def initialize_defaults(method_name) diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index cda394d926..96c00a4098 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -15,18 +15,20 @@ end class TestMailer < ActionMailer::Base def signed_up(recipient) - @recipients = recipient - @subject = "[Signed up] Welcome #{recipient}" - @from = "system@loudthinking.com" - @body["recipient"] = recipient + recipients recipient + subject "[Signed up] Welcome #{recipient}" + from "system@loudthinking.com" + + @recipient = recipient end def cancelled_account(recipient) - self.recipients = recipient - self.subject = "[Cancelled] Goodbye #{recipient}" - self.from = "system@loudthinking.com" - self.sent_on = Time.local(2004, 12, 12) - self.body = "Goodbye, Mr. #{recipient}" + recipients recipient + subject "[Cancelled] Goodbye #{recipient}" + from "system@loudthinking.com" + sent_on Time.local(2004, 12, 12) + + render :text => "Goodbye, Mr. #{recipient}" end def cc_bcc(recipient) @@ -36,7 +38,8 @@ class TestMailer < ActionMailer::Base sent_on Time.local(2004, 12, 12) cc "nobody@loudthinking.com" bcc "root@loudthinking.com" - body "Nothing to see here." + + render :text => "Nothing to see here." end def different_reply_to(recipient) @@ -45,50 +48,55 @@ class TestMailer < ActionMailer::Base from "system@loudthinking.com" sent_on Time.local(2008, 5, 23) reply_to "atraver@gmail.com" - body "Nothing to see here." + + render :text => "Nothing to see here." end def iso_charset(recipient) - @recipients = recipient - @subject = "testing isø charsets" - @from = "system@loudthinking.com" - @sent_on = Time.local 2004, 12, 12 - @cc = "nobody@loudthinking.com" - @bcc = "root@loudthinking.com" - @body = "Nothing to see here." - @charset = "iso-8859-1" + recipients recipient + subject "testing isø charsets" + from "system@loudthinking.com" + sent_on Time.local(2004, 12, 12) + cc "nobody@loudthinking.com" + bcc "root@loudthinking.com" + charset "iso-8859-1" + + render :text => "Nothing to see here." end def unencoded_subject(recipient) - @recipients = recipient - @subject = "testing unencoded subject" - @from = "system@loudthinking.com" - @sent_on = Time.local 2004, 12, 12 - @cc = "nobody@loudthinking.com" - @bcc = "root@loudthinking.com" - @body = "Nothing to see here." + recipients recipient + subject "testing unencoded subject" + from "system@loudthinking.com" + sent_on Time.local(2004, 12, 12) + cc "nobody@loudthinking.com" + bcc "root@loudthinking.com" + + render :text => "Nothing to see here." end def extended_headers(recipient) - @recipients = recipient - @subject = "testing extended headers" - @from = "Grytøyr " - @sent_on = Time.local 2004, 12, 12 - @cc = "Grytøyr " - @bcc = "Grytøyr " - @body = "Nothing to see here." - @charset = "iso-8859-1" + recipients recipient + subject "testing extended headers" + from "Grytøyr " + sent_on Time.local(2004, 12, 12) + cc "Grytøyr " + bcc "Grytøyr " + charset "iso-8859-1" + + render :text => "Nothing to see here." end def utf8_body(recipient) - @recipients = recipient - @subject = "testing utf-8 body" - @from = "Foo áëô îü " - @sent_on = Time.local 2004, 12, 12 - @cc = "Foo áëô îü " - @bcc = "Foo áëô îü " - @body = "åœö blah" - @charset = "utf-8" + recipients recipient + subject "testing utf-8 body" + from "Foo áëô îü " + sent_on Time.local(2004, 12, 12) + cc "Foo áëô îü " + bcc "Foo áëô îü " + charset "utf-8" + + render :text => "åœö blah" end def multipart_with_mime_version(recipient) @@ -128,7 +136,6 @@ class TestMailer < ActionMailer::Base subject "multipart example" from "test@example.com" sent_on Time.local(2004, 12, 12) - body "plain text default" content_type ct if ct part "text/html" do |p| @@ -138,15 +145,18 @@ class TestMailer < ActionMailer::Base attachment :content_type => "image/jpeg", :filename => "foo.jpg", :body => "123456789" + + render :text => "plain text default" end def implicitly_multipart_example(recipient, cs = nil, order = nil) - @recipients = recipient - @subject = "multipart example" - @from = "test@example.com" - @sent_on = Time.local 2004, 12, 12 - @body = { "recipient" => recipient } - @charset = cs if cs + recipients recipient + subject "multipart example" + from "test@example.com" + sent_on Time.local(2004, 12, 12) + + @charset = cs if cs + @recipient = recipient @implicit_parts_order = order if order end @@ -155,20 +165,22 @@ class TestMailer < ActionMailer::Base subject "Foo áëô îü" from "some.one@somewhere.test" template "implicitly_multipart_example" - body ({ "recipient" => "no.one@nowhere.test" }) + + @recipient = "no.one@nowhere.test" end def html_mail(recipient) recipients recipient subject "html mail" from "test@example.com" - body "Emphasize this" content_type "text/html" + + render :text => "Emphasize this" end def html_mail_with_underscores(recipient) subject "html mail with underscores" - body %{_Google} + render :text => %{_Google} end def custom_template(recipient) @@ -178,7 +190,7 @@ class TestMailer < ActionMailer::Base sent_on Time.local(2004, 12, 12) template "signed_up" - body["recipient"] = recipient + @recipient = recipient end def custom_templating_extension(recipient) @@ -187,15 +199,16 @@ class TestMailer < ActionMailer::Base from "system@loudthinking.com" sent_on Time.local(2004, 12, 12) - body["recipient"] = recipient + @recipient = recipient end def various_newlines(recipient) recipients recipient subject "various newlines" from "test@example.com" - body "line #1\nline #2\rline #3\r\nline #4\r\r" + - "line #5\n\nline#6\r\n\r\nline #7" + + render :text => "line #1\nline #2\rline #3\r\nline #4\r\r" + + "line #5\n\nline#6\r\n\r\nline #7" end def various_newlines_multipart(recipient) @@ -203,6 +216,7 @@ class TestMailer < ActionMailer::Base subject "various newlines multipart" from "test@example.com" content_type "multipart/alternative" + part :content_type => "text/plain", :body => "line #1\nline #2\rline #3\r\nline #4\r\r" part :content_type => "text/html", :body => "

line #1

\n

line #2

\r

line #3

\r\n

line #4

\r\r" end @@ -212,10 +226,12 @@ class TestMailer < ActionMailer::Base subject "nested multipart" from "test@example.com" content_type "multipart/mixed" + part :content_type => "multipart/alternative", :content_disposition => "inline", :headers => { "foo" => "bar" } do |p| p.part :content_type => "text/plain", :body => "test text\nline #2" p.part :content_type => "text/html", :body => "test HTML
\nline #2" end + attachment :content_type => "application/octet-stream",:filename => "test.txt", :body => "test abcdefghijklmnopqstuvwxyz" end @@ -224,6 +240,7 @@ class TestMailer < ActionMailer::Base subject "nested multipart with body" from "test@example.com" content_type "multipart/mixed" + part :content_type => "multipart/alternative", :content_disposition => "inline", :body => "Nothing to see here." do |p| p.part :content_type => "text/html", :body => "test HTML
" end @@ -253,7 +270,7 @@ class TestMailer < ActionMailer::Base from "One: Two " cc "Three: Four " bcc "Five: Six " - body "testing" + render :text => "testing" end def custom_content_type_attributes @@ -261,15 +278,15 @@ class TestMailer < ActionMailer::Base subject "custom content types" from "some.one@somewhere.test" content_type "text/plain; format=flowed" - body "testing" + render :text => "testing" end def return_path recipients "no.one@nowhere.test" subject "return path test" from "some.one@somewhere.test" - body "testing" headers "return-path" => "another@somewhere.test" + render :text => "testing" end def body_ivar(recipient) @@ -1024,7 +1041,7 @@ end class MethodNamingTest < Test::Unit::TestCase class TestMailer < ActionMailer::Base def send - body 'foo' + render :text => 'foo' end end diff --git a/actionmailer/test/test_helper_test.rb b/actionmailer/test/test_helper_test.rb index a9f83f555b..34c5243936 100644 --- a/actionmailer/test/test_helper_test.rb +++ b/actionmailer/test/test_helper_test.rb @@ -4,7 +4,9 @@ class TestHelperMailer < ActionMailer::Base def test recipients "test@example.com" from "tester@example.com" - body render(:inline => "Hello, <%= @world %>", :body => { :world => "Earth" }) + + @world = "Earth" + render(:inline => "Hello, <%= @world %>") end end -- cgit v1.2.3 From 81c416b72e44a75ea74ba342cd223a33f3b80caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 28 Oct 2009 09:08:55 -0200 Subject: More refactoring on ActionMailer::Base. --- actionmailer/lib/action_mailer/base.rb | 43 ++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'actionmailer') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 3d71ba5a14..49551dca51 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -272,18 +272,6 @@ module ActionMailer #:nodoc: cattr_accessor :logger - class << self - delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::File, :prefix => :file - delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::Sendmail, :prefix => :sendmail - delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::Smtp, :prefix => :smtp - - def delivery_method=(method_name) - @delivery_method = ActionMailer::DeliveryMethod.lookup_method(method_name) - end - end - self.delivery_method = :smtp - superclass_delegating_reader :delivery_method - @@raise_delivery_errors = true cattr_accessor :raise_delivery_errors @@ -305,8 +293,8 @@ 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 = [] + cattr_reader :protected_instance_variables # Specify the BCC addresses for the message adv_attr_accessor :bcc @@ -380,10 +368,18 @@ module ActionMailer #:nodoc: class << self attr_writer :mailer_name + delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::File, :prefix => :file + delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::Sendmail, :prefix => :sendmail + delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::Smtp, :prefix => :smtp + def mailer_name @mailer_name ||= name.underscore end + def delivery_method=(method_name) + @delivery_method = ActionMailer::DeliveryMethod.lookup_method(method_name) + end + def respond_to?(method_symbol, include_private = false) #:nodoc: matches_dynamic_method?(method_symbol) || super end @@ -445,6 +441,11 @@ module ActionMailer #:nodoc: end end + # Configure delivery method. Check ActionMailer::DeliveryMethod for more + # instructions. + superclass_delegating_reader :delivery_method + self.delivery_method = :smtp + # Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer # will be initialized according to the named method. If not, the mailer will # remain uninitialized (useful when you only need to invoke the "receive" @@ -498,15 +499,17 @@ module ActionMailer #:nodoc: # mailer. Subclasses may override this method to provide different # defaults. def initialize_defaults(method_name) - @charset ||= @@default_charset.dup - @content_type ||= @@default_content_type.dup + @charset ||= @@default_charset.dup + @content_type ||= @@default_content_type.dup @implicit_parts_order ||= @@default_implicit_parts_order.dup - @template ||= method_name - @default_template_name = @action_name = @template - @mailer_name ||= self.class.name.underscore - @parts ||= [] + @mime_version ||= @@default_mime_version.dup if @@default_mime_version + + @mailer_name ||= self.class.mailer_name + @template ||= method_name + @action_name = @template + + @parts ||= [] @headers ||= {} - @mime_version = @@default_mime_version.dup if @@default_mime_version @sent_on ||= Time.now super # Run deprecation hooks -- cgit v1.2.3 From 2aafdc839600240a55cea06c960d0a2a7f63016d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 28 Oct 2009 09:22:07 -0200 Subject: Use I18n on ActionMailer subjects by default. --- actionmailer/lib/action_mailer/base.rb | 10 +++++++--- actionmailer/test/mail_service_test.rb | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'actionmailer') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 49551dca51..3855ce91c8 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -463,9 +463,9 @@ module ActionMailer #:nodoc: # Create e-mail parts create_parts - # If this is a multipart e-mail add the mime_version if it is not - # already set. - @mime_version ||= "1.0" if !@parts.empty? + # Set the subject if not set yet + @subject ||= I18n.t(method_name, :scope => [:actionmailer, :subjects, mailer_name], + :default => method_name.humanize) # build the mail object itself @mail = create_mail @@ -539,6 +539,10 @@ module ActionMailer #:nodoc: @content_type = "multipart/alternative" if @content_type !~ /^multipart/ @parts = sort_parts(@parts, @implicit_parts_order) end + + # If this is a multipart e-mail add the mime_version if it is not + # already set. + @mime_version ||= "1.0" if !@parts.empty? end end diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index 96c00a4098..f9365ea90c 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -296,6 +296,12 @@ class TestMailer < ActionMailer::Base body :body => "foo", :bar => "baz" end + def subject_with_i18n(recipient) + recipients recipient + from "system@loudthinking.com" + render :text => "testing" + end + class << self attr_accessor :received_body end @@ -392,6 +398,15 @@ class ActionMailerTest < Test::Unit::TestCase assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded end + def test_subject_with_i18n + assert_nothing_raised { TestMailer.deliver_subject_with_i18n(@recipient) } + assert_equal "Subject with i18n", ActionMailer::Base.deliveries.first.subject + + I18n.backend.store_translations('en', :actionmailer => {:subjects => {:test_mailer => {:subject_with_i18n => "New Subject!"}}}) + assert_nothing_raised { TestMailer.deliver_subject_with_i18n(@recipient) } + assert_equal "New Subject!", ActionMailer::Base.deliveries.last.subject + end + def test_custom_template expected = new_mail expected.to = @recipient -- cgit v1.2.3 From 976c2647240fd40a2b706ab5e41856cd47e7b212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 28 Oct 2009 10:33:05 -0200 Subject: Extracted localized_cache.rb from ActionController, added it to AbstractController and made ActionMailer use it. --- actionmailer/lib/action_mailer/base.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionmailer') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 3855ce91c8..293af01bbf 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -254,6 +254,7 @@ module ActionMailer #:nodoc: include AdvAttrAccessor, PartContainer, Quoting, Utils include AbstractController::RenderingController + include AbstractController::LocalizedCache include AbstractController::Layouts include AbstractController::Helpers -- cgit v1.2.3 From 73a36b599ae21d444d3b1f4114306a80b37ec8d4 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 5 Nov 2009 16:04:05 -0800 Subject: Shush --- actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/parser.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionmailer') diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/parser.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/parser.rb index ab1a828471..0ddc525213 100644 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/parser.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/parser.rb @@ -43,6 +43,7 @@ module Racc class Parser + old_verbose, $VERBOSE = $VERBOSE, nil Racc_Runtime_Version = '1.4.5' Racc_Runtime_Revision = '$Revision: 1.7 $'.split[1] @@ -71,6 +72,7 @@ module Racc Racc_Runtime_Core_Revision = Racc_Runtime_Core_Revision_R Racc_Runtime_Type = 'ruby' end + $VERBOSE = old_verbose def Parser.racc_runtime_type Racc_Runtime_Type -- cgit v1.2.3 From 4a1f43878105d701fd2dd769ec3cf7e81d133c09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 9 Nov 2009 16:35:31 -0200 Subject: Change mailer subjects lookup. --- actionmailer/lib/action_mailer/base.rb | 4 ++-- actionmailer/test/mail_service_test.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'actionmailer') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 293af01bbf..6a5a598f94 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -465,8 +465,8 @@ module ActionMailer #:nodoc: create_parts # Set the subject if not set yet - @subject ||= I18n.t(method_name, :scope => [:actionmailer, :subjects, mailer_name], - :default => method_name.humanize) + @subject ||= I18n.t(:subject, :scope => [:actionmailer, mailer_name, method_name], + :default => method_name.humanize) # build the mail object itself @mail = create_mail diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index f9365ea90c..c98f0a7601 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -402,7 +402,7 @@ class ActionMailerTest < Test::Unit::TestCase assert_nothing_raised { TestMailer.deliver_subject_with_i18n(@recipient) } assert_equal "Subject with i18n", ActionMailer::Base.deliveries.first.subject - I18n.backend.store_translations('en', :actionmailer => {:subjects => {:test_mailer => {:subject_with_i18n => "New Subject!"}}}) + I18n.backend.store_translations('en', :actionmailer => {:test_mailer => {:subject_with_i18n => {:subject => "New Subject!"}}}) assert_nothing_raised { TestMailer.deliver_subject_with_i18n(@recipient) } assert_equal "New Subject!", ActionMailer::Base.deliveries.last.subject end -- cgit v1.2.3 From 11e798ae0f2f46498811282756c9d21df3d4b523 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 9 Nov 2009 23:28:36 -0600 Subject: Avoid adding component lib/ to load path multiple times --- actionmailer/test/abstract_unit.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'actionmailer') diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index fcbaa9e186..e84b3b0d23 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -4,9 +4,11 @@ begin rescue LoadError $:.unshift("#{root}/activesupport/lib") $:.unshift("#{root}/actionpack/lib") - $:.unshift("#{root}/actionmailer/lib") end +lib = File.expand_path("#{File.dirname(__FILE__)}/../lib") +$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib) + require 'rubygems' require 'test/unit' -- cgit v1.2.3 From 38e8d5b10c8a7f8084e49f6571759bb424854d03 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 9 Nov 2009 23:42:17 -0600 Subject: Enable warnings for mailer tests --- actionmailer/Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionmailer') diff --git a/actionmailer/Rakefile b/actionmailer/Rakefile index 96c84b986e..140661ecb0 100644 --- a/actionmailer/Rakefile +++ b/actionmailer/Rakefile @@ -24,7 +24,7 @@ Rake::TestTask.new { |t| t.libs << "test" t.pattern = 'test/*_test.rb' t.verbose = true - t.warning = false + t.warning = true } task :isolated_test do -- cgit v1.2.3 From d887e46c2946eb1619f551420c5d076e31f9f919 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 10 Nov 2009 14:14:17 -0800 Subject: Be sure to invoke the super chain! And initialize response body. --- actionmailer/lib/action_mailer/base.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionmailer') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 6a5a598f94..bef9bb8e79 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -452,6 +452,8 @@ module ActionMailer #:nodoc: # remain uninitialized (useful when you only need to invoke the "receive" # method, for instance). def initialize(method_name=nil, *parameters) #:nodoc: + @_response_body = nil + super() create!(method_name, *parameters) if method_name end -- cgit v1.2.3 From bbb3e5a858b2d078b2af7516a583fa12f3edb565 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 10 Nov 2009 16:50:15 -0800 Subject: Unify test:isolated across components and run by default at toplevel --- actionmailer/Rakefile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'actionmailer') diff --git a/actionmailer/Rakefile b/actionmailer/Rakefile index 140661ecb0..1a7ece5068 100644 --- a/actionmailer/Rakefile +++ b/actionmailer/Rakefile @@ -27,11 +27,13 @@ Rake::TestTask.new { |t| t.warning = true } -task :isolated_test do - ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME')) - Dir.glob("test/*_test.rb").all? do |file| - system(ruby, '-Ilib:test', file) - end or raise "Failures" +namespace :test do + task :isolated do + ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME')) + Dir.glob("test/*_test.rb").all? do |file| + system(ruby, '-Ilib:test', file) + end or raise "Failures" + end end # Generate the RDoc documentation -- cgit v1.2.3