Skip to content

Commit

Permalink
Get controller/layout_test.rb running on new base except for ActionCo…
Browse files Browse the repository at this point in the history
…ntroller::Base.exempt_from_layout which is going to be deprecated.
  • Loading branch information
Yehuda Katz + Carl Lerche committed May 22, 2009
1 parent 0112953 commit 72a574b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 29 deletions.
13 changes: 7 additions & 6 deletions actionpack/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ Rake::TestTask.new(:test_new_base_on_old_tests) do |t|
# layout
# Dir.glob( "test/{dispatch,template}/**/*_test.rb" ).sort +
t.test_files = %w(
addresses_render base benchmark caching capture content_type dispatcher
flash mime_responds record_identifier redirect
render render_json render_xml
send_file request_forgery_protection rescue url_rewriter verification webservice
http_basic_authentication http_digest_authentication
action_pack_assertions assert_select filter_params helper
action_pack_assertions addresses_render assert_select
base benchmark caching capture content_type dispatcher
filter_params flash helper http_basic_authentication
http_digest_authentication layout mime_responds
record_identifier redirect render render_json render_xml
send_file request_forgery_protection rescue url_rewriter
verification webservice
).map { |name| "test/controller/#{name}_test.rb" }
end

Expand Down
6 changes: 3 additions & 3 deletions actionpack/lib/action_controller/abstract/layouts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,20 @@ def _layout() end # This will be overwritten
# :api: plugin
# ====
# Override this to mutate the inbound layout name
def _layout_for_name(name)
def _layout_for_name(name, details = {:formats => formats})
unless [String, FalseClass, NilClass].include?(name.class)
raise ArgumentError, "String, false, or nil expected; you passed #{name.inspect}"
end

name && view_paths.find_by_parts(name, {:formats => formats}, _layout_prefix(name))
name && view_paths.find_by_parts(name, details, _layout_prefix(name))
end

# TODO: Decide if this is the best hook point for the feature
def _layout_prefix(name)
"layouts"
end

def _default_layout(require_layout = false)
def _default_layout(require_layout = false, details = {:formats => formats})
if require_layout && _action_has_layout? && !_layout
raise ArgumentError,
"There was no default layout for #{self.class} in #{view_paths.inspect}"
Expand Down
21 changes: 9 additions & 12 deletions actionpack/lib/action_controller/new_base/layouts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,20 @@ def _implied_layout_name
end
end

def render_to_body(options)
# render :text => ..., :layout => ...
# or
# render :anything_else
private

def _determine_template(options)
super
if (!options.key?(:text) && !options.key?(:inline) && !options.key?(:partial)) || options.key?(:layout)
options[:_layout] = options.key?(:layout) ? _layout_for_option(options[:layout]) : _default_layout
options[:_layout] = _layout_for_option(options.key?(:layout) ? options[:layout] : :none, options[:_template].details)
end

super
end

private

def _layout_for_option(name)
def _layout_for_option(name, details)
case name
when String then _layout_for_name(name)
when true then _default_layout(true)
when String then _layout_for_name(name, details)
when true then _default_layout(true, details)
when :none then _default_layout(false, details)
when false, nil then nil
else
raise ArgumentError,
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/template/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
module ActionView
class Template
extend TemplateHandlers
attr_reader :source, :identifier, :handler, :mime_type
attr_reader :source, :identifier, :handler, :mime_type, :details

def initialize(source, identifier, handler, details)
@source = source
Expand Down
4 changes: 4 additions & 0 deletions actionpack/lib/action_view/template/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ def initialize(string, content_type = Mime[:html])
@content_type = Mime[content_type]
end

def details
{:formats => [@content_type.to_sym]}
end

def identifier() self end

def render(*) self end
Expand Down
17 changes: 10 additions & 7 deletions actionpack/test/controller/layout_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,18 @@ def test_layout_is_not_set_when_none_rendered
assert_nil @controller.template.layout
end

def test_exempt_from_layout_honored_by_render_template
ActionController::Base.exempt_from_layout :erb
@controller = RenderWithTemplateOptionController.new
for_tag(:old_base) do
# exempt_from_layout is deprecated
def test_exempt_from_layout_honored_by_render_template
ActionController::Base.exempt_from_layout :erb
@controller = RenderWithTemplateOptionController.new

get :hello
assert_equal "alt/hello.rhtml", @response.body.strip
get :hello
assert_equal "alt/hello.rhtml", @response.body.strip

ensure
ActionController::Base.exempt_from_layout.delete(ERB)
ensure
ActionController::Base.exempt_from_layout.delete(ERB)
end
end

def test_layout_is_picked_from_the_controller_instances_view_path
Expand Down

0 comments on commit 72a574b

Please sign in to comment.