Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:rails/rails
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed Sep 20, 2008
2 parents 0aef9d1 + a3b7fa7 commit 22e830f
Show file tree
Hide file tree
Showing 267 changed files with 10,347 additions and 5,055 deletions.
5 changes: 5 additions & 0 deletions actionmailer/CHANGELOG
@@ -1,3 +1,8 @@
* Add layout functionality to mailers [Pratik]

Mailer layouts behaves just like controller layouts, except layout names need to
have '_mailer' postfix for them to be automatically picked up.

*2.1.0 (May 31st, 2008)*

* Fixed that a return-path header would be ignored #7572 [joost]
Expand Down
47 changes: 39 additions & 8 deletions actionmailer/lib/action_mailer/base.rb
Expand Up @@ -246,7 +246,10 @@ module ActionMailer #:nodoc:
# +implicit_parts_order+.
class Base
include AdvAttrAccessor, PartContainer
include ActionController::UrlWriter if Object.const_defined?(:ActionController)
if Object.const_defined?(:ActionController)
include ActionController::UrlWriter
include ActionController::Layout
end

private_class_method :new #:nodoc:

Expand Down Expand Up @@ -362,6 +365,7 @@ def mailer_name=(value)

# The mail object instance referenced by this mailer.
attr_reader :mail
attr_reader :template_name, :default_template_name, :action_name

class << self
attr_writer :mailer_name
Expand All @@ -374,11 +378,16 @@ def mailer_name
alias_method :controller_name, :mailer_name
alias_method :controller_path, :mailer_name

def method_missing(method_symbol, *parameters)#:nodoc:
case method_symbol.id2name
when /^create_([_a-z]\w*)/ then new($1, *parameters).mail
when /^deliver_([_a-z]\w*)/ then new($1, *parameters).deliver!
when "new" then nil
def respond_to?(method_symbol, include_private = false) #:nodoc:
matches_dynamic_method?(method_symbol) || super
end

def method_missing(method_symbol, *parameters) #:nodoc:
match = matches_dynamic_method?(method_symbol)
case match[1]
when 'create' then new(match[2], *parameters).mail
when 'deliver' then new(match[2], *parameters).deliver!
when 'new' then nil
else super
end
end
Expand Down Expand Up @@ -424,6 +433,12 @@ def template_root
def template_root=(root)
self.view_paths = ActionView::Base.process_view_paths(root)
end

private
def matches_dynamic_method?(method_name) #:nodoc:
method_name = method_name.to_s
/(create|deliver)_([_a-z]\w*)/.match(method_name) || /^(new)$/.match(method_name)
end
end

# Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
Expand Down Expand Up @@ -451,7 +466,7 @@ def create!(method_name, *parameters) #:nodoc:
template = template_root["#{mailer_name}/#{File.basename(path)}"]

# Skip unless template has a multipart format
next unless template.multipart?
next unless template && template.multipart?

