Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:lifo/docrails
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Chadha committed May 2, 2009
2 parents 5469a0b + 1b32f88 commit 7a17ad3
Show file tree
Hide file tree
Showing 172 changed files with 2,041 additions and 6,371 deletions.
11 changes: 6 additions & 5 deletions actionmailer/lib/action_mailer/base.rb
Expand Up @@ -475,7 +475,7 @@ def create!(method_name, *parameters) #:nodoc:
# if @parts.empty?
template_root.find_all_by_parts(@template, {}, template_path).each do |template|
@parts << Part.new(
:content_type => Mime::Type.lookup_by_extension(template.content_type || "text").to_s,
:content_type => template.mime_type ? template.mime_type.to_s : "text/plain",
:disposition => "inline",
:charset => charset,
:body => render_template(template, @body)
Expand Down Expand Up @@ -555,12 +555,13 @@ def initialize_defaults(method_name)
end

def render_template(template, body)
if template.respond_to?(:content_type)
@current_template_content_type = template.content_type
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 template.exempt_from_layout?
layout = _pick_layout(layout, true) unless
ActionController::Base.exempt_from_layout.include?(template.handler)
@template._render_template_with_layout(template, layout, {})
ensure
@current_template_content_type = nil
Expand All @@ -584,7 +585,7 @@ def render(opts)
end

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

if template
@template._render_template_with_layout(template, layout, opts)
Expand Down
4 changes: 2 additions & 2 deletions actionmailer/test/mail_service_test.rb
Expand Up @@ -994,13 +994,13 @@ def test_starttls_is_not_enabled

class InheritableTemplateRootTest < Test::Unit::TestCase
def test_attr
expected = "#{File.dirname(__FILE__)}/fixtures/path.with.dots"
expected = File.expand_path("#{File.dirname(__FILE__)}/fixtures/path.with.dots")
assert_equal expected, FunkyPathMailer.template_root.to_s

sub = Class.new(FunkyPathMailer)
sub.template_root = 'test/path'

assert_equal 'test/path', sub.template_root.to_s
assert_equal File.expand_path('test/path'), sub.template_root.to_s
assert_equal expected, FunkyPathMailer.template_root.to_s
end
end
Expand Down
44 changes: 23 additions & 21 deletions actionpack/lib/action_controller/base/base.rb
Expand Up @@ -238,7 +238,7 @@ class Base
cattr_reader :protected_instance_variables
# Controller specific instance variables which will not be accessible inside views.
@@protected_instance_variables = %w(@assigns @performed_redirect @performed_render @variables_added @request_origin @url @parent_controller
@action_name @before_filter_chain_aborted @action_cache_path @_session @_headers @_params
@action_name @before_filter_chain_aborted @action_cache_path @_headers @_params
@_flash @_response)

# Prepends all the URL-generating helpers from AssetHelper. This makes it possible to easily move javascripts, stylesheets,
Expand Down Expand Up @@ -356,7 +356,9 @@ class Base

# Holds a hash of objects in the session. Accessed like <tt>session[:person]</tt> to get the object tied to the "person"
# key. The session will hold any type of object as values, but the key should be a string or symbol.
attr_internal :session
def session
request.session
end

# Holds a hash of header names and values. Accessed like <tt>headers["Cache-Control"]</tt> to get the value of the Cache-Control
# directive. Values should always be specified as strings.
Expand All @@ -365,6 +367,8 @@ class Base
# Returns the name of the action this controller is processing.
attr_accessor :action_name

attr_reader :template

class << self
def call(env)
# HACK: For global rescue to have access to the original request and response
Expand Down Expand Up @@ -492,8 +496,18 @@ def filter_parameter_logging(*filter_words, &block)
end
protected :filter_parameters
end

@@exempt_from_layout = [ActionView::TemplateHandlers::RJS]

def exempt_from_layout(*types)
types.each do |type|
@@exempt_from_layout <<
ActionView::Template.handler_class_for_extension(type)
end

@@exempt_from_layout
end

delegate :exempt_from_layout, :to => 'ActionView::Template'
end

public
Expand Down Expand Up @@ -787,7 +801,6 @@ def expires_now #:doc:
# Resets the session by clearing out all the objects stored within and initializing a new session object.
def reset_session #:doc:
request.reset_session
@_session = request.session
end

private
Expand All @@ -805,19 +818,13 @@ def _process_options(options)

def initialize_template_class(response)
@template = response.template = ActionView::Base.new(self.class.view_paths, {}, self, formats)
response.template.helpers.send :include, self.class.master_helper_module
@template.helpers.send :include, self.class.master_helper_module
response.redirected_to = nil
@performed_render = @performed_redirect = false
end

def assign_shortcuts(request, response)
@_request, @_params = request, request.parameters

@_response = response
@_response.session = request.session

@_session = @_response.session

@_request, @_response, @_params = request, response, request.parameters
@_headers = @_response.headers
end

Expand Down Expand Up @@ -861,13 +868,13 @@ def perform_action
return (performed? ? ret : default_render) if called

begin
default_render
rescue ActionView::MissingTemplate => e
raise e unless e.action_name == action_name
# If the path is the same as the action_name, the action is completely missing
view_paths.find_by_parts(action_name, {:formats => formats, :locales => [I18n.locale]}, controller_path)
rescue => e
raise UnknownAction, "No action responded to #{action_name}. Actions: " +
"#{action_methods.sort.to_sentence}", caller
end

default_render
end

# Returns true if a render or redirect has already been performed.
Expand All @@ -894,10 +901,6 @@ def complete_request_uri
"#{request.protocol}#{request.host}#{request.request_uri}"
end

def close_session
# @_session.close if @_session && @_session.respond_to?(:close)
end

def default_template(action_name = self.action_name)
self.view_paths.find_template(default_template_name(action_name), default_template_format)
end
Expand All @@ -921,7 +924,6 @@ def template_path_includes_controller?(path)
end

def process_cleanup
close_session
end
end

Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/base/mime_responds.rb
Expand Up @@ -139,7 +139,7 @@ def custom(mime_type, &block)
@order << mime_type

@responses[mime_type] ||= Proc.new do
@response.template.formats = [mime_type.to_sym]
@controller.template.formats = [mime_type.to_sym]
@response.content_type = mime_type.to_s
block_given? ? block.call : @controller.send(:render, :action => @controller.action_name)
end
Expand Down
9 changes: 5 additions & 4 deletions actionpack/lib/action_controller/base/render.rb
Expand Up @@ -254,7 +254,7 @@ def render(options = nil, extra_options = {}, &block) #:doc:
render_for_text(js)

elsif json = options[:json]
json = ActiveSupport::JSON.encode(json) unless json.is_a?(String)
json = ActiveSupport::JSON.encode(json) unless json.respond_to?(:to_str)
json = "#{options[:callback]}(#{json})" unless options[:callback].blank?
response.content_type ||= Mime::JSON
render_for_text(json)
Expand Down Expand Up @@ -378,13 +378,14 @@ def render_for_name(name, layout, options)
# ==== Arguments
# parts<Array[String, Array[Symbol*], String, Boolean]>::
# Example: ["show", [:html, :xml], "users", false]
def render_for_parts(parts, layout, options = {})
def render_for_parts(parts, layout_details, options = {})
parts[1] = {:formats => parts[1], :locales => [I18n.locale]}

tmp = view_paths.find_by_parts(*parts)

layout = _pick_layout(*layout) unless tmp.exempt_from_layout?

layout = _pick_layout(*layout_details) unless
self.class.exempt_from_layout.include?(tmp.handler)

render_for_text(
@template._render_template_with_layout(tmp, layout, options, parts[3]))
end
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/caching/actions.rb
Expand Up @@ -121,7 +121,7 @@ def cache_layout?
end

def content_for_layout(controller)
controller.response.layout && controller.response.template.instance_variable_get('@cached_content_for_layout')
controller.template.layout && controller.template.instance_variable_get('@cached_content_for_layout')
end
end

Expand Down
1 change: 0 additions & 1 deletion actionpack/lib/action_controller/dispatch/middlewares.rb
Expand Up @@ -7,7 +7,6 @@
use lambda { ActionController::Base.session_store },
lambda { ActionController::Base.session_options }

use "ActionDispatch::RewindableInput"
use "ActionDispatch::ParamsParser"
use "Rack::MethodOverride"
use "Rack::Head"
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/routing.rb
Expand Up @@ -135,7 +135,7 @@ module ActionController
# # In routes.rb
# map.with_options :controller => 'blog' do |blog|
# blog.show '', :action => 'list'
# blog.delete 'delete/:id', :action => 'delete',
# blog.delete 'delete/:id', :action => 'delete'
# blog.edit 'edit/:id', :action => 'edit'
# end
#
Expand Down
32 changes: 22 additions & 10 deletions actionpack/lib/action_controller/testing/assertions/response.rb
Expand Up @@ -22,6 +22,8 @@ module ResponseAssertions
# assert_response 401
#
def assert_response(type, message = nil)
validate_request!

clean_backtrace do
if [ :success, :missing, :redirect, :error ].include?(type) && @response.send("#{type}?")
assert_block("") { true } # to count the assertion
Expand All @@ -30,8 +32,8 @@ def assert_response(type, message = nil)
elsif type.is_a?(Symbol) && @response.response_code == ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE[type]
assert_block("") { true } # to count the assertion
else
if @response.error?
exception = @response.template.instance_variable_get(:@exception)
if @controller && @response.error?
exception = @controller.template.instance_variable_get(:@exception)
exception_message = exception && exception.message
assert_block(build_message(message, "Expected response to be a <?>, but was <?>\n<?>", type, @response.response_code, exception_message.to_s)) { false }
else
Expand All @@ -57,6 +59,8 @@ def assert_response(type, message = nil)
# assert_redirected_to @customer
#
def assert_redirected_to(options = {}, message=nil)
validate_request!

clean_backtrace do
assert_response(:redirect, message)
return true if options == @response.redirected_to
Expand Down Expand Up @@ -89,25 +93,27 @@ def assert_redirected_to(options = {}, message=nil)
# assert_template :partial => false
#
def assert_template(options = {}, message = nil)
validate_request!

clean_backtrace do
case options
when NilClass, String
rendered = @response.rendered[:template].to_s
rendered = (@controller.template.rendered[:template] || []).map { |t| t.identifier }
msg = build_message(message,
"expecting <?> but rendering with <?>",
options, rendered)
options, rendered.join(', '))
assert_block(msg) do
if options.nil?
@response.rendered[:template].blank?
@controller.template.rendered[:template].blank?
else
rendered.to_s.match(options)
rendered.any? { |t| t.match(options) }
end
end
when Hash
if expected_partial = options[:partial]
partials = @response.rendered[:partials]
partials = @controller.template.rendered[:partials]
if expected_count = options[:count]
found = partials.detect { |p, _| p.to_s.match(expected_partial) }
found = partials.detect { |p, _| p.identifier.match(expected_partial) }
actual_count = found.nil? ? 0 : found.second
msg = build_message(message,
"expecting ? to be rendered ? time(s) but rendered ? time(s)",
Expand All @@ -117,10 +123,10 @@ def assert_template(options = {}, message = nil)
msg = build_message(message,
"expecting partial <?> but action rendered <?>",
options[:partial], partials.keys)
assert(partials.keys.any? { |p| p.to_s.match(expected_partial) }, msg)
assert(partials.keys.any? { |p| p.identifier.match(expected_partial) }, msg)
end
else
assert @response.rendered[:partials].empty?,
assert @controller.template.rendered[:partials].empty?,
"Expected no partials to be rendered"
end
end
Expand All @@ -145,6 +151,12 @@ def normalize_argument_to_redirection(fragment)
@request.protocol + @request.host_with_port + after_routing
end
end

def validate_request!
unless @request.is_a?(ActionDispatch::Request)
raise ArgumentError, "@request must be an ActionDispatch::Request"
end
end
end
end
end

0 comments on commit 7a17ad3

Please sign in to comment.