Skip to content

Commit

Permalink
ActionMailer should depend just on AbstractController.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jan 29, 2010
1 parent 2960077 commit 3f84091
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 198 deletions.
10 changes: 9 additions & 1 deletion actionmailer/lib/action_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@
actionpack_path = File.expand_path('../../../actionpack/lib', __FILE__)
$:.unshift(actionpack_path) if File.directory?(actionpack_path) && !$:.include?(actionpack_path)

require 'action_controller'
require 'abstract_controller'
require 'action_view'

# Common ActiveSupport usage in ActionMailer
require 'active_support/core_ext/class'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/array/uniq_by'
require 'active_support/core_ext/module/attr_internal'
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/string/inflections'

module ActionMailer
extend ::ActiveSupport::Autoload

Expand Down
6 changes: 0 additions & 6 deletions actionmailer/lib/action_mailer/base.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
require 'active_support/core_ext/class'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/array/uniq_by'
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/string/inflections'
require 'mail'
require 'action_mailer/tmail_compat'
require 'action_mailer/collector'
Expand Down Expand Up @@ -254,7 +249,6 @@ class Base < AbstractController::Base
include AbstractController::LocalizedCache
include AbstractController::Layouts
include AbstractController::Helpers
include AbstractController::UrlFor
include AbstractController::Translation

helper ActionMailer::MailHelper
Expand Down
4 changes: 4 additions & 0 deletions actionmailer/lib/action_mailer/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ class Railtie < Rails::Railtie
ActionMailer::Base.send "#{k}=", v
end
end

initializer "action_mailer.url_for" do |app|
ActionMailer::Base.send(:include, ActionController::UrlFor) if defined?(ActionController)
end
end
end
33 changes: 17 additions & 16 deletions actionmailer/test/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,21 @@ def different_layout(layout_name='')
assert_equal("7bit", email.parts[1].content_transfer_encoding)
end

test "explicit multipart should be multipart" do
mail = BaseMailer.explicit_multipart
assert_not_nil(mail.content_type_parameters[:boundary])
end

test "should set a content type if only has an html part" do
mail = BaseMailer.html_only
assert_equal('text/html', mail.mime_type)
end

test "should set a content type if only has an plain text part" do
mail = BaseMailer.plain_text_only
assert_equal('text/plain', mail.mime_type)
end

test "explicit multipart with one part is rendered as body" do
email = BaseMailer.custom_block
assert_equal(0, email.parts.size)
Expand Down Expand Up @@ -456,22 +471,8 @@ def different_layout(layout_name='')
BaseMailer.expects(:welcome).returns(mail)
BaseMailer.welcome.deliver
end

test "explicit multipart should be multipart" do
mail = BaseMailer.explicit_multipart
assert_not_nil(mail.content_type_parameters[:boundary])
end

test "should set a content type if only has an html part" do
mail = BaseMailer.html_only
assert_equal('text/html', mail.mime_type)
end

test "should set a content type if only has an plain text part" do
mail = BaseMailer.plain_text_only
assert_equal('text/plain', mail.mime_type)
end


# Rendering
test "that you can specify a different template" do
mail = BaseMailer.different_template('explicit_multipart_templates')
assert_equal("HTML Explicit Multipart Templates", mail.html_part.body.decoded)
Expand Down
3 changes: 3 additions & 0 deletions actionmailer/test/old_base/url_test.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
require 'abstract_unit'
require 'action_controller'

class WelcomeController < ActionController::Base
end

class TestMailer < ActionMailer::Base
include ActionController::UrlFor

default_url_options[:host] = 'www.basecamphq.com'

def signed_up_with_url(recipient)
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/abstract_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)

require 'active_support/ruby/shim'
require 'active_support/dependencies/autoload'
require 'active_support/core_ext/module/attr_internal'
require 'active_support/core_ext/module/delegation'

Expand All @@ -17,5 +18,4 @@ module AbstractController
autoload :Logger
autoload :Rendering
autoload :Translation
autoload :UrlFor
end
156 changes: 0 additions & 156 deletions actionpack/lib/abstract_controller/url_for.rb

This file was deleted.

10 changes: 4 additions & 6 deletions actionpack/lib/action_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__)
$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
require 'active_support/ruby/shim'
require 'abstract_controller'
require 'action_dispatch'

module ActionController
extend ActiveSupport::Autoload
Expand Down Expand Up @@ -41,6 +40,7 @@ module ActionController
autoload :Integration, 'action_controller/deprecated/integration_test'
autoload :IntegrationTest, 'action_controller/deprecated/integration_test'
autoload :PerformanceTest, 'action_controller/deprecated/performance_test'
autoload :UrlWriter, 'action_controller/deprecated'
autoload :Routing, 'action_controller/deprecated'
autoload :TestCase, 'action_controller/test_case'

Expand All @@ -66,13 +66,11 @@ module ActionController
end

# All of these simply register additional autoloads
require 'abstract_controller'
require 'action_dispatch'
require 'action_view'
require 'action_controller/vendor/html-scanner'

# Common ActiveSupport usage in ActionController
require "active_support/concern"
require 'active_support/concern'
require 'active_support/core_ext/class/attribute_accessors'
require 'active_support/core_ext/load_error'
require 'active_support/core_ext/module/attr_internal'
Expand Down
8 changes: 8 additions & 0 deletions actionpack/lib/action_controller/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,13 @@ def self.filter_parameter_logging(*args, &block)
filter << block if block
filter
end

protected

# Overwrite url rewriter to use request.
def _url_rewriter
return ActionController::UrlRewriter unless request
@_url_rewriter ||= ActionController::UrlRewriter.new(request, params)
end
end
end
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/deprecated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
ActionController::AbstractResponse = ActionController::Response = ActionDispatch::Response
ActionController::Routing = ActionDispatch::Routing
ActionController::Routing::Routes = ActionDispatch::Routing::RouteSet.new
ActionController::UrlWriter = AbstractController::UrlFor
ActionController::UrlWriter = ActionController::UrlFor
Loading

0 comments on commit 3f84091

Please sign in to comment.