@parts << Part.new(
:content_type => template.content_type,
Expand Down Expand Up @@ -519,6 +534,7 @@ def initialize_defaults(method_name)
@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 ||= []
@headers ||= {}
Expand All @@ -535,7 +551,22 @@ def render(opts)
if opts[:file] && (opts[:file] !~ /\// && !opts[:file].respond_to?(:render))
opts[:file] = "#{mailer_name}/#{opts[:file]}"
end
initialize_template_class(body).render(opts)

begin
old_template, @template = @template, initialize_template_class(body)
layout = respond_to?(:pick_layout, true) ? pick_layout(opts) : false
@template.render(opts.merge(:layout => layout))
ensure
@template = old_template
end
end

def default_template_format
:html
end

def candidate_for_layout?(options)
!@template.send(:_exempt_from_layout?, default_template_name)
end

def template_root
Expand Down
4 changes: 2 additions & 2 deletions actionmailer/lib/action_mailer/helpers.rb
Expand Up @@ -72,7 +72,7 @@ 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)
controller.__send__(%(#{method}), *args, &block)
end
end_eval
end
Expand All @@ -92,7 +92,7 @@ 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.master_helper_module.__send__(:include, master_helper_module)
child.helper child.name.to_s.underscore
rescue MissingSourceFile => e
raise unless e.is_missing?("helpers/#{child.name.to_s.underscore}_helper")
Expand Down
@@ -0,0 +1 @@
Inside
@@ -0,0 +1 @@
You logged out
@@ -0,0 +1 @@
We do not spam
@@ -0,0 +1 @@
Hello from layout <%= yield %>
1 change: 1 addition & 0 deletions actionmailer/test/fixtures/layouts/spam.html.erb
@@ -0,0 +1 @@
Spammer layout <%= yield %>
@@ -0,0 +1,10 @@
<html>
<body>
HTML formatted message to <strong><%= @recipient %></strong>.
</body>
</html>
<html>
<body>
HTML formatted message to <strong><%= @recipient %></strong>.
</body>
</html>
78 changes: 78 additions & 0 deletions actionmailer/test/mail_layout_test.rb
@@ -0,0 +1,78 @@
require 'abstract_unit'

class AutoLayoutMailer < ActionMailer::Base
def hello(recipient)
recipients recipient
subject "You have a mail"
from "tester@example.com"
end

def spam(recipient)
recipients recipient
subject "You have a mail"
from "tester@example.com"
body render(:inline => "Hello, <%= @world %>", :layout => 'spam', :body => { :world => "Earth" })
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" })
end
end

class ExplicitLayoutMailer < ActionMailer::Base
layout 'spam', :except => [:logout]

def signup(recipient)
recipients recipient
subject "You have a mail"
from "tester@example.com"
end

def logout(recipient)
recipients recipient
subject "You have a mail"
from "tester@example.com"
end
end

class LayoutMailerTest < Test::Unit::TestCase
def setup
set_delivery_method :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []

@recipient = 'test@localhost'
end

def teardown
restore_delivery_method
end

def test_should_pickup_default_layout
mail = AutoLayoutMailer.create_hello(@recipient)
assert_equal "Hello from layout Inside", mail.body.strip
end

def test_should_pickup_layout_given_to_render
mail = AutoLayoutMailer.create_spam(@recipient)
assert_equal "Spammer layout Hello, Earth", mail.body.strip
end

def test_should_respect_layout_false
mail = AutoLayoutMailer.create_nolayout(@recipient)
assert_equal "Hello, Earth", mail.body.strip
end

def test_explicit_class_layout
mail = ExplicitLayoutMailer.create_signup(@recipient)
assert_equal "Spammer layout We do not spam", mail.body.strip
end

def test_explicit_layout_exceptions
mail = ExplicitLayoutMailer.create_logout(@recipient)
assert_equal "You logged out", mail.body.strip
end
end
52 changes: 52 additions & 0 deletions actionmailer/test/mail_service_test.rb
Expand Up @@ -968,3 +968,55 @@ def test_send_method
end
end
end

class RespondToTest < Test::Unit::TestCase
class RespondToMailer < ActionMailer::Base; end

def setup
set_delivery_method :test
end

def teardown
restore_delivery_method
end

def test_should_respond_to_new
assert RespondToMailer.respond_to?(:new)
end

def test_should_respond_to_create_with_template_suffix
assert RespondToMailer.respond_to?(:create_any_old_template)
end

def test_should_respond_to_deliver_with_template_suffix
assert RespondToMailer.respond_to?(:deliver_any_old_template)
end

def test_should_not_respond_to_new_with_template_suffix
assert !RespondToMailer.respond_to?(:new_any_old_template)
end

def test_should_not_respond_to_create_with_template_suffix_unless_it_is_separated_by_an_underscore
assert !RespondToMailer.respond_to?(:createany_old_template)
end

def test_should_not_respond_to_deliver_with_template_suffix_unless_it_is_separated_by_an_underscore
assert !RespondToMailer.respond_to?(:deliverany_old_template)
end

def test_should_not_respond_to_create_with_template_suffix_if_it_begins_with_a_uppercase_letter
assert !RespondToMailer.respond_to?(:create_Any_old_template)
end

def test_should_not_respond_to_deliver_with_template_suffix_if_it_begins_with_a_uppercase_letter
assert !RespondToMailer.respond_to?(:deliver_Any_old_template)
end

def test_should_not_respond_to_create_with_template_suffix_if_it_begins_with_a_digit
assert !RespondToMailer.respond_to?(:create_1_template)
end

def test_should_not_respond_to_deliver_with_template_suffix_if_it_begins_with_a_digit
assert !RespondToMailer.respond_to?(:deliver_1_template)
end
end
46 changes: 46 additions & 0 deletions actionpack/CHANGELOG
@@ -1,5 +1,51 @@
*Edge*

* Set HttpOnly for the cookie session store's cookie. #1046

* Added FormTagHelper#image_submit_tag confirm option #784 [Alastair Brunton]

* Fixed FormTagHelper#submit_tag with :disable_with option wouldn't submit the button's value when was clicked #633 [Jose Fernandez]

* Stopped logging template compiles as it only clogs up the log [DHH]

* Changed the X-Runtime header to report in milliseconds [DHH]

* Changed BenchmarkHelper#benchmark to report in milliseconds [DHH]

* Changed logging format to be millisecond based and skip misleading stats [DHH]. Went from:

Completed in 0.10000 (4 reqs/sec) | Rendering: 0.04000 (40%) | DB: 0.00400 (4%) | 200 OK [http://example.com]

...to:

Completed in 100ms (View: 40, DB: 4) | 200 OK [http://example.com]

* Add support for shallow nesting of routes. #838 [S. Brent Faulkner]

Example :

map.resources :users, :shallow => true do |user|
user.resources :posts
end

- GET /users/1/posts (maps to PostsController#index action as usual)
named route "user_posts" is added as usual.

- GET /posts/2 (maps to PostsController#show action as if it were not nested)
Additionally, named route "post" is added too.

* Added button_to_remote helper. #3641 [Donald Piret, Tarmo Tänav]

* Deprecate render_component. Please use render_component plugin from http://github.com/rails/render_component/tree/master [Pratik]

* Routes may be restricted to lists of HTTP methods instead of a single method or :any. #407 [Brennan Dunn, Gaius Centus Novus]
map.resource :posts, :collection => { :search => [:get, :post] }
map.session 'session', :requirements => { :method => [:get, :post, :delete] }

* Deprecated implicit local assignments when rendering partials [Josh Peek]

* Introduce current_cycle helper method to return the current value without bumping the cycle. #417 [Ken Collins]

* Allow polymorphic_url helper to take url options. #880 [Tarmo Tänav]

* Switched integration test runner to use Rack processor instead of CGI [Josh Peek]
Expand Down
14 changes: 8 additions & 6 deletions actionpack/Rakefile
Expand Up @@ -25,14 +25,16 @@ task :default => [ :test ]
desc "Run all unit tests"
task :test => [:test_action_pack, :test_active_record_integration]

Rake::TestTask.new(:test_action_pack) { |t|
Rake::TestTask.new(:test_action_pack) do |t|
t.libs << "test"
# make sure we include the tests in alphabetical order as on some systems
# this will not happen automatically and the tests (as a whole) will error
t.test_files=Dir.glob( "test/[cft]*/**/*_test.rb" ).sort
# t.pattern = 'test/*/*_test.rb'

# make sure we include the tests in alphabetical order as on some systems
# this will not happen automatically and the tests (as a whole) will error
t.test_files = Dir.glob( "test/[cft]*/**/*_test.rb" ).sort

t.verbose = true
}
#t.warning = true
end

desc 'ActiveRecord Integration Tests'
Rake::TestTask.new(:test_active_record_integration) do |t|
Expand Down
2 changes: 2 additions & 0 deletions actionpack/lib/action_controller.rb
Expand Up @@ -54,6 +54,7 @@
require 'action_controller/record_identifier'
require 'action_controller/request_forgery_protection'
require 'action_controller/headers'
require 'action_controller/translation'

require 'action_view'

Expand All @@ -74,4 +75,5 @@
include ActionController::Components
include ActionController::RecordIdentifier
include ActionController::RequestForgeryProtection
include ActionController::Translation
end

0 comments on commit 22e830f

Please sign in to comment.