Skip to content

Commit

Permalink
Merge commit 'mainstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
lifo committed Aug 9, 2009
2 parents a7f09bc + bb1e177 commit 2e50110
Show file tree
Hide file tree
Showing 264 changed files with 3,933 additions and 2,176 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -11,6 +11,7 @@ actionpack/pkg
activemodel/test/fixtures/fixture_database.sqlite3
actionmailer/pkg
activesupport/pkg
activesupport/test/fixtures/isolation_test
railties/pkg
railties/test/500.html
railties/test/fixtures/tmp
Expand Down
31 changes: 26 additions & 5 deletions actionmailer/lib/action_mailer/base.rb
@@ -1,3 +1,5 @@
require 'tmpdir'

require "active_support/core_ext/class"
# Use the old layouts until actionmailer gets refactored
require "action_controller/legacy/layout"
Expand Down Expand Up @@ -224,9 +226,13 @@ module ActionMailer #:nodoc:
# * <tt>:location</tt> - The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>.
# * <tt>:arguments</tt> - The command line arguments. Defaults to <tt>-i -t</tt>.
#
# * <tt>file_settings</tt> - Allows you to override options for the <tt>:file</tt> delivery method.
# * <tt>:location</tt> - The directory into which emails will be written. Defaults to the application <tt>tmp/mails</tt>.
#
# * <tt>raise_delivery_errors</tt> - Whether or not errors should be raised if the email fails to be delivered.
#
# * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default), <tt>:sendmail</tt>, and <tt>:test</tt>.
# * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default), <tt>:sendmail</tt>, <tt>:test</tt>,
# and <tt>:file</tt>.
#
# * <tt>perform_deliveries</tt> - Determines whether <tt>deliver_*</tt> methods are actually carried out. By default they are,
# but this can be turned off to help functional testing.
Expand Down Expand Up @@ -279,6 +285,12 @@ class Base
}
cattr_accessor :sendmail_settings

@@file_settings = {
:location => defined?(Rails) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails"
}

cattr_accessor :file_settings

@@raise_delivery_errors = true
cattr_accessor :raise_delivery_errors

Expand Down Expand Up @@ -499,7 +511,7 @@ def create!(method_name, *parameters) #:nodoc:
# ====
# TODO: Revisit this
# template_exists = @parts.empty?
# template_exists ||= template_root.find_by_parts("#{mailer_name}/#{@template}")
# 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,
Expand Down Expand Up @@ -556,6 +568,7 @@ def initialize_defaults(method_name)
@headers ||= {}
@body ||= {}
@mime_version = @@default_mime_version.dup if @@default_mime_version
@sent_on ||= Time.now
end

def render_template(template, body)
Expand All @@ -566,7 +579,7 @@ def render_template(template, body)
@template = initialize_template_class(body)
layout = _pick_layout(layout, true) unless
ActionController::Base.exempt_from_layout.include?(template.handler)
@template._render_template_with_layout(template, layout, {})
@template._render_template(template, layout, {})
ensure
@current_template_content_type = nil
end
Expand All @@ -585,14 +598,14 @@ def render(opts)

if file
prefix = mailer_name unless file =~ /\//
template = view_paths.find_by_parts(file, {:formats => formats}, prefix)
template = view_paths.find(file, {:formats => formats}, prefix)
end

layout = _pick_layout(layout,
!template || ActionController::Base.exempt_from_layout.include?(template.handler))

if template
@template._render_template_with_layout(template, layout, opts)
@template._render_template(template, layout, opts)
elsif inline = opts[:inline]
@template._render_inline(inline, layout, opts)
end
Expand Down Expand Up @@ -723,6 +736,14 @@ def perform_delivery_sendmail(mail)
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
Expand Down
22 changes: 22 additions & 0 deletions actionmailer/test/delivery_method_test.rb
Expand Up @@ -7,6 +7,10 @@ class NonDefaultDeliveryMethodMailer < ActionMailer::Base
self.delivery_method = :sendmail
end

class FileDeliveryMethodMailer < ActionMailer::Base
self.delivery_method = :file
end

class ActionMailerBase_delivery_method_Test < Test::Unit::TestCase
def setup
set_delivery_method :smtp
Expand Down Expand Up @@ -49,3 +53,21 @@ def test_should_be_the_set_delivery_method
end
end

class FileDeliveryMethodMailer_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_equal :file, FileDeliveryMethodMailer.delivery_method
end

