diff options
Diffstat (limited to 'actionpack/test/new_base')
-rw-r--r-- | actionpack/test/new_base/abstract_unit.rb | 166 | ||||
-rw-r--r-- | actionpack/test/new_base/base_test.rb | 80 | ||||
-rw-r--r-- | actionpack/test/new_base/content_type_test.rb | 120 | ||||
-rw-r--r-- | actionpack/test/new_base/etag_test.rb | 25 | ||||
-rw-r--r-- | actionpack/test/new_base/render_action_test.rb | 394 | ||||
-rw-r--r-- | actionpack/test/new_base/render_implicit_action_test.rb | 28 | ||||
-rw-r--r-- | actionpack/test/new_base/render_layout_test.rb | 96 | ||||
-rw-r--r-- | actionpack/test/new_base/render_template_test.rb | 87 | ||||
-rw-r--r-- | actionpack/test/new_base/render_test.rb | 51 | ||||
-rw-r--r-- | actionpack/test/new_base/render_text_test.rb | 156 | ||||
-rw-r--r-- | actionpack/test/new_base/test_helper.rb | 73 |
11 files changed, 692 insertions, 584 deletions
diff --git a/actionpack/test/new_base/abstract_unit.rb b/actionpack/test/new_base/abstract_unit.rb new file mode 100644 index 0000000000..e6690d41d9 --- /dev/null +++ b/actionpack/test/new_base/abstract_unit.rb @@ -0,0 +1,166 @@ +$:.unshift(File.dirname(__FILE__) + '/../../lib') +$:.unshift(File.dirname(__FILE__) + '/../../../activesupport/lib') +$:.unshift(File.dirname(__FILE__) + '/../lib') + +$:.unshift(File.dirname(__FILE__) + '/../fixtures/helpers') +$:.unshift(File.dirname(__FILE__) + '/../fixtures/alternate_helpers') + +ENV['new_base'] = "true" +$stderr.puts "Running old tests on new_base" + +require 'test/unit' +require 'active_support' + +# TODO : Revisit requiring all the core extensions here +require 'active_support/core_ext' + +require 'active_support/test_case' +require 'action_controller/abstract' +require 'action_controller/new_base' +require 'fixture_template' +require 'action_controller/testing/process2' +require 'action_view/test_case' +require 'action_controller/testing/integration' +require 'active_support/dependencies' + +$tags[:new_base] = true + +begin + require 'ruby-debug' + Debugger.settings[:autoeval] = true + Debugger.start +rescue LoadError + # Debugging disabled. `gem install ruby-debug` to enable. +end + +ActiveSupport::Dependencies.hook! + +# Show backtraces for deprecated behavior for quicker cleanup. +ActiveSupport::Deprecation.debug = true + +# Register danish language for testing +I18n.backend.store_translations 'da', {} +I18n.backend.store_translations 'pt-BR', {} +ORIGINAL_LOCALES = I18n.available_locales.map {|locale| locale.to_s }.sort + +FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), '../fixtures') + +module ActionController + Base.session = { + :key => '_testing_session', + :secret => '8273f16463985e2b3747dc25e30f2528' +} + + class ActionControllerError < StandardError #:nodoc: + end + + class SessionRestoreError < ActionControllerError #:nodoc: + end + + class RenderError < ActionControllerError #:nodoc: + end + + class RoutingError < ActionControllerError #:nodoc: + attr_reader :failures + def initialize(message, failures=[]) + super(message) + @failures = failures + end + end + + class MethodNotAllowed < ActionControllerError #:nodoc: + attr_reader :allowed_methods + + def initialize(*allowed_methods) + super("Only #{allowed_methods.to_sentence(:locale => :en)} requests are allowed.") + @allowed_methods = allowed_methods + end + + def allowed_methods_header + allowed_methods.map { |method_symbol| method_symbol.to_s.upcase } * ', ' + end + + def handle_response!(response) + response.headers['Allow'] ||= allowed_methods_header + end + end + + class NotImplemented < MethodNotAllowed #:nodoc: + end + + class UnknownController < ActionControllerError #:nodoc: + end + + class MissingFile < ActionControllerError #:nodoc: + end + + class RenderError < ActionControllerError #:nodoc: + end + + class SessionOverflowError < ActionControllerError #:nodoc: + DEFAULT_MESSAGE = 'Your session data is larger than the data column in which it is to be stored. You must increase the size of your data column if you intend to store large data.' + + def initialize(message = nil) + super(message || DEFAULT_MESSAGE) + end + end + + class UnknownHttpMethod < ActionControllerError #:nodoc: + end + + class Base + include ActionController::Testing + end + + Base.view_paths = FIXTURE_LOAD_PATH + + class TestCase + include TestProcess + setup do + ActionController::Routing::Routes.draw do |map| + map.connect ':controller/:action/:id' + end + end + + def assert_template(options = {}, message = nil) + validate_request! + + hax = @controller._action_view.instance_variable_get(:@_rendered) + + case options + when NilClass, String + rendered = (hax[:template] || []).map { |t| t.identifier } + msg = build_message(message, + "expecting <?> but rendering with <?>", + options, rendered.join(', ')) + assert_block(msg) do + if options.nil? + hax[:template].blank? + else + rendered.any? { |t| t.match(options) } + end + end + when Hash + if expected_partial = options[:partial] + partials = hax[:partials] + if expected_count = options[:count] + 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)", + expected_partial, expected_count, actual_count) + assert(actual_count == expected_count.to_i, msg) + else + msg = build_message(message, + "expecting partial <?> but action rendered <?>", + options[:partial], partials.keys) + assert(partials.keys.any? { |p| p.identifier.match(expected_partial) }, msg) + end + else + assert hax[:partials].empty?, + "Expected no partials to be rendered" + end + end + end + end +end diff --git a/actionpack/test/new_base/base_test.rb b/actionpack/test/new_base/base_test.rb index a32653f128..d9d552f9e5 100644 --- a/actionpack/test/new_base/base_test.rb +++ b/actionpack/test/new_base/base_test.rb @@ -10,78 +10,60 @@ module Dispatching def modify_response_body self.response_body = "success" end - + def modify_response_body_twice ret = (self.response_body = "success") self.response_body = "#{ret}!" end - + def modify_response_headers - end end - - class TestSimpleDispatch < SimpleRouteCase - - get "/dispatching/simple/index" - - test "sets the body" do + + class EmptyController < ActionController::Base ; end + + module Submodule + class ContainedEmptyController < ActionController::Base ; end + end + + class BaseTest < SimpleRouteCase + # :api: plugin + test "simple dispatching" do + get "/dispatching/simple/index" + assert_body "success" - end - - test "sets the status code" do assert_status 200 - end - - test "sets the content type" do assert_content_type "text/html; charset=utf-8" - end - - test "sets the content length" do assert_header "Content-Length", "7" end - - end - - # :api: plugin - class TestDirectResponseMod < SimpleRouteCase - get "/dispatching/simple/modify_response_body" - - test "sets the body" do + + # :api: plugin + test "directly modifying response body" do + get "/dispatching/simple/modify_response_body" + assert_body "success" + assert_header "Content-Length", "7" # setting the body manually sets the content length end - - test "setting the body manually sets the content length" do - assert_header "Content-Length", "7" - end - end - - # :api: plugin - class TestDirectResponseModTwice < SimpleRouteCase - get "/dispatching/simple/modify_response_body_twice" - - test "self.response_body= returns the body being set" do + + # :api: plugin + test "directly modifying response body twice" do + get "/dispatching/simple/modify_response_body_twice" + assert_body "success!" - end - - test "updating the response body updates the content length" do assert_header "Content-Length", "8" end - end - - class EmptyController < ActionController::Base ; end - module Submodule - class ContainedEmptyController < ActionController::Base ; end - end - class ControllerClassTests < Test::Unit::TestCase - def test_controller_path + test "controller path" do assert_equal 'dispatching/empty', EmptyController.controller_path assert_equal EmptyController.controller_path, EmptyController.new.controller_path + end + + test "namespaced controller path" do assert_equal 'dispatching/submodule/contained_empty', Submodule::ContainedEmptyController.controller_path assert_equal Submodule::ContainedEmptyController.controller_path, Submodule::ContainedEmptyController.new.controller_path end - def test_controller_name + + test "controller name" do assert_equal 'empty', EmptyController.controller_name assert_equal 'contained_empty', Submodule::ContainedEmptyController.controller_name end diff --git a/actionpack/test/new_base/content_type_test.rb b/actionpack/test/new_base/content_type_test.rb index a5c04e9cb6..82b817a5a3 100644 --- a/actionpack/test/new_base/content_type_test.rb +++ b/actionpack/test/new_base/content_type_test.rb @@ -5,107 +5,107 @@ module ContentType def index render :text => "Hello world!" end - + def set_on_response_obj response.content_type = Mime::RSS render :text => "Hello world!" end - + def set_on_render render :text => "Hello world!", :content_type => Mime::RSS end end - - class TestDefault < SimpleRouteCase - describe "a default response is HTML and UTF8" - - get "/content_type/base" - assert_body "Hello world!" - assert_header "Content-Type", "text/html; charset=utf-8" - end - - class TestSetOnResponseObj < SimpleRouteCase - describe "setting the content type of the response directly on the response object" - - get "/content_type/base/set_on_response_obj" - assert_body "Hello world!" - assert_header "Content-Type", "application/rss+xml; charset=utf-8" - end - - class TestSetOnRender < SimpleRouteCase - describe "setting the content type of the response as an option to render" - - get "/content_type/base/set_on_render" - assert_body "Hello world!" - assert_header "Content-Type", "application/rss+xml; charset=utf-8" - end - + class ImpliedController < ActionController::Base + # Template's mime type is used if no content_type is specified + self.view_paths = [ActionView::Template::FixturePath.new( "content_type/implied/i_am_html_erb.html.erb" => "Hello world!", "content_type/implied/i_am_xml_erb.xml.erb" => "<xml>Hello world!</xml>", "content_type/implied/i_am_html_builder.html.builder" => "xml.p 'Hello'", "content_type/implied/i_am_xml_builder.xml.builder" => "xml.awesome 'Hello'" )] - + def i_am_html_erb() end def i_am_xml_erb() end def i_am_html_builder() end def i_am_xml_builder() end end - - class TestImpliedController < SimpleRouteCase - describe "the template's mime type is used if no content_type is specified" - + + class CharsetController < ActionController::Base + def set_on_response_obj + response.charset = "utf-16" + render :text => "Hello world!" + end + + def set_as_nil_on_response_obj + response.charset = nil + render :text => "Hello world!" + end + end + + class ExplicitContentTypeTest < SimpleRouteCase + test "default response is HTML and UTF8" do + get "/content_type/base" + + assert_body "Hello world!" + assert_header "Content-Type", "text/html; charset=utf-8" + end + + test "setting the content type of the response directly on the response object" do + get "/content_type/base/set_on_response_obj" + + assert_body "Hello world!" + assert_header "Content-Type", "application/rss+xml; charset=utf-8" + end + + test "setting the content type of the response as an option to render" do + get "/content_type/base/set_on_render" + + assert_body "Hello world!" + assert_header "Content-Type", "application/rss+xml; charset=utf-8" + end + end + + class ImpliedContentTypeTest < SimpleRouteCase test "sets Content-Type as text/html when rendering *.html.erb" do get "/content_type/implied/i_am_html_erb" + assert_header "Content-Type", "text/html; charset=utf-8" end test "sets Content-Type as application/xml when rendering *.xml.erb" do get "/content_type/implied/i_am_xml_erb" + assert_header "Content-Type", "application/xml; charset=utf-8" end test "sets Content-Type as text/html when rendering *.html.builder" do get "/content_type/implied/i_am_html_builder" + assert_header "Content-Type", "text/html; charset=utf-8" end test "sets Content-Type as application/xml when rendering *.xml.builder" do get "/content_type/implied/i_am_xml_builder" + assert_header "Content-Type", "application/xml; charset=utf-8" end - end -end -module Charset - class BaseController < ActionController::Base - def set_on_response_obj - response.charset = "utf-16" - render :text => "Hello world!" + class ExplicitCharsetTest < SimpleRouteCase + test "setting the charset of the response directly on the response object" do + get "/content_type/charset/set_on_response_obj" + + assert_body "Hello world!" + assert_header "Content-Type", "text/html; charset=utf-16" end - - def set_as_nil_on_response_obj - response.charset = nil - render :text => "Hello world!" + + test "setting the charset of the response as nil directly on the response object" do + get "/content_type/charset/set_as_nil_on_response_obj" + + assert_body "Hello world!" + assert_header "Content-Type", "text/html; charset=utf-8" end end - - class TestSetOnResponseObj < SimpleRouteCase - describe "setting the charset of the response directly on the response object" - - get "/charset/base/set_on_response_obj" - assert_body "Hello world!" - assert_header "Content-Type", "text/html; charset=utf-16" - end - - class TestSetAsNilOnResponseObj < SimpleRouteCase - describe "setting the charset of the response as nil directly on the response object" - - get "/charset/base/set_as_nil_on_response_obj" - assert_body "Hello world!" - assert_header "Content-Type", "text/html; charset=utf-8" - end -end
\ No newline at end of file +end diff --git a/actionpack/test/new_base/etag_test.rb b/actionpack/test/new_base/etag_test.rb index 7af5febfb3..a40d3c936a 100644 --- a/actionpack/test/new_base/etag_test.rb +++ b/actionpack/test/new_base/etag_test.rb @@ -1,47 +1,46 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") module Etags - class BasicController < ActionController::Base - self.view_paths = [ActionView::Template::FixturePath.new( "etags/basic/base.html.erb" => "Hello from without_layout.html.erb", "layouts/etags.html.erb" => "teh <%= yield %> tagz" )] - + def without_layout render :action => "base" end - + def with_layout - render :action => "base", :layout => "etag" + render :action => "base", :layout => "etags" end - end - - class TestBasic < SimpleRouteCase + + class EtagTest < SimpleRouteCase describe "Rendering without any special etag options returns an etag that is an MD5 hash of its text" - + test "an action without a layout" do get "/etags/basic/without_layout" + body = "Hello from without_layout.html.erb" assert_body body assert_header "Etag", etag_for(body) assert_status 200 end - + test "an action with a layout" do get "/etags/basic/with_layout" + body = "teh Hello from without_layout.html.erb tagz" assert_body body assert_header "Etag", etag_for(body) assert_status 200 end - + + private + def etag_for(text) %("#{Digest::MD5.hexdigest(text)}") end end - - end
\ No newline at end of file diff --git a/actionpack/test/new_base/render_action_test.rb b/actionpack/test/new_base/render_action_test.rb index f25faee433..4402eadf42 100644 --- a/actionpack/test/new_base/render_action_test.rb +++ b/actionpack/test/new_base/render_action_test.rb @@ -1,26 +1,24 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") module RenderAction - # This has no layout and it works class BasicController < ActionController::Base - self.view_paths = [ActionView::Template::FixturePath.new( "render_action/basic/hello_world.html.erb" => "Hello world!" )] - + def hello_world render :action => "hello_world" end - + def hello_world_as_string render "hello_world" end - + def hello_world_as_string_with_options render "hello_world", :status => 404 end - + def hello_world_as_symbol render :hello_world end @@ -28,105 +26,95 @@ module RenderAction def hello_world_with_symbol render :action => :hello_world end - + def hello_world_with_layout render :action => "hello_world", :layout => true end - + def hello_world_with_layout_false render :action => "hello_world", :layout => false end - + def hello_world_with_layout_nil render :action => "hello_world", :layout => nil end - + def hello_world_with_custom_layout render :action => "hello_world", :layout => "greetings" end - - end - - class TestBasic < SimpleRouteCase - describe "Rendering an action using :action => <String>" - - get "/render_action/basic/hello_world" - assert_body "Hello world!" - assert_status 200 - end - - class TestWithString < SimpleRouteCase - describe "Render an action using 'hello_world'" - - get "/render_action/basic/hello_world_as_string" - assert_body "Hello world!" - assert_status 200 - end - - class TestWithStringAndOptions < SimpleRouteCase - describe "Render an action using 'hello_world'" - - get "/render_action/basic/hello_world_as_string_with_options" - assert_body "Hello world!" - assert_status 404 - end - - class TestAsSymbol < SimpleRouteCase - describe "Render an action using :hello_world" - - get "/render_action/basic/hello_world_as_symbol" - assert_body "Hello world!" - assert_status 200 + end - - class TestWithSymbol < SimpleRouteCase - describe "Render an action using :action => :hello_world" - - get "/render_action/basic/hello_world_with_symbol" - assert_body "Hello world!" - assert_status 200 + + class RenderActionTest < SimpleRouteCase + test "rendering an action using :action => <String>" do + get "/render_action/basic/hello_world" + + assert_body "Hello world!" + assert_status 200 + end + + test "rendering an action using '<action>'" do + get "/render_action/basic/hello_world_as_string" + + assert_body "Hello world!" + assert_status 200 + end + + test "rendering an action using '<action>' and options" do + get "/render_action/basic/hello_world_as_string_with_options" + + assert_body "Hello world!" + assert_status 404 + end + + test "rendering an action using :action" do + get "/render_action/basic/hello_world_as_symbol" + + assert_body "Hello world!" + assert_status 200 + end + + test "rendering an action using :action => :hello_world" do + get "/render_action/basic/hello_world_with_symbol" + + assert_body "Hello world!" + assert_status 200 + end end - - class TestLayoutTrue < SimpleRouteCase - describe "rendering a normal template with full path with layout => true" - - test "raises an exception when requesting a layout and none exist" do - assert_raise(ArgumentError, /no default layout for RenderAction::BasicController in/) do - get "/render_action/basic/hello_world_with_layout" + + class RenderLayoutTest < SimpleRouteCase + describe "Both <controller_path>.html.erb and application.html.erb are missing" + + test "rendering with layout => true" do + assert_raise(ArgumentError, /no default layout for RenderAction::BasicController in/) do + get "/render_action/basic/hello_world_with_layout", {}, "action_dispatch.show_exceptions" => false end end - end - - class TestLayoutFalse < SimpleRouteCase - describe "rendering a normal template with full path with layout => false" - - get "/render_action/basic/hello_world_with_layout_false" - assert_body "Hello world!" - assert_status 200 - end - - class TestLayoutNil < SimpleRouteCase - describe "rendering a normal template with full path with layout => :nil" - - get "/render_action/basic/hello_world_with_layout_nil" - assert_body "Hello world!" - assert_status 200 - end - - class TestCustomLayout < SimpleRouteCase - describe "rendering a normal template with full path with layout => 'greetings'" - - test "raises an exception when requesting a layout that does not exist" do - assert_raise(ActionView::MissingTemplate) { get "/render_action/basic/hello_world_with_custom_layout" } + + test "rendering with layout => false" do + get "/render_action/basic/hello_world_with_layout_false" + + assert_body "Hello world!" + assert_status 200 + end + + test "rendering with layout => :nil" do + get "/render_action/basic/hello_world_with_layout_nil" + + assert_body "Hello world!" + assert_status 200 + end + + test "rendering with layout => 'greetings'" do + assert_raise(ActionView::MissingTemplate) do + get "/render_action/basic/hello_world_with_custom_layout", {}, "action_dispatch.show_exceptions" => false + end end end - end module RenderActionWithApplicationLayout - # # ==== Render actions with layouts ==== - class BasicController < ::ApplicationController # Set the view path to an application view structure with layouts self.view_paths = self.view_paths = [ActionView::Template::FixturePath.new( @@ -136,205 +124,197 @@ module RenderActionWithApplicationLayout "layouts/greetings.html.erb" => "Greetings <%= yield %> Bai", "layouts/builder.html.builder" => "xml.html do\n xml << yield\nend" )] - + def hello_world render :action => "hello_world" end - + def hello_world_with_layout render :action => "hello_world", :layout => true end - + def hello_world_with_layout_false render :action => "hello_world", :layout => false end - + def hello_world_with_layout_nil render :action => "hello_world", :layout => nil end - + def hello_world_with_custom_layout render :action => "hello_world", :layout => "greetings" end - + def with_builder_and_layout render :action => "hello", :layout => "builder" end end - - class TestDefaultLayout < SimpleRouteCase - describe %( - Render hello_world and implicitly use application.html.erb as a layout if - no layout is specified and no controller layout is present - ) - - get "/render_action_with_application_layout/basic/hello_world" - assert_body "OHAI Hello World! KTHXBAI" - assert_status 200 - end - - class TestLayoutTrue < SimpleRouteCase - describe "rendering a normal template with full path with layout => true" - - get "/render_action_with_application_layout/basic/hello_world_with_layout" - assert_body "OHAI Hello World! KTHXBAI" - assert_status 200 - end - - class TestLayoutFalse < SimpleRouteCase - describe "rendering a normal template with full path with layout => false" - - get "/render_action_with_application_layout/basic/hello_world_with_layout_false" - assert_body "Hello World!" - assert_status 200 - end - - class TestLayoutNil < SimpleRouteCase - describe "rendering a normal template with full path with layout => :nil" - - get "/render_action_with_application_layout/basic/hello_world_with_layout_nil" - assert_body "Hello World!" - assert_status 200 - end - - class TestCustomLayout < SimpleRouteCase - describe "rendering a normal template with full path with layout => 'greetings'" - - get "/render_action_with_application_layout/basic/hello_world_with_custom_layout" - assert_body "Greetings Hello World! Bai" - assert_status 200 + + class LayoutTest < SimpleRouteCase + describe "Only application.html.erb is present and <controller_path>.html.erb is missing" + + test "rendering implicit application.html.erb as layout" do + get "/render_action_with_application_layout/basic/hello_world" + + assert_body "OHAI Hello World! KTHXBAI" + assert_status 200 + end + + test "rendering with layout => true" do + get "/render_action_with_application_layout/basic/hello_world_with_layout" + + assert_body "OHAI Hello World! KTHXBAI" + assert_status 200 + end + + test "rendering with layout => false" do + get "/render_action_with_application_layout/basic/hello_world_with_layout_false" + + assert_body "Hello World!" + assert_status 200 + end + + test "rendering with layout => :nil" do + get "/render_action_with_application_layout/basic/hello_world_with_layout_nil" + + assert_body "Hello World!" + assert_status 200 + end + + test "rendering with layout => 'greetings'" do + get "/render_action_with_application_layout/basic/hello_world_with_custom_layout" + + assert_body "Greetings Hello World! Bai" + assert_status 200 + end end - + class TestLayout < SimpleRouteCase testing BasicController - + test "builder works with layouts" do get :with_builder_and_layout assert_response "<html>\n<p>Omg</p>\n</html>\n" end end - + end module RenderActionWithControllerLayout - class BasicController < ActionController::Base self.view_paths = self.view_paths = [ActionView::Template::FixturePath.new( "render_action_with_controller_layout/basic/hello_world.html.erb" => "Hello World!", "layouts/render_action_with_controller_layout/basic.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI" )] - + def hello_world render :action => "hello_world" end - + def hello_world_with_layout render :action => "hello_world", :layout => true end - + def hello_world_with_layout_false render :action => "hello_world", :layout => false end - + def hello_world_with_layout_nil render :action => "hello_world", :layout => nil end - + def hello_world_with_custom_layout render :action => "hello_world", :layout => "greetings" end end - - class TestControllerLayout < SimpleRouteCase - describe "Render hello_world and implicitly use <controller_path>.html.erb as a layout." - get "/render_action_with_controller_layout/basic/hello_world" - assert_body "With Controller Layout! Hello World! KTHXBAI" - assert_status 200 - end - - class TestLayoutTrue < SimpleRouteCase - describe "rendering a normal template with full path with layout => true" - - get "/render_action_with_controller_layout/basic/hello_world_with_layout" - assert_body "With Controller Layout! Hello World! KTHXBAI" - assert_status 200 - end - - class TestLayoutFalse < SimpleRouteCase - describe "rendering a normal template with full path with layout => false" - - get "/render_action_with_controller_layout/basic/hello_world_with_layout_false" - assert_body "Hello World!" - assert_status 200 - end - - class TestLayoutNil < SimpleRouteCase - describe "rendering a normal template with full path with layout => :nil" - - get "/render_action_with_controller_layout/basic/hello_world_with_layout_nil" - assert_body "Hello World!" - assert_status 200 + class ControllerLayoutTest < SimpleRouteCase + describe "Only <controller_path>.html.erb is present and application.html.erb is missing" + + test "render hello_world and implicitly use <controller_path>.html.erb as a layout." do + get "/render_action_with_controller_layout/basic/hello_world" + + assert_body "With Controller Layout! Hello World! KTHXBAI" + assert_status 200 + end + + test "rendering with layout => true" do + get "/render_action_with_controller_layout/basic/hello_world_with_layout" + + assert_body "With Controller Layout! Hello World! KTHXBAI" + assert_status 200 + end + + test "rendering with layout => false" do + get "/render_action_with_controller_layout/basic/hello_world_with_layout_false" + + assert_body "Hello World!" + assert_status 200 + end + + test "rendering with layout => :nil" do + get "/render_action_with_controller_layout/basic/hello_world_with_layout_nil" + + assert_body "Hello World!" + assert_status 200 + end end - end module RenderActionWithBothLayouts - class BasicController < ActionController::Base self.view_paths = [ActionView::Template::FixturePath.new({ "render_action_with_both_layouts/basic/hello_world.html.erb" => "Hello World!", "layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI", "layouts/render_action_with_both_layouts/basic.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI" })] - + def hello_world render :action => "hello_world" end - + def hello_world_with_layout render :action => "hello_world", :layout => true end - + def hello_world_with_layout_false render :action => "hello_world", :layout => false end - + def hello_world_with_layout_nil render :action => "hello_world", :layout => nil end end - - class TestControllerLayoutFirst < SimpleRouteCase - describe "Render hello_world and implicitly use <controller_path>.html.erb over application.html.erb as a layout" - get "/render_action_with_both_layouts/basic/hello_world" - assert_body "With Controller Layout! Hello World! KTHXBAI" - assert_status 200 - end - - class TestLayoutTrue < SimpleRouteCase - describe "rendering a normal template with full path with layout => true" - - get "/render_action_with_both_layouts/basic/hello_world_with_layout" - assert_body "With Controller Layout! Hello World! KTHXBAI" - assert_status 200 - end - - class TestLayoutFalse < SimpleRouteCase - describe "rendering a normal template with full path with layout => false" - - get "/render_action_with_both_layouts/basic/hello_world_with_layout_false" - assert_body "Hello World!" - assert_status 200 - end - - class TestLayoutNil < SimpleRouteCase - describe "rendering a normal template with full path with layout => :nil" - - get "/render_action_with_both_layouts/basic/hello_world_with_layout_nil" - assert_body "Hello World!" - assert_status 200 + class ControllerLayoutTest < SimpleRouteCase + describe "Both <controller_path>.html.erb and application.html.erb are present" + + test "rendering implicitly use <controller_path>.html.erb over application.html.erb as a layout" do + get "/render_action_with_both_layouts/basic/hello_world" + + assert_body "With Controller Layout! Hello World! KTHXBAI" + assert_status 200 + end + + test "rendering with layout => true" do + get "/render_action_with_both_layouts/basic/hello_world_with_layout" + + assert_body "With Controller Layout! Hello World! KTHXBAI" + assert_status 200 + end + + test "rendering with layout => false" do + get "/render_action_with_both_layouts/basic/hello_world_with_layout_false" + + assert_body "Hello World!" + assert_status 200 + end + + test "rendering with layout => :nil" do + get "/render_action_with_both_layouts/basic/hello_world_with_layout_nil" + + assert_body "Hello World!" + assert_status 200 + end end - end
\ No newline at end of file diff --git a/actionpack/test/new_base/render_implicit_action_test.rb b/actionpack/test/new_base/render_implicit_action_test.rb index 58f5cec181..2846df48da 100644 --- a/actionpack/test/new_base/render_implicit_action_test.rb +++ b/actionpack/test/new_base/render_implicit_action_test.rb @@ -10,19 +10,19 @@ module RenderImplicitAction def hello_world() end end - class TestImplicitRender < SimpleRouteCase - describe "render a simple action with new explicit call to render" - - get "/render_implicit_action/simple/hello_world" - assert_body "Hello world!" - assert_status 200 - end - - class TestImplicitWithSpecialCharactersRender < SimpleRouteCase - describe "render an action with a missing method and has special characters" - - get "/render_implicit_action/simple/hyphen-ated" - assert_body "Hello hyphen-ated!" - assert_status 200 + class RenderImplicitActionTest < SimpleRouteCase + test "render a simple action with new explicit call to render" do + get "/render_implicit_action/simple/hello_world" + + assert_body "Hello world!" + assert_status 200 + end + + test "render an action with a missing method and has special characters" do + get "/render_implicit_action/simple/hyphen-ated" + + assert_body "Hello hyphen-ated!" + assert_status 200 + end end end
\ No newline at end of file diff --git a/actionpack/test/new_base/render_layout_test.rb b/actionpack/test/new_base/render_layout_test.rb index dc858b4f5c..f32c60d683 100644 --- a/actionpack/test/new_base/render_layout_test.rb +++ b/actionpack/test/new_base/render_layout_test.rb @@ -2,72 +2,100 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") module ControllerLayouts class ImplicitController < ::ApplicationController - self.view_paths = [ActionView::Template::FixturePath.new( "layouts/application.html.erb" => "OMG <%= yield %> KTHXBAI", "layouts/override.html.erb" => "Override! <%= yield %>", "basic.html.erb" => "Hello world!", "controller_layouts/implicit/layout_false.html.erb" => "hai(layout_false.html.erb)" )] - + def index render :template => "basic" end - + def override render :template => "basic", :layout => "override" end - + def layout_false render :layout => false end - + def builder_override - end end - - class TestImplicitLayout < SimpleRouteCase - describe "rendering a normal template, but using the implicit layout" - - get "/controller_layouts/implicit/index" - assert_body "OMG Hello world! KTHXBAI" - assert_status 200 - end - + class ImplicitNameController < ::ApplicationController - self.view_paths = [ActionView::Template::FixturePath.new( "layouts/controller_layouts/implicit_name.html.erb" => "OMGIMPLICIT <%= yield %> KTHXBAI", "basic.html.erb" => "Hello world!" )] - + def index render :template => "basic" end end - - class TestImplicitNamedLayout < SimpleRouteCase - describe "rendering a normal template, but using an implicit NAMED layout" - - get "/controller_layouts/implicit_name/index" - assert_body "OMGIMPLICIT Hello world! KTHXBAI" - assert_status 200 - end - - class TestOverridingImplicitLayout < SimpleRouteCase - describe "overriding an implicit layout with render :layout option" - - get "/controller_layouts/implicit/override" - assert_body "Override! Hello world!" + + class RenderLayoutTest < SimpleRouteCase + test "rendering a normal template, but using the implicit layout" do + get "/controller_layouts/implicit/index" + + assert_body "OMG Hello world! KTHXBAI" + assert_status 200 + end + + test "rendering a normal template, but using an implicit NAMED layout" do + get "/controller_layouts/implicit_name/index" + + assert_body "OMGIMPLICIT Hello world! KTHXBAI" + assert_status 200 + end + + test "overriding an implicit layout with render :layout option" do + get "/controller_layouts/implicit/override" + assert_body "Override! Hello world!" + end + end - - class TestLayoutOptions < SimpleRouteCase + + class LayoutOptionsTest < SimpleRouteCase testing ControllerLayouts::ImplicitController - + test "rendering with :layout => false leaves out the implicit layout" do get :layout_false assert_response "hai(layout_false.html.erb)" end end + + class MismatchFormatController < ::ApplicationController + self.view_paths = [ActionView::Template::FixturePath.new( + "layouts/application.html.erb" => "<html><%= yield %></html>", + "controller_layouts/mismatch_format/index.js.rjs" => "page[:test].omg", + "controller_layouts/mismatch_format/implicit.rjs" => "page[:test].omg" + )] + + def explicit + render :layout => "application" + end + end + + class MismatchFormatTest < SimpleRouteCase + testing ControllerLayouts::MismatchFormatController + + test "if JS is selected, an HTML template is not also selected" do + get :index + assert_response "$(\"test\").omg();" + end + + test "if JS is implicitly selected, an HTML template is not also selected" do + get :implicit + assert_response "$(\"test\").omg();" + end + + test "if an HTML template is explicitly provides for a JS template, an error is raised" do + assert_raises ActionView::MissingTemplate do + get :explicit, {}, "action_dispatch.show_exceptions" => false + end + end + end end
\ No newline at end of file diff --git a/actionpack/test/new_base/render_template_test.rb b/actionpack/test/new_base/render_template_test.rb index 6c50ae4203..face5b7571 100644 --- a/actionpack/test/new_base/render_template_test.rb +++ b/actionpack/test/new_base/render_template_test.rb @@ -79,7 +79,6 @@ module RenderTemplate end class WithLayoutController < ::ApplicationController - self.view_paths = [ActionView::Template::FixturePath.new( "test/basic.html.erb" => "Hello from basic.html.erb", "shared.html.erb" => "Elastica", @@ -108,46 +107,45 @@ module RenderTemplate end end - class TestTemplateRenderWithLayout < SimpleRouteCase - describe "rendering a normal template with full path with layout" - - get "/render_template/with_layout" - assert_body "Hello from basic.html.erb, I'm here!" - assert_status 200 - end - - class TestTemplateRenderWithLayoutTrue < SimpleRouteCase - describe "rendering a normal template with full path with layout => :true" - - get "/render_template/with_layout/with_layout" - assert_body "Hello from basic.html.erb, I'm here!" - assert_status 200 - end - - class TestTemplateRenderWithLayoutFalse < SimpleRouteCase - describe "rendering a normal template with full path with layout => :false" - - get "/render_template/with_layout/with_layout_false" - assert_body "Hello from basic.html.erb" - assert_status 200 - end - - class TestTemplateRenderWithLayoutNil < SimpleRouteCase - describe "rendering a normal template with full path with layout => :nil" - - get "/render_template/with_layout/with_layout_nil" - assert_body "Hello from basic.html.erb" - assert_status 200 - end - - class TestTemplateRenderWithCustomLayout < SimpleRouteCase - describe "rendering a normal template with full path with layout => 'greetings'" - - get "/render_template/with_layout/with_custom_layout" - assert_body "Hello from basic.html.erb, I wish thee well." - assert_status 200 + class TestWithLayout < SimpleRouteCase + describe "Rendering with :template using implicit or explicit layout" + + test "rendering with implicit layout" do + get "/render_template/with_layout" + + assert_body "Hello from basic.html.erb, I'm here!" + assert_status 200 + end + + test "rendering with layout => :true" do + get "/render_template/with_layout/with_layout" + + assert_body "Hello from basic.html.erb, I'm here!" + assert_status 200 + end + + test "rendering with layout => :false" do + get "/render_template/with_layout/with_layout_false" + + assert_body "Hello from basic.html.erb" + assert_status 200 + end + + test "rendering with layout => :nil" do + get "/render_template/with_layout/with_layout_nil" + + assert_body "Hello from basic.html.erb" + assert_status 200 + end + + test "rendering layout => 'greetings'" do + get "/render_template/with_layout/with_custom_layout" + + assert_body "Hello from basic.html.erb, I wish thee well." + assert_status 200 + end end - + module Compatibility class WithoutLayoutController < ActionController::Base self.view_paths = [ActionView::Template::FixturePath.new( @@ -161,11 +159,12 @@ module RenderTemplate end class TestTemplateRenderWithForwardSlash < SimpleRouteCase - describe "rendering a normal template with full path starting with a leading slash" + test "rendering a normal template with full path starting with a leading slash" do + get "/render_template/compatibility/without_layout/with_forward_slash" - get "/render_template/compatibility/without_layout/with_forward_slash" - assert_body "Hello from basic.html.erb" - assert_status 200 + assert_body "Hello from basic.html.erb" + assert_status 200 + end end end end
\ No newline at end of file diff --git a/actionpack/test/new_base/render_test.rb b/actionpack/test/new_base/render_test.rb index b1867fdcc2..ed3d50fa0b 100644 --- a/actionpack/test/new_base/render_test.rb +++ b/actionpack/test/new_base/render_test.rb @@ -8,63 +8,60 @@ module Render "render/blank_render/access_action_name.html.erb" => "Action Name: <%= action_name %>", "render/blank_render/access_controller_name.html.erb" => "Controller Name: <%= controller_name %>" )] - + def index render end - + def access_request render :action => "access_request" end - + def render_action_name render :action => "access_action_name" end - - private - + + private + def secretz render :text => "FAIL WHALE!" end end - - class TestBlankRender < SimpleRouteCase - describe "Render with blank" - get "/render/blank_render" - assert_body "Hello world!" - assert_status 200 - end - class DoubleRenderController < ActionController::Base def index render :text => "hello" render :text => "world" end end - - class TestBasic < SimpleRouteCase - describe "Rendering more than once" - - test "raises an exception" do + + class RenderTest < SimpleRouteCase + test "render with blank" do + get "/render/blank_render" + + assert_body "Hello world!" + assert_status 200 + end + + test "rendering more than once raises an exception" do assert_raises(AbstractController::DoubleRenderError) do - get "/render/double_render" + get "/render/double_render", {}, "action_dispatch.show_exceptions" => false end end end - + class TestOnlyRenderPublicActions < SimpleRouteCase describe "Only public methods on actual controllers are callable actions" - + test "raises an exception when a method of Object is called" do assert_raises(AbstractController::ActionNotFound) do - get "/render/blank_render/clone" + get "/render/blank_render/clone", {}, "action_dispatch.show_exceptions" => false end end - + test "raises an exception when a private method is called" do assert_raises(AbstractController::ActionNotFound) do - get "/render/blank_render/secretz" + get "/render/blank_render/secretz", {}, "action_dispatch.show_exceptions" => false end end end @@ -74,12 +71,12 @@ module Render get "/render/blank_render/access_request" assert_body "The request: GET" end - + test "The action_name is accessible in the view" do get "/render/blank_render/render_action_name" assert_body "Action Name: render_action_name" end - + test "The controller_name is accessible in the view" do get "/render/blank_render/access_controller_name" assert_body "Controller Name: blank_render" diff --git a/actionpack/test/new_base/render_text_test.rb b/actionpack/test/new_base/render_text_test.rb index 39f2f7abbf..ffc149283b 100644 --- a/actionpack/test/new_base/render_text_test.rb +++ b/actionpack/test/new_base/render_text_test.rb @@ -1,8 +1,5 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") -class ApplicationController < ActionController::Base -end - module RenderText class SimpleController < ActionController::Base self.view_paths = [ActionView::Template::FixturePath.new] @@ -11,15 +8,7 @@ module RenderText render :text => "hello david" end end - - class TestSimpleTextRenderWithNoLayout < SimpleRouteCase - describe "Rendering text from a action with default options renders the text with the layout" - - get "/render_text/simple" - assert_body "hello david" - assert_status 200 - end - + class WithLayoutController < ::ApplicationController self.view_paths = [ActionView::Template::FixturePath.new( "layouts/application.html.erb" => "<%= yield %>, I'm here!", @@ -73,77 +62,78 @@ module RenderText end end - class TestSimpleTextRenderWithLayout < SimpleRouteCase - describe "Rendering text from a action with default options renders the text without the layout" - - get "/render_text/with_layout" - assert_body "hello david" - assert_status 200 - end - - class TestTextRenderWithStatus < SimpleRouteCase - describe "Rendering text, while also providing a custom status code" - - get "/render_text/with_layout/custom_code" - assert_body "hello world" - assert_status 404 - end - - class TestTextRenderWithNil < SimpleRouteCase - describe "Rendering text with nil returns a single space character" - - get "/render_text/with_layout/with_nil" - assert_body " " - assert_status 200 - end - - class TestTextRenderWithNilAndStatus < SimpleRouteCase - describe "Rendering text with nil and custom status code returns a single space character with the status" - - get "/render_text/with_layout/with_nil_and_status" - assert_body " " - assert_status 403 - end - - class TestTextRenderWithFalse < SimpleRouteCase - describe "Rendering text with false returns the string 'false'" - - get "/render_text/with_layout/with_false" - assert_body "false" - assert_status 200 - end - - class TestTextRenderWithLayoutTrue < SimpleRouteCase - describe "Rendering text with :layout => true" - - get "/render_text/with_layout/with_layout_true" - assert_body "hello world, I'm here!" - assert_status 200 - end - - class TestTextRenderWithCustomLayout < SimpleRouteCase - describe "Rendering text with :layout => 'greetings'" - - get "/render_text/with_layout/with_custom_layout" - assert_body "hello world, I wish thee well." - assert_status 200 - end - - class TestTextRenderWithLayoutFalse < SimpleRouteCase - describe "Rendering text with :layout => false" - - get "/render_text/with_layout/with_layout_false" - assert_body "hello world" - assert_status 200 - end - - class TestTextRenderWithLayoutNil < SimpleRouteCase - describe "Rendering text with :layout => nil" - - get "/render_text/with_layout/with_layout_nil" - assert_body "hello world" - assert_status 200 + class RenderTextTest < SimpleRouteCase + describe "Rendering text using render :text" + + test "rendering text from a action with default options renders the text with the layout" do + get "/render_text/simple" + assert_body "hello david" + assert_status 200 + end + + test "rendering text from a action with default options renders the text without the layout" do + get "/render_text/with_layout" + + assert_body "hello david" + assert_status 200 + end + + test "rendering text, while also providing a custom status code" do + get "/render_text/with_layout/custom_code" + + assert_body "hello world" + assert_status 404 + end + + test "rendering text with nil returns an empty body padded for Safari" do + get "/render_text/with_layout/with_nil" + + assert_body " " + assert_status 200 + end + + test "Rendering text with nil and custom status code returns an empty body padded for Safari and the status" do + get "/render_text/with_layout/with_nil_and_status" + + assert_body " " + assert_status 403 + end + + test "rendering text with false returns the string 'false'" do + get "/render_text/with_layout/with_false" + + assert_body "false" + assert_status 200 + end + + test "rendering text with :layout => true" do + get "/render_text/with_layout/with_layout_true" + + assert_body "hello world, I'm here!" + assert_status 200 + end + + test "rendering text with :layout => 'greetings'" do + get "/render_text/with_layout/with_custom_layout" + + assert_body "hello world, I wish thee well." + assert_status 200 + end + + test "rendering text with :layout => false" do + get "/render_text/with_layout/with_layout_false" + + assert_body "hello world" + assert_status 200 + end + + test "rendering text with :layout => nil" do + get "/render_text/with_layout/with_layout_nil" + + assert_body "hello world" + assert_status 200 + end end end -ActionController::Base.app_loaded!
\ No newline at end of file +ActionController::Base.app_loaded! diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/new_base/test_helper.rb index ec7dbffaae..d92029df7f 100644 --- a/actionpack/test/new_base/test_helper.rb +++ b/actionpack/test/new_base/test_helper.rb @@ -20,8 +20,8 @@ require 'action_controller/abstract' require 'action_controller/new_base' require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late -require 'rubygems' -require 'rack/test' +require 'action_controller/testing/process' +require 'action_controller/testing/integration' module Rails def self.env @@ -32,19 +32,17 @@ module Rails end # Temporary base class -class Rack::TestCase < ActiveSupport::TestCase - include Rack::Test::Methods - +class Rack::TestCase < ActionController::IntegrationTest setup do ActionController::Base.session_options[:key] = "abc" ActionController::Base.session_options[:secret] = ("*" * 30) - + controllers = ActionController::Base.subclasses.map do |k| k.underscore.sub(/_controller$/, '') end - + ActionController::Routing.use_controllers!(controllers) - + # Move into a bootloader ActionController::Base.subclasses.each do |klass| klass = klass.constantize @@ -52,13 +50,13 @@ class Rack::TestCase < ActiveSupport::TestCase klass.class_eval do _write_layout_method end - end + end end - + def app @app ||= ActionController::Dispatcher.new end - + def self.testing(klass = nil) if klass @testing = "/#{klass.name.underscore}".sub!(/_controller$/, '') @@ -66,41 +64,23 @@ class Rack::TestCase < ActiveSupport::TestCase @testing end end - - def self.get(url) - setup do |test| - test.get url - end - end - + def get(thing, *args) if thing.is_a?(Symbol) - super("#{self.class.testing}/#{thing}") + super("#{self.class.testing}/#{thing}", *args) else super end end - + def assert_body(body) - assert_equal body, Array.wrap(last_response.body).join - end - - def self.assert_body(body) - test "body is set to '#{body}'" do - assert_body body - end + assert_equal body, Array.wrap(response.body).join end - + def assert_status(code) - assert_equal code, last_response.status - end - - def self.assert_status(code) - test "status code is set to #{code}" do - assert_status code - end + assert_equal code, response.status end - + def assert_response(body, status = 200, headers = {}) assert_body body assert_status status @@ -108,27 +88,14 @@ class Rack::TestCase < ActiveSupport::TestCase assert_header header, value end end - + def assert_content_type(type) - assert_equal type, last_response.headers["Content-Type"] + assert_equal type, response.headers["Content-Type"] end - - def self.assert_content_type(type) - test "content type is set to #{type}" do - assert_content_type(type) - end - end - + def assert_header(name, value) - assert_equal value, last_response.headers[name] - end - - def self.assert_header(name, value) - test "'#{name}' header is set to #{value.inspect}" do - assert_header(name, value) - end + assert_equal value, response.headers[name] end - end class ::ApplicationController < ActionController::Base |