From 8fac2c88cae0f2fd42fad3c2c2c6c860df14d629 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 14 May 2009 15:30:35 -0700 Subject: Cleaning up more render tests --- actionpack/test/controller/render_test.rb | 5 ++ actionpack/test/new_base/render_action_test.rb | 17 +++++- actionpack/test/new_base/render_layout_test.rb | 2 - actionpack/test/new_base/render_partial_test.rb | 27 +++++++++ actionpack/test/new_base/render_template_test.rb | 76 +++++++++++++++--------- actionpack/test/new_base/render_xml_test.rb | 11 ++++ actionpack/test/new_base/test_helper.rb | 2 +- 7 files changed, 108 insertions(+), 32 deletions(-) create mode 100644 actionpack/test/new_base/render_partial_test.rb create mode 100644 actionpack/test/new_base/render_xml_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 469e8601d0..a750f018b8 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -262,6 +262,7 @@ class TestController < ActionController::Base render :action => "hello_world" end + # :ported: def builder_layout_test render :action => "hello", :layout => "layouts/builder" end @@ -271,6 +272,7 @@ class TestController < ActionController::Base render :action => "hello_world_container" end + # :ported: def partials_list @test_unchanged = 'hello' @customers = [ Customer.new("david"), Customer.new("mary") ] @@ -860,6 +862,7 @@ class RenderTest < ActionController::TestCase assert_equal "application/xml", @response.content_type end + # :ported: def test_render_xml_as_string_template get :render_xml_hello_as_string_template assert_equal "\n

Hello David

\n

This is grand!

\n\n", @response.body @@ -872,11 +875,13 @@ class RenderTest < ActionController::TestCase assert_equal "

This is grand!

\n", @response.body end + # :move: test in AV def test_render_xml_with_partial get :builder_partial_test assert_equal "\n \n\n", @response.body end + # :ported: def test_layout_rendering get :layout_test assert_equal "Hello world!", @response.body diff --git a/actionpack/test/new_base/render_action_test.rb b/actionpack/test/new_base/render_action_test.rb index 348d70381b..f25faee433 100644 --- a/actionpack/test/new_base/render_action_test.rb +++ b/actionpack/test/new_base/render_action_test.rb @@ -131,8 +131,10 @@ module RenderActionWithApplicationLayout # Set the view path to an application view structure with layouts self.view_paths = self.view_paths = [ActionView::Template::FixturePath.new( "render_action_with_application_layout/basic/hello_world.html.erb" => "Hello World!", + "render_action_with_application_layout/basic/hello.html.builder" => "xml.p 'Omg'", "layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI", - "layouts/greetings.html.erb" => "Greetings <%= yield %> Bai" + "layouts/greetings.html.erb" => "Greetings <%= yield %> Bai", + "layouts/builder.html.builder" => "xml.html do\n xml << yield\nend" )] def hello_world @@ -154,6 +156,10 @@ module RenderActionWithApplicationLayout 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 @@ -199,6 +205,15 @@ module RenderActionWithApplicationLayout assert_status 200 end + class TestLayout < SimpleRouteCase + testing BasicController + + test "builder works with layouts" do + get :with_builder_and_layout + assert_response "\n

Omg

\n\n" + end + end + end module RenderActionWithControllerLayout diff --git a/actionpack/test/new_base/render_layout_test.rb b/actionpack/test/new_base/render_layout_test.rb index 7f627f86ec..dc858b4f5c 100644 --- a/actionpack/test/new_base/render_layout_test.rb +++ b/actionpack/test/new_base/render_layout_test.rb @@ -22,8 +22,6 @@ module ControllerLayouts render :layout => false end - - def builder_override end diff --git a/actionpack/test/new_base/render_partial_test.rb b/actionpack/test/new_base/render_partial_test.rb new file mode 100644 index 0000000000..3a300afe5c --- /dev/null +++ b/actionpack/test/new_base/render_partial_test.rb @@ -0,0 +1,27 @@ +require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") + +module RenderPartial + + class BasicController < ActionController::Base + + self.view_paths = [ActionView::Template::FixturePath.new( + "render_partial/basic/_basic.html.erb" => "OMG!", + "render_partial/basic/basic.html.erb" => "<%= @test_unchanged = 'goodbye' %><%= render :partial => 'basic' %><%= @test_unchanged %>" + )] + + def changing + @test_unchanged = 'hello' + render :action => "basic" + end + end + + class TestPartial < SimpleRouteCase + testing BasicController + + test "rendering a partial in ActionView doesn't pull the ivars again from the controller" do + get :changing + assert_response("goodbyeOMG!goodbye") + 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 c09eeb1926..6c50ae4203 100644 --- a/actionpack/test/new_base/render_template_test.rb +++ b/actionpack/test/new_base/render_template_test.rb @@ -4,14 +4,19 @@ module RenderTemplate class WithoutLayoutController < ActionController::Base self.view_paths = [ActionView::Template::FixturePath.new( - "test/basic.html.erb" => "Hello from basic.html.erb", - "shared.html.erb" => "Elastica", - "locals.html.erb" => "The secret is <%= secret %>" + "test/basic.html.erb" => "Hello from basic.html.erb", + "shared.html.erb" => "Elastica", + "locals.html.erb" => "The secret is <%= secret %>", + "xml_template.xml.builder" => "xml.html do\n xml.p 'Hello'\nend" )] def index render :template => "test/basic" end + + def index_without_key + render "test/basic" + end def in_top_directory render :template => 'shared' @@ -21,41 +26,56 @@ module RenderTemplate render :template => '/shared' end + def in_top_directory_with_slash_without_key + render '/shared' + end + def with_locals render :template => "locals", :locals => { :secret => 'area51' } end + + def builder_template + render :template => "xml_template" + end end class TestWithoutLayout < SimpleRouteCase - describe "rendering a normal template with full path without layout" + testing RenderTemplate::WithoutLayoutController - get "/render_template/without_layout" - assert_body "Hello from basic.html.erb" - assert_status 200 - end - - class TestTemplateRenderInTopDirectory < SimpleRouteCase - describe "rendering a template not in a subdirectory" + test "rendering a normal template with full path without layout" do + get :index + assert_response "Hello from basic.html.erb" + end - get "/render_template/without_layout/in_top_directory" - assert_body "Elastica" - assert_status 200 - end - - class TestTemplateRenderInTopDirectoryWithSlash < SimpleRouteCase - describe "rendering a template not in a subdirectory with a leading slash" + test "rendering a normal template with full path without layout without key" do + get :index_without_key + assert_response "Hello from basic.html.erb" + end - get "/render_template/without_layout/in_top_directory_with_slash" - assert_body "Elastica" - assert_status 200 - end - - class TestTemplateRenderWithLocals < SimpleRouteCase - describe "rendering a template with local variables" + test "rendering a template not in a subdirectory" do + get :in_top_directory + assert_response "Elastica" + end - get "/render_template/without_layout/with_locals" - assert_body "The secret is area51" - assert_status 200 + test "rendering a template not in a subdirectory with a leading slash" do + get :in_top_directory_with_slash + assert_response "Elastica" + end + + test "rendering a template not in a subdirectory with a leading slash without key" do + get :in_top_directory_with_slash_without_key + assert_response "Elastica" + end + + test "rendering a template with local variables" do + get :with_locals + assert_response "The secret is area51" + end + + test "rendering a builder template" do + get :builder_template + assert_response "\n

Hello

\n\n" + end end class WithLayoutController < ::ApplicationController diff --git a/actionpack/test/new_base/render_xml_test.rb b/actionpack/test/new_base/render_xml_test.rb new file mode 100644 index 0000000000..e6c40b1533 --- /dev/null +++ b/actionpack/test/new_base/render_xml_test.rb @@ -0,0 +1,11 @@ +require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") + +module RenderXml + + # This has no layout and it works + class BasicController < ActionController::Base + self.view_paths = [ActionView::Template::FixturePath.new( + "render_xml/basic/with_render_erb" => "Hello world!" + )] + end +end \ No newline at end of file diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/new_base/test_helper.rb index a7302af060..ec7dbffaae 100644 --- a/actionpack/test/new_base/test_helper.rb +++ b/actionpack/test/new_base/test_helper.rb @@ -46,7 +46,7 @@ class Rack::TestCase < ActiveSupport::TestCase ActionController::Routing.use_controllers!(controllers) # Move into a bootloader - AbstractController::Base.subclasses.each do |klass| + ActionController::Base.subclasses.each do |klass| klass = klass.constantize next unless klass < AbstractController::Layouts klass.class_eval do -- cgit v1.2.3 From da65320433088548bc4cff33758e5acd71fd137a Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 14 May 2009 17:25:10 -0700 Subject: Got new base to pass controller/base_test.rb, implemented method_missing action semantics in compatibility mode, and fixed a few action_missing bugs. --- actionpack/test/abstract_unit.rb | 2 +- actionpack/test/controller/base_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 825ac9a46c..7982f06545 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -37,7 +37,7 @@ ActionController::Base.session_store = nil # Register danish language for testing I18n.backend.store_translations 'da', {} I18n.backend.store_translations 'pt-BR', {} -ORIGINAL_LOCALES = I18n.available_locales.map(&:to_s).sort +ORIGINAL_LOCALES = I18n.available_locales.map {|locale| locale.to_s }.sort FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures') ActionController::Base.view_paths = FIXTURE_LOAD_PATH diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index a09db95d7d..3a4cdb81d9 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -117,7 +117,7 @@ class PerformActionTest < ActionController::TestCase end def method_missing(method, *args) - @logged << args.first + @logged << args.first.to_s end end -- cgit v1.2.3 From eb021707f53be46140b55a48e5ef03ed0577a45c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 1 Apr 2009 12:44:56 +0200 Subject: Allow strings to be sent as collection to select. Signed-off-by: Michael Koziarski --- .../test/template/form_options_helper_test.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 78db87971b..73624406be 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -80,6 +80,14 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_string_options_for_select + options = "" + assert_dom_equal( + options, + options_for_select(options) + ) + end + def test_array_options_for_select assert_dom_equal( "\n\n", @@ -324,6 +332,20 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_select_under_fields_for_with_string_and_given_prompt + @post = Post.new + options = "" + + fields_for :post, @post do |f| + concat f.select(:category, options, :prompt => 'The prompt') + end + + assert_dom_equal( + "", + output_buffer + ) + end + def test_select_with_blank @post = Post.new @post.category = "" -- cgit v1.2.3 From 7e10504bdeab14ea70a942110a1b1ef6d8467ed3 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Fri, 15 May 2009 15:57:12 -0700 Subject: Refactored AbstractController to provide better hook points for overriding aspects of action dispatching --- actionpack/test/abstract_controller/abstract_controller_test.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_controller/abstract_controller_test.rb b/actionpack/test/abstract_controller/abstract_controller_test.rb index 689aa99fd8..9c028e7d1e 100644 --- a/actionpack/test/abstract_controller/abstract_controller_test.rb +++ b/actionpack/test/abstract_controller/abstract_controller_test.rb @@ -201,11 +201,10 @@ module AbstractController def fail() self.response_body = "fail" end private - - def respond_to_action?(action_name) - action_name.to_s != "fail" + + def method_for_action(action_name) + action_name.to_s != "fail" && action_name end - end class TestRespondToAction < ActiveSupport::TestCase -- cgit v1.2.3 From 5a45446cff0daf4ca747257a8779dcd5d9cae1d7 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Fri, 15 May 2009 17:49:11 -0700 Subject: Ported Rescuable to new base --- actionpack/test/abstract_unit2.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit2.rb b/actionpack/test/abstract_unit2.rb index 932f594ad2..519e6bea36 100644 --- a/actionpack/test/abstract_unit2.rb +++ b/actionpack/test/abstract_unit2.rb @@ -11,11 +11,19 @@ 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' + +ActiveSupport::Dependencies.hook! FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures') module ActionController - + Base.session = { + :key => '_testing_session', + :secret => '8273f16463985e2b3747dc25e30f2528' +} + class ActionControllerError < StandardError #:nodoc: end @@ -126,6 +134,6 @@ module ActionController "Expected no partials to be rendered" end end - end + end end end -- cgit v1.2.3 From 7f318c3ec535afe53733c55cd0ecaccc16a8b944 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sat, 16 May 2009 14:15:26 -0400 Subject: Instead of checking Rails.env.test? in Failsafe middleware, check env["rails.raise_exceptions"] --- actionpack/test/new_base/render_action_test.rb | 6 ++++-- actionpack/test/new_base/render_test.rb | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/new_base/render_action_test.rb b/actionpack/test/new_base/render_action_test.rb index f25faee433..96666077d2 100644 --- a/actionpack/test/new_base/render_action_test.rb +++ b/actionpack/test/new_base/render_action_test.rb @@ -92,7 +92,7 @@ module RenderAction 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" + get "/render_action/basic/hello_world_with_layout", {}, "rails.raise_exceptions" => true end end end @@ -117,7 +117,9 @@ module RenderAction 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" } + assert_raise(ActionView::MissingTemplate) do + get "/render_action/basic/hello_world_with_custom_layout", {}, "rails.raise_exceptions" => true + end end end diff --git a/actionpack/test/new_base/render_test.rb b/actionpack/test/new_base/render_test.rb index b1867fdcc2..16578fbc82 100644 --- a/actionpack/test/new_base/render_test.rb +++ b/actionpack/test/new_base/render_test.rb @@ -48,7 +48,7 @@ module Render test "raises an exception" do assert_raises(AbstractController::DoubleRenderError) do - get "/render/double_render" + get "/render/double_render", {}, "rails.raise_exceptions" => true end end end @@ -58,13 +58,13 @@ module Render 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", {}, "rails.raise_exceptions" => true 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", {}, "rails.raise_exceptions" => true end end end -- cgit v1.2.3 From 11bac700784efe232083f94e3d28d171957e667e Mon Sep 17 00:00:00 2001 From: Lance Ivy Date: Wed, 15 Apr 2009 16:46:30 -0700 Subject: Ensure auto_link does not ignore multiple trailing punctuations [#2504 state:resolved] Signed-off-by: Pratik Naik --- actionpack/test/template/text_helper_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index be7163888e..a780bfc606 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -401,6 +401,13 @@ class TextHelperTest < ActionView::TestCase auto_link("Welcome to my new blog at http://www.myblog.com/. Please e-mail me at me@email.com.", :link => :all, :html => { :class => "menu", :target => "_blank" }) end + + def test_auto_link_with_multiple_trailing_punctuations + url = "http://youtube.com" + url_result = generate_result(url) + assert_equal url_result, auto_link(url) + assert_equal "(link: #{url_result}).", auto_link("(link: #{url}).") + end def test_cycle_class value = Cycle.new("one", 2, "3") -- cgit v1.2.3 From 98eaa2c6834e418959f2a1a18421e4811167e03b Mon Sep 17 00:00:00 2001 From: Travis Briggs Date: Wed, 18 Mar 2009 21:51:26 -0400 Subject: Ensure number_to_human_size does not strip zeros from the end [#1763 state:resolved] Signed-off-by: Pratik Naik --- actionpack/test/template/number_helper_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/number_helper_test.rb b/actionpack/test/template/number_helper_test.rb index 29cb60fd73..b6542ef29d 100644 --- a/actionpack/test/template/number_helper_test.rb +++ b/actionpack/test/template/number_helper_test.rb @@ -118,6 +118,10 @@ class NumberHelperTest < ActionView::TestCase assert_equal '1.01 KB', number_to_human_size(1.0123.kilobytes, :precision => 2) assert_equal '1.01 KB', number_to_human_size(1.0100.kilobytes, :precision => 4) assert_equal '10 KB', number_to_human_size(10.000.kilobytes, :precision => 4) + assert_equal '1 TB', number_to_human_size(1234567890123, :precision => 0) + assert_equal '500 MB', number_to_human_size(524288000, :precision=>0) + assert_equal '40 KB', number_to_human_size(41010, :precision => 0) + assert_equal '40 KB', number_to_human_size(41100, :precision => 0) end def test_number_to_human_size_with_custom_delimiter_and_separator -- cgit v1.2.3 From c3319504f066c9362b4b30e1e15bbd1cadde8e25 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 17 May 2009 11:09:14 -0500 Subject: Rescue hack was supposed to be removed. Some how it crept back in. --- actionpack/test/controller/filters_test.rb | 1 - actionpack/test/controller/helper_test.rb | 3 --- 2 files changed, 4 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index 9ad49e9282..afefc6a77e 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -607,7 +607,6 @@ class FilterTest < Test::Unit::TestCase def test_dynamic_dispatch %w(foo bar baz).each do |action| request = ActionController::TestRequest.new - request.env["action_controller.rescue.request"] = request request.query_parameters[:choose] = action response = DynamicDispatchController.action.call(request.env).last assert_equal action, response.body diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb index 7b8096fccc..3bbda9eb3a 100644 --- a/actionpack/test/controller/helper_test.rb +++ b/actionpack/test/controller/helper_test.rb @@ -104,7 +104,6 @@ class HelperTest < Test::Unit::TestCase def call_controller(klass, action) request = ActionController::TestRequest.new - request.env["action_controller.rescue.request"] = request klass.action(action).call(request.env) end @@ -112,7 +111,6 @@ class HelperTest < Test::Unit::TestCase assert_equal 'hello: Iz guuut!', call_controller(Fun::GamesController, "render_hello_world").last.body # request = ActionController::TestRequest.new - # request.env["action_controller.rescue.request"] = request # # resp = Fun::GamesController.action(:render_hello_world).call(request.env) # assert_equal 'hello: Iz guuut!', resp.last.body @@ -217,7 +215,6 @@ class IsolatedHelpersTest < Test::Unit::TestCase def call_controller(klass, action) request = ActionController::TestRequest.new - request.env["action_controller.rescue.request"] = request klass.action(action).call(request.env) end -- cgit v1.2.3 From 8118fca9beec675fba19395e7d1027eaa4b5703a Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 17 May 2009 12:24:42 -0500 Subject: Merge Failsafe middleware into ShowExceptions --- actionpack/test/controller/rescue_test.rb | 14 ++++++++++++++ actionpack/test/dispatch/show_exceptions_test.rb | 5 +++++ actionpack/test/new_base/render_action_test.rb | 4 ++-- actionpack/test/new_base/render_test.rb | 6 +++--- 4 files changed, 24 insertions(+), 5 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index f745926b20..490a4ff3b3 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -1,5 +1,19 @@ require 'abstract_unit' +module ActionDispatch + class ShowExceptions + private + def public_path + "#{FIXTURE_LOAD_PATH}/public" + end + + # Silence logger + def logger + nil + end + end +end + class RescueController < ActionController::Base class NotAuthorized < StandardError end diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index f8f562e7c1..0c0c087340 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -6,6 +6,11 @@ module ActionDispatch def public_path "#{FIXTURE_LOAD_PATH}/public" end + + # Silence logger + def logger + nil + end end end diff --git a/actionpack/test/new_base/render_action_test.rb b/actionpack/test/new_base/render_action_test.rb index 96666077d2..626c7b3540 100644 --- a/actionpack/test/new_base/render_action_test.rb +++ b/actionpack/test/new_base/render_action_test.rb @@ -92,7 +92,7 @@ module RenderAction 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", {}, "rails.raise_exceptions" => true + get "/render_action/basic/hello_world_with_layout", {}, "action_dispatch.show_exceptions" => false end end end @@ -118,7 +118,7 @@ module RenderAction test "raises an exception when requesting a layout that does not exist" do assert_raise(ActionView::MissingTemplate) do - get "/render_action/basic/hello_world_with_custom_layout", {}, "rails.raise_exceptions" => true + get "/render_action/basic/hello_world_with_custom_layout", {}, "action_dispatch.show_exceptions" => false end end end diff --git a/actionpack/test/new_base/render_test.rb b/actionpack/test/new_base/render_test.rb index 16578fbc82..ef5e7d89c5 100644 --- a/actionpack/test/new_base/render_test.rb +++ b/actionpack/test/new_base/render_test.rb @@ -48,7 +48,7 @@ module Render test "raises an exception" do assert_raises(AbstractController::DoubleRenderError) do - get "/render/double_render", {}, "rails.raise_exceptions" => true + get "/render/double_render", {}, "action_dispatch.show_exceptions" => false end end end @@ -58,13 +58,13 @@ module Render test "raises an exception when a method of Object is called" do assert_raises(AbstractController::ActionNotFound) do - get "/render/blank_render/clone", {}, "rails.raise_exceptions" => true + 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", {}, "rails.raise_exceptions" => true + get "/render/blank_render/secretz", {}, "action_dispatch.show_exceptions" => false end end end -- cgit v1.2.3 From edc9c226d11e6104d191ceeb6416c7062ceda54a Mon Sep 17 00:00:00 2001 From: Mike Breen Date: Sun, 17 May 2009 19:48:15 +0200 Subject: Add tests for assert_template :template Signed-off-by: Pratik Naik --- .../test/controller/action_pack_assertions_test.rb | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 484d3c5ce7..c3c769919a 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -12,6 +12,9 @@ class ActionPackAssertionsController < ActionController::Base # a standard template def hello_xml_world() render :template => "test/hello_xml_world"; end + # a standard partial + def partial() render :partial => 'test/partial'; end + # a redirect to an internal location def redirect_internal() redirect_to "/nothing"; end @@ -331,6 +334,26 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase end end + def test_assert_template_with_partial + get :partial + assert_template :partial => '_partial' + end + + def test_assert_template_with_nil + get :nothing + assert_template nil + end + + def test_assert_template_with_string + get :hello_world + assert_template 'hello_world' + end + + def test_assert_template_with_symbol + get :hello_world + assert_template :hello_world + end + # check if we were rendered by a file-based template? def test_rendered_action process :nothing -- cgit v1.2.3 From 092089015b79752c5e9d664b3eeefef9e2223e36 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 17 May 2009 13:39:44 -0500 Subject: Extract generic callbacks middleware from dispatcher --- actionpack/test/controller/dispatcher_test.rb | 34 ++++++++++++++++----------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index b315232a7b..9fae1fcf63 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -6,20 +6,20 @@ class DispatcherTest < Test::Unit::TestCase def setup ENV['REQUEST_METHOD'] = 'GET' - Dispatcher.middleware = ActionDispatch::MiddlewareStack.new do |middleware| - middlewares = File.expand_path(File.join(File.dirname(__FILE__), "../../lib/action_controller/dispatch/middlewares.rb")) - middleware.instance_eval(File.read(middlewares)) - end - # Clear callbacks as they are redefined by Dispatcher#define_dispatcher_callbacks - Dispatcher.instance_variable_set("@prepare_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new) - Dispatcher.instance_variable_set("@before_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new) - Dispatcher.instance_variable_set("@after_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new) + ActionDispatch::Callbacks.instance_variable_set("@prepare_callbacks", ActiveSupport::Callbacks::CallbackChain.new) + ActionDispatch::Callbacks.instance_variable_set("@before_callbacks", ActiveSupport::Callbacks::CallbackChain.new) + ActionDispatch::Callbacks.instance_variable_set("@after_callbacks", ActiveSupport::Callbacks::CallbackChain.new) + @old_router, Dispatcher.router = Dispatcher.router, mock() + Dispatcher.router.stubs(:call).returns([200, {}, 'response']) + Dispatcher.router.stubs(:reload) Dispatcher.stubs(:require_dependency) end def teardown + Dispatcher.router = @old_router + @dispatcher = nil ENV.delete 'REQUEST_METHOD' end @@ -29,12 +29,12 @@ class DispatcherTest < Test::Unit::TestCase end def test_reloads_routes_before_dispatch_if_in_loading_mode - ActionController::Routing::Routes.expects(:reload).once + Dispatcher.router.expects(:reload).once dispatch(false) end def test_leaves_dependencies_after_dispatch_if_not_in_loading_mode - ActionController::Routing::Routes.expects(:reload).never + Dispatcher.router.expects(:reload).never ActiveSupport::Dependencies.expects(:clear).never dispatch @@ -55,7 +55,7 @@ class DispatcherTest < Test::Unit::TestCase assert_nil a || b || c # Run callbacks - Dispatcher.run_prepare_callbacks + dispatch assert_equal 1, a assert_equal 2, b @@ -72,16 +72,22 @@ class DispatcherTest < Test::Unit::TestCase Dispatcher.to_prepare(:unique_id) { |*args| a = b = 1 } Dispatcher.to_prepare(:unique_id) { |*args| a = 2 } - Dispatcher.run_prepare_callbacks + dispatch assert_equal 2, a assert_equal nil, b end private def dispatch(cache_classes = true) - ActionController::Routing::RouteSet.any_instance.stubs(:call).returns([200, {}, 'response']) + ActionController::Dispatcher.prepare_each_request = false Dispatcher.define_dispatcher_callbacks(cache_classes) - Dispatcher.new.call({'rack.input' => StringIO.new('')}) + Dispatcher.middleware = ActionDispatch::MiddlewareStack.new do |middleware| + middlewares = File.expand_path(File.join(File.dirname(__FILE__), "../../lib/action_controller/dispatch/middlewares.rb")) + middleware.instance_eval(File.read(middlewares)) + end + + @dispatcher ||= Dispatcher.new + @dispatcher.call({'rack.input' => StringIO.new(''), 'action_dispatch.show_exceptions' => false}) end def assert_subclasses(howmany, klass, message = klass.subclasses.inspect) -- cgit v1.2.3 From 01d7acd11d631d980497870aad1af42a0c66115c Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 17 May 2009 14:42:36 -0500 Subject: Fix reset_session with ActiveRecord store [#2200 state:resolved] --- actionpack/test/activerecord/active_record_store_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/activerecord/active_record_store_test.rb b/actionpack/test/activerecord/active_record_store_test.rb index 663cd259c8..47f8496181 100644 --- a/actionpack/test/activerecord/active_record_store_test.rb +++ b/actionpack/test/activerecord/active_record_store_test.rb @@ -28,9 +28,9 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest end def call_reset_session - session[:bar] + session[:foo] reset_session - session[:bar] = "baz" + session[:foo] = "baz" head :ok end @@ -91,7 +91,7 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest get '/get_session_value' assert_response :success - assert_equal 'foo: nil', response.body + assert_equal 'foo: "baz"', response.body get '/get_session_id' assert_response :success -- cgit v1.2.3 From 195fadbfd31294d43634afb7bbf4f0ffc86b470a Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Mon, 18 May 2009 16:59:37 +0200 Subject: Ensure HTTP Digest auth uses appropriate HTTP method [#2490 state:resolved] [Steve Madsen] --- .../controller/http_digest_authentication_test.rb | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/http_digest_authentication_test.rb b/actionpack/test/controller/http_digest_authentication_test.rb index 7bebc8cd2a..b8a2205ce6 100644 --- a/actionpack/test/controller/http_digest_authentication_test.rb +++ b/actionpack/test/controller/http_digest_authentication_test.rb @@ -149,6 +149,16 @@ class HttpDigestAuthenticationTest < ActionController::TestCase assert_equal 'Definitely Maybe', @response.body end + test "authentication request with _method" do + @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please', :method => :post) + @request.env['rack.methodoverride.original_method'] = 'POST' + put :display + + assert_response :success + assert assigns(:logged_in) + assert_equal 'Definitely Maybe', @response.body + end + private def encode_credentials(options) @@ -159,15 +169,22 @@ class HttpDigestAuthenticationTest < ActionController::TestCase # to prevent tampering of timestamp ActionController::Base.session_options[:secret] = "session_options_secret" - # Perform unauthenticated GET to retrieve digest parameters to use on subsequent request - get :index + # Perform unauthenticated request to retrieve digest parameters to use on subsequent request + method = options.delete(:method) || 'GET' + + case method.to_s.upcase + when 'GET' + get :index + when 'POST' + post :index + end assert_response :unauthorized credentials = decode_credentials(@response.headers['WWW-Authenticate']) credentials.merge!(options) credentials.reverse_merge!(:uri => "#{@request.env['REQUEST_URI']}") - ActionController::HttpAuthentication::Digest.encode_credentials("GET", credentials, password, options[:password_is_ha1]) + ActionController::HttpAuthentication::Digest.encode_credentials(method, credentials, password, options[:password_is_ha1]) end def decode_credentials(header) -- cgit v1.2.3