def test_should_default_location_to_the_tmpdir
assert_equal "#{Dir.tmpdir}/mails", ActionMailer::Base.file_settings[:location]
end
end

27 changes: 21 additions & 6 deletions actionmailer/test/mail_service_test.rb
Expand Up @@ -18,7 +18,6 @@ def signed_up(recipient)
@recipients = recipient
@subject = "[Signed up] Welcome #{recipient}"
@from = "system@loudthinking.com"
@sent_on = Time.local(2004, 12, 12)
@body["recipient"] = recipient
end

Expand Down Expand Up @@ -357,12 +356,14 @@ def test_attachment_with_custom_header
end

def test_signed_up
Time.stubs(:now => Time.now)

expected = new_mail
expected.to = @recipient
expected.subject = "[Signed up] Welcome #{@recipient}"
expected.body = "Hello there, \n\nMr. #{@recipient}"
expected.from = "system@loudthinking.com"
expected.date = Time.local(2004, 12, 12)
expected.date = Time.now

created = nil
assert_nothing_raised { created = TestMailer.create_signed_up(@recipient) }
Expand Down Expand Up @@ -573,12 +574,14 @@ def initialize
@info_contents, @debug_contents = "", ""
end

def info(str)
@info_contents << str
def info(str = nil, &blk)
@info_contents << str if str
@info_contents << blk.call if block_given?
end

def debug(str)
@debug_contents << str
def debug(str = nil, &blk)
@debug_contents << str if str
@debug_contents << blk.call if block_given?
end
end

Expand Down Expand Up @@ -886,6 +889,18 @@ def test_headers_removed_on_smtp_delivery
assert_no_match %r{^Bcc: root@loudthinking.com}, MockSMTP.deliveries[0][0]
end

def test_file_delivery_should_create_a_file
ActionMailer::Base.delivery_method = :file
tmp_location = ActionMailer::Base.file_settings[:location]

TestMailer.deliver_cc_bcc(@recipient)
assert File.exists?(tmp_location)
assert File.directory?(tmp_location)
assert File.exists?(File.join(tmp_location, @recipient))
assert File.exists?(File.join(tmp_location, 'nobody@loudthinking.com'))
assert File.exists?(File.join(tmp_location, 'root@loudthinking.com'))
end

def test_recursive_multipart_processing
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email7")
mail = TMail::Mail.parse(fixture)
Expand Down
4 changes: 4 additions & 0 deletions actionpack/CHANGELOG
@@ -1,5 +1,9 @@
*Edge*

* Make sure javascript_include_tag/stylesheet_link_tag does not append ".js" or ".css" onto external urls. #1664 [Matthew Rudy Jacobs]

* Ruby 1.9: fix Content-Length for multibyte send_data streaming. #2661 [Sava Chankov]

* Ruby 1.9: ERB template encoding using a magic comment at the top of the file. [Jeremy Kemper]
<%# encoding: utf-8 %>

Expand Down
88 changes: 74 additions & 14 deletions actionpack/examples/minimal.rb
Expand Up @@ -3,13 +3,19 @@
ENV['NO_RELOAD'] ||= '1'

$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../activesupport/lib"
require 'action_controller'
require 'action_controller/new_base' if ENV['NEW']
require 'action_view'
require 'benchmark'

class Runner
def initialize(app)
@app = app
def initialize(app, output)
@app, @output = app, output
end

def puts(*)
super if @output
end

def call(env)
Expand All @@ -18,16 +24,22 @@ def call(env)
end

def report(env, response)
return unless ENV["DEBUG"]
out = env['rack.errors']
out.puts response[0], response[1].to_yaml, '---'
response[2].each { |part| out.puts part }
out.puts '---'
end

def self.run(app, n, label = nil)
puts '=' * label.size, label, '=' * label.size if label
env = { 'n' => n, 'rack.input' => StringIO.new(''), 'rack.errors' => $stdout }
t = Benchmark.realtime { new(app).call(env) }
def self.puts(*)
super if @output
end

def self.run(app, n, label, output = true)
@output = output
puts label, '=' * label.size if label
env = Rack::MockRequest.env_for("/").merge('n' => n, 'rack.input' => StringIO.new(''), 'rack.errors' => $stdout)
t = Benchmark.realtime { new(app, output).call(env) }
puts "%d ms / %d req = %.1f usec/req" % [10**3 * t, n, 10**6 * t / n]
puts
end
Expand All @@ -36,23 +48,71 @@ def self.run(app, n, label = nil)

N = (ENV['N'] || 1000).to_i

module ActionController::Rails2Compatibility
instance_methods.each do |name|
remove_method name
end
end

class BasePostController < ActionController::Base
append_view_path "#{File.dirname(__FILE__)}/views"

def overhead
self.response_body = ''
end

def index
render :text => ''
end

def partial
render :partial => "/partial"
end

def many_partials
render :partial => "/many_partials"
end

def partial_collection
render :partial => "/collection", :collection => [1,2,3,4,5,6,7,8,9,10]
end

def show_template
render :template => "template"
end
end

OK = [200, {}, []]
MetalPostController = lambda { OK }

if ActionController.const_defined?(:Http)
class HttpPostController < ActionController::Http
def index
self.response_body = ''
end
class HttpPostController < ActionController::Metal
def index
self.response_body = ''
end
end

Runner.run(MetalPostController, N, 'metal')
Runner.run(HttpPostController.action(:index), N, 'http') if defined? HttpPostController
Runner.run(BasePostController.action(:index), N, 'base')
unless ENV["PROFILE"]
Runner.run(BasePostController.action(:overhead), N, 'overhead', false)
Runner.run(BasePostController.action(:index), N, 'index', false)
Runner.run(BasePostController.action(:partial), N, 'partial', false)
Runner.run(BasePostController.action(:many_partials), N, 'many_partials', false)
Runner.run(BasePostController.action(:partial_collection), N, 'collection', false)
Runner.run(BasePostController.action(:show_template), N, 'template', false)

(ENV["M"] || 1).to_i.times do
Runner.run(BasePostController.action(:overhead), N, 'overhead')
Runner.run(BasePostController.action(:index), N, 'index')
Runner.run(BasePostController.action(:partial), N, 'partial')
Runner.run(BasePostController.action(:many_partials), N, 'many_partials')
Runner.run(BasePostController.action(:partial_collection), N, 'collection')
Runner.run(BasePostController.action(:show_template), N, 'template')
end
else
Runner.run(BasePostController.action(:many_partials), N, 'many_partials')
require "ruby-prof"
RubyProf.start
Runner.run(BasePostController.action(:many_partials), N, 'many_partials')
result = RubyProf.stop
printer = RubyProf::CallStackPrinter.new(result)
printer.print(File.open("output.html", "w"))
end
10 changes: 5 additions & 5 deletions actionpack/examples/very_simple.rb
Expand Up @@ -3,17 +3,17 @@

require "action_controller"

class Kaigi < ActionController::Http
class Kaigi < ActionController::Metal
include AbstractController::Callbacks
include ActionController::RackConvenience
include ActionController::Renderer
include ActionController::RenderingController
include ActionController::Layouts
include ActionView::Context

before_filter :set_name
append_view_path "views"

def _action_view
def view_context
self
end

Expand All @@ -23,7 +23,7 @@ def controller

DEFAULT_LAYOUT = Object.new.tap {|l| def l.render(*) yield end }

def _render_template_from_controller(template, layout = DEFAULT_LAYOUT, options = {}, partial = false)
def render_template(template, layout = DEFAULT_LAYOUT, options = {}, partial = false)
ret = template.render(self, {})
layout.render(self, {}) { ret }
end
Expand All @@ -47,4 +47,4 @@ def set_name
map("/kaigi/alt") { run Kaigi.action(:alt) }
end.to_app

Rack::Handler::Mongrel.run app, :Port => 3000
Rack::Handler::Mongrel.run app, :Port => 3000
1 change: 1 addition & 0 deletions actionpack/examples/views/_collection.erb
@@ -0,0 +1 @@
<%= collection %>
1 change: 1 addition & 0 deletions actionpack/examples/views/_hello.erb
@@ -0,0 +1 @@
Hello
10 changes: 10 additions & 0 deletions actionpack/examples/views/_many_partials.erb
@@ -0,0 +1,10 @@
<%= render :partial => '/hello' %>
<%= render :partial => '/hello' %>
<%= render :partial => '/hello' %>
<%= render :partial => '/hello' %>
<%= render :partial => '/hello' %>
<%= render :partial => '/hello' %>
<%= render :partial => '/hello' %>
<%= render :partial => '/hello' %>
<%= render :partial => '/hello' %>
<%= render :partial => '/hello' %>

0 comments on commit 2e50110

Please sign in to comment.