Skip to content

Commit

Permalink
Merge remote branch 'rails/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rizwanreza committed Mar 28, 2010
2 parents 4b4f69b + 66d57d7 commit b4c91de
Show file tree
Hide file tree
Showing 411 changed files with 3,065 additions and 1,786 deletions.
9 changes: 6 additions & 3 deletions Gemfile
Expand Up @@ -7,14 +7,17 @@ gem "rails", "3.0.0.beta1"
gem "rake", ">= 0.8.7"
gem "mocha", ">= 0.9.8"

if RUBY_VERSION < '1.9'
gem "ruby-debug", ">= 0.10.3"
group :mri do
if RUBY_VERSION < '1.9'
gem "system_timer"
gem "ruby-debug", ">= 0.10.3"
end
end

# AR
gem "sqlite3-ruby", ">= 1.2.5", :require => 'sqlite3'

group :test do
group :db do
gem "pg", ">= 0.9.0"
gem "mysql", ">= 2.8.1"
end
Expand Down
8 changes: 4 additions & 4 deletions Rakefile
Expand Up @@ -49,13 +49,13 @@ end

desc "Install gems for all projects."
task :install => :gem do
require File.expand_path("../actionpack/lib/action_pack/version", __FILE__)
version = File.read("RAILS_VERSION").strip
(PROJECTS - ["railties"]).each do |project|
puts "INSTALLING #{project}"
system("gem install #{project}/pkg/#{project}-#{ActionPack::VERSION::STRING}.gem --no-ri --no-rdoc")
system("gem install #{project}/pkg/#{project}-#{version}.gem --no-ri --no-rdoc")
end
system("gem install railties/pkg/railties-#{ActionPack::VERSION::STRING}.gem --no-ri --no-rdoc")
system("gem install pkg/rails-#{ActionPack::VERSION::STRING}.gem --no-ri --no-rdoc")
system("gem install railties/pkg/railties-#{version}.gem --no-ri --no-rdoc")
system("gem install pkg/rails-#{version}.gem --no-ri --no-rdoc")
end

desc "Generate documentation for the Rails framework"
Expand Down
7 changes: 5 additions & 2 deletions actionmailer/lib/action_mailer/base.rb
@@ -1,6 +1,7 @@
require 'mail'
require 'action_mailer/tmail_compat'
require 'action_mailer/collector'
require 'active_support/core_ext/array/wrap'

module ActionMailer #:nodoc:
# Action Mailer allows you to send email from your application using a mailer model and views.
Expand Down Expand Up @@ -590,7 +591,7 @@ def collect_responses_and_parts_order(headers) #:nodoc:
responses, parts_order = [], nil

if block_given?
collector = ActionMailer::Collector.new(self) { render(action_name) }
collector = ActionMailer::Collector.new(lookup_context) { render(action_name) }
yield(collector)
parts_order = collector.responses.map { |r| r[:content_type] }
responses = collector.responses
Expand All @@ -604,6 +605,8 @@ def collect_responses_and_parts_order(headers) #:nodoc:
templates_name = headers.delete(:template_name) || action_name

each_template(templates_path, templates_name) do |template|
self.formats = template.formats

responses << {
:body => render(:template => template),
:content_type => template.mime_type.to_s
Expand All @@ -615,7 +618,7 @@ def collect_responses_and_parts_order(headers) #:nodoc:
end

def each_template(paths, name, &block) #:nodoc:
Array(paths).each do |path|
Array.wrap(paths).each do |path|
templates = lookup_context.find_all(name, path)
templates = templates.uniq_by { |t| t.formats }

Expand Down
12 changes: 3 additions & 9 deletions actionmailer/lib/action_mailer/collector.rb
Expand Up @@ -11,7 +11,6 @@ def initialize(context, &block)
@context = context
@responses = []
@default_render = block
@default_formats = context.formats
end

def any(*args, &block)
Expand All @@ -21,16 +20,11 @@ def any(*args, &block)
end
alias :all :any

def custom(mime, options={}, &block)
def custom(mime, options={})
options.reverse_merge!(:content_type => mime.to_s)
@context.formats = [mime.to_sym]
options[:body] = if block
block.call
else
@default_render.call
end
@context.freeze_formats([mime.to_sym])
options[:body] = block_given? ? yield : @default_render.call
@responses << options
@context.formats = @default_formats
end
end
end
4 changes: 1 addition & 3 deletions actionmailer/lib/action_mailer/old_api.rb
Expand Up @@ -31,9 +31,6 @@ module OldApi #:nodoc:
# replies to this message.
adv_attr_accessor :reply_to

# Specify additional headers to be added to the message.
adv_attr_accessor :headers

# Specify the order in which parts should be sorted, based on content-type.
# This defaults to the value for the +default_implicit_parts_order+.
adv_attr_accessor :implicit_parts_order
Expand Down Expand Up @@ -207,6 +204,7 @@ def create_parts
@parts.unshift create_inline_part(@body)
elsif @parts.empty? || @parts.all? { |p| p.content_disposition =~ /^attachment/ }
lookup_context.find_all(@template, @mailer_name).each do |template|
self.formats = template.formats
@parts << create_inline_part(render(:template => template), template.mime_type)
end

Expand Down
4 changes: 2 additions & 2 deletions actionmailer/lib/action_mailer/railtie.rb
Expand Up @@ -3,14 +3,14 @@

module ActionMailer
class Railtie < Rails::Railtie
railtie_name :action_mailer
config.action_mailer = ActiveSupport::OrderedOptions.new

initializer "action_mailer.url_for", :before => :load_environment_config do |app|
ActionMailer.base_hook { include app.routes.url_helpers }
end

require "action_mailer/railties/log_subscriber"
log_subscriber ActionMailer::Railties::LogSubscriber.new
log_subscriber :action_mailer, ActionMailer::Railties::LogSubscriber.new

initializer "action_mailer.logger" do
ActionMailer.base_hook { self.logger ||= Rails.logger }
Expand Down
6 changes: 4 additions & 2 deletions actionmailer/lib/action_mailer/railties/log_subscriber.rb
@@ -1,8 +1,10 @@
require 'active_support/core_ext/array/wrap'

module ActionMailer
module Railties
class LogSubscriber < Rails::LogSubscriber
def deliver(event)
recipients = Array(event.payload[:to]).join(', ')
recipients = Array.wrap(event.payload[:to]).join(', ')
info("\nSent mail to #{recipients} (%1.fms)" % event.duration)
debug(event.payload[:mail])
end
Expand All @@ -17,4 +19,4 @@ def logger
end
end
end
end
end
21 changes: 20 additions & 1 deletion actionmailer/test/abstract_unit.rb
@@ -1,4 +1,23 @@
require File.expand_path('../../../load_paths', __FILE__)
# Pathname has a warning, so require it first while silencing
# warnings to shut it up.
#
# Also, in 1.9, Bundler creates warnings due to overriding
# Rubygems methods
begin
old, $VERBOSE = $VERBOSE, nil
require 'pathname'
require File.expand_path('../../../load_paths', __FILE__)
ensure
$VERBOSE = old
end


require 'active_support/core_ext/kernel/reporting'
silence_warnings do
# These external dependencies have warnings :/
require 'text/format'
require 'mail'
end

lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
Expand Down
58 changes: 36 additions & 22 deletions actionmailer/test/base_test.rb
Expand Up @@ -74,13 +74,20 @@ def explicit_multipart_with_any(hash = {})
end
end

def custom_block(include_html=false)
def explicit_multipart_with_options(include_html = false)
mail do |format|
format.text(:content_transfer_encoding => "base64"){ render "welcome" }
format.html{ render "welcome" } if include_html
end
end

def explicit_multipart_with_one_template(hash = {})
mail(hash) do |format|
format.html
format.text
end
end

def implicit_different_template(template_name='')
mail(:template_name => template_name)
end
Expand Down Expand Up @@ -148,6 +155,13 @@ def different_layout(layout_name='')
assert_equal("Hello there", email.body.encoded)
end

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

# Custom headers
test "custom headers" do
email = BaseMailer.welcome
Expand All @@ -162,7 +176,7 @@ def different_layout(layout_name='')
assert_equal('1234@mikel.me.com', mail['In-Reply-To'].decoded)
end

test "can pass random headers in as a hash" do
test "can pass random headers in as a hash to headers" do
hash = {'X-Special-Domain-Specific-Header' => "SecretValue",
'In-Reply-To' => '1234@mikel.me.com' }
mail = BaseMailer.welcome_with_headers(hash)
Expand Down Expand Up @@ -366,6 +380,11 @@ def different_layout(layout_name='')
assert_equal("HTML Explicit Multipart", email.parts[1].body.encoded)
end

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

test "explicit multipart does not sort order" do
order = ["text/html", "text/plain"]
with_default BaseMailer, :parts_order => order do
Expand Down Expand Up @@ -399,7 +418,7 @@ def different_layout(layout_name='')
assert_equal("TEXT Explicit Multipart Templates", email.parts[1].body.encoded)
end

test "explicit multipart with any" do
test "explicit multipart with format.any" do
email = BaseMailer.explicit_multipart_with_any
assert_equal(2, email.parts.size)
assert_equal("multipart/alternative", email.mime_type)
Expand All @@ -409,8 +428,8 @@ def different_layout(layout_name='')
assert_equal("Format with any!", email.parts[1].body.encoded)
end

test "explicit multipart with options" do
email = BaseMailer.custom_block(true)
test "explicit multipart with format(Hash)" do
email = BaseMailer.explicit_multipart_with_options(true)
email.ready_to_send!
assert_equal(2, email.parts.size)
assert_equal("multipart/alternative", email.mime_type)
Expand All @@ -420,28 +439,23 @@ 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
test "explicit multipart with one part is rendered as body and options are merged" do
email = BaseMailer.explicit_multipart_with_options
assert_equal(0, email.parts.size)
assert_equal("text/plain", email.mime_type)
assert_equal("base64", email.content_transfer_encoding)
end

test "explicit multipart with one template has the expected format" do
email = BaseMailer.explicit_multipart_with_one_template
assert_equal(2, email.parts.size)
assert_equal("multipart/alternative", email.mime_type)
assert_equal("text/html", email.parts[0].mime_type)
assert_equal("[:html]", email.parts[0].body.encoded)
assert_equal("text/plain", email.parts[1].mime_type)
assert_equal("[:text]", email.parts[1].body.encoded)
end

# Class level API with method missing
test "should respond to action methods" do
assert BaseMailer.respond_to?(:welcome)
Expand Down
@@ -0,0 +1 @@
<%= self.formats.inspect %>
22 changes: 0 additions & 22 deletions actionmailer/test/old_base/mail_layout_test.rb
Expand Up @@ -69,47 +69,25 @@ def test_should_pickup_default_layout

def test_should_pickup_multipart_layout
mail = AutoLayoutMailer.multipart
# CHANGED: content_type returns an object
# assert_equal "multipart/alternative", mail.content_type
assert_equal "multipart/alternative", mail.mime_type
assert_equal 2, mail.parts.size

# CHANGED: content_type returns an object
# assert_equal 'text/plain', mail.parts.first.content_type
assert_equal 'text/plain', mail.parts.first.mime_type

# CHANGED: body returns an object
# assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body
assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s

# CHANGED: content_type returns an object
# assert_equal 'text/html', mail.parts.last.content_type
assert_equal 'text/html', mail.parts.last.mime_type

# CHANGED: body returns an object
# assert_equal "Hello from layout text/html multipart", mail.parts.last.body
assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s
end

def test_should_pickup_multipartmixed_layout
mail = AutoLayoutMailer.multipart("multipart/mixed")
# CHANGED: content_type returns an object
# assert_equal "multipart/mixed", mail.content_type
assert_equal "multipart/mixed", mail.mime_type
assert_equal 2, mail.parts.size

# CHANGED: content_type returns an object
# assert_equal 'text/plain', mail.parts.first.content_type
assert_equal 'text/plain', mail.parts.first.mime_type
# CHANGED: body returns an object
# assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body
assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s

# CHANGED: content_type returns an object
# assert_equal 'text/html', mail.parts.last.content_type
assert_equal 'text/html', mail.parts.last.mime_type
# CHANGED: body returns an object
# assert_equal "Hello from layout text/html multipart", mail.parts.last.body
assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s
end

Expand Down
6 changes: 4 additions & 2 deletions actionmailer/test/old_base/mail_service_test.rb
Expand Up @@ -340,6 +340,8 @@ def setup

@original_logger = TestMailer.logger
@recipient = 'test@localhost'

TestMailer.delivery_method = :test
end

def teardown
Expand Down Expand Up @@ -1191,6 +1193,6 @@ def test_should_still_raise_exception_with_expected_message_when_calling_an_unde
RespondToMailer.not_a_method
end

assert_match(/undefined method.*not_a_method/, error.message)
assert_match(/method.*not_a_method/, error.message)
end
end
end

0 comments on commit b4c91de

Please sign in to comment.