diff options
author | Rizwan Reza <rizwanreza@gmail.com> | 2010-03-28 12:04:00 +0430 |
---|---|---|
committer | Rizwan Reza <rizwanreza@gmail.com> | 2010-03-28 12:04:00 +0430 |
commit | b4c91de9462f59d6395c7c871aafa3301afdc383 (patch) | |
tree | fadcaf603a6f473e8ccd52070a1f3b4f957c34cb /actionpack/test/controller | |
parent | 4b4f69b9bfbd33556e23262f57cf6d944dfd9f63 (diff) | |
parent | 66d57d7ba83df52ff1e0485c89f6192c2f84c6b8 (diff) | |
download | rails-b4c91de9462f59d6395c7c871aafa3301afdc383.tar.gz rails-b4c91de9462f59d6395c7c871aafa3301afdc383.tar.bz2 rails-b4c91de9462f59d6395c7c871aafa3301afdc383.zip |
Merge remote branch 'rails/master'
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/action_pack_assertions_test.rb | 13 | ||||
-rw-r--r-- | actionpack/test/controller/base_test.rb | 39 | ||||
-rw-r--r-- | actionpack/test/controller/caching_test.rb | 38 | ||||
-rw-r--r-- | actionpack/test/controller/cookie_test.rb | 11 | ||||
-rw-r--r-- | actionpack/test/controller/filters_test.rb | 4 | ||||
-rw-r--r-- | actionpack/test/controller/integration_test.rb | 8 | ||||
-rw-r--r-- | actionpack/test/controller/layout_test.rb | 16 | ||||
-rw-r--r-- | actionpack/test/controller/mime_responds_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/new_base/bare_metal_test.rb | 27 | ||||
-rw-r--r-- | actionpack/test/controller/new_base/metal_test.rb | 6 | ||||
-rw-r--r-- | actionpack/test/controller/new_base/middleware_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/new_base/render_action_test.rb | 4 | ||||
-rw-r--r-- | actionpack/test/controller/new_base/render_rjs_test.rb | 18 | ||||
-rw-r--r-- | actionpack/test/controller/render_test.rb | 24 |
14 files changed, 144 insertions, 68 deletions
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 26e0d6d844..1741b58f72 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -181,6 +181,8 @@ module Admin end end +# require "action_dispatch/test_process" + # a test case to exercise the new capabilities TestRequest & TestResponse class ActionPackAssertionsControllerTest < ActionController::TestCase # -- assertion-based testing ------------------------------------------------ @@ -303,14 +305,14 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase # make sure that the template objects exist def test_template_objects_alive process :assign_this - assert !@controller.template.instance_variable_get(:"@hi") - assert @controller.template.instance_variable_get(:"@howdy") + assert !@controller.instance_variable_get(:"@hi") + assert @controller.instance_variable_get(:"@howdy") end # make sure we don't have template objects when we shouldn't def test_template_object_missing process :nothing - assert_nil @controller.template.assigns['howdy'] + assert_nil @controller.instance_variable_get(:@howdy) end # check the empty flashing @@ -365,11 +367,10 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase # check if we were rendered by a file-based template? def test_rendered_action process :nothing - assert_nil @controller.template.rendered[:template] + assert_template nil process :hello_world - assert @controller.template.rendered[:template] - assert 'hello_world', @controller.template.rendered[:template].to_s + assert_template 'hello_world' end # check the redirection location diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index f047e7da30..49f79681f6 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -56,6 +56,16 @@ protected end end +class AnotherMethodMissingController < ActionController::Base + cattr_accessor :_exception + rescue_from Exception, :with => :_exception= + + protected + def method_missing(*attrs, &block) + super + end +end + class DefaultUrlOptionsController < ActionController::Base def from_view render :inline => "<%= #{params[:route]} %>" @@ -124,11 +134,11 @@ class ControllerInstanceTests < Test::Unit::TestCase def test_action_methods @empty_controllers.each do |c| - assert_equal Set.new, c.class.__send__(:action_methods), "#{c.controller_path} should be empty!" + assert_equal Set.new, c.class.action_methods, "#{c.controller_path} should be empty!" end @non_empty_controllers.each do |c| - assert_equal Set.new(%w(public_action)), c.class.__send__(:action_methods), "#{c.controller_path} should not be empty!" + assert_equal Set.new(%w(public_action)), c.class.action_methods, "#{c.controller_path} should not be empty!" end end @@ -173,6 +183,12 @@ class PerformActionTest < ActionController::TestCase assert_equal 'method_missing', @response.body end + def test_method_missing_should_recieve_symbol + use_controller AnotherMethodMissingController + get :some_action + assert_kind_of NameError, @controller._exception + end + def test_get_on_hidden_should_fail use_controller NonEmptyController assert_raise(ActionController::UnknownAction) { get :hidden_action } @@ -191,7 +207,7 @@ class UrlOptionsTest < ActionController::TestCase def test_url_options_override with_routing do |set| - set.draw do |map| + set.draw do match 'from_view', :to => 'url_options#from_view', :as => :from_view match ':controller/:action' end @@ -202,7 +218,18 @@ class UrlOptionsTest < ActionController::TestCase assert_equal 'http://www.override.com/from_view?locale=en', @controller.send(:from_view_url) assert_equal 'http://www.override.com/default_url_options/new?locale=en', @controller.url_for(:controller => 'default_url_options') end - end + end + + def test_url_helpers_does_not_become_actions + with_routing do |set| + set.draw do + match "account/overview" + end + + @controller.class.send(:include, set.url_helpers) + assert !@controller.class.action_methods.include?("account_overview_path") + end + end end class DefaultUrlOptionsTest < ActionController::TestCase @@ -216,7 +243,7 @@ class DefaultUrlOptionsTest < ActionController::TestCase def test_default_url_options_override with_routing do |set| - set.draw do |map| + set.draw do match 'from_view', :to => 'default_url_options#from_view', :as => :from_view match ':controller/:action' end @@ -231,7 +258,7 @@ class DefaultUrlOptionsTest < ActionController::TestCase def test_default_url_options_are_used_in_non_positional_parameters with_routing do |set| - set.draw do |map| + set.draw do scope("/:locale") do resources :descriptions end diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index a792752ef4..f0ad652d50 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -285,6 +285,8 @@ class ActionCacheTest < ActionController::TestCase assert_not_equal cached_time, @response.body end + include RackTestUtils + def test_action_cache_with_layout get :with_layout cached_time = content_to_cache @@ -294,8 +296,8 @@ class ActionCacheTest < ActionController::TestCase get :with_layout assert_not_equal cached_time, @response.body - - assert_equal @response.body, read_fragment('hostname.com/action_caching_test/with_layout') + body = body_to_string(read_fragment('hostname.com/action_caching_test/with_layout')) + assert_equal @response.body, body end def test_action_cache_with_layout_and_layout_cache_false @@ -308,7 +310,8 @@ class ActionCacheTest < ActionController::TestCase get :layout_false assert_not_equal cached_time, @response.body - assert_equal cached_time, read_fragment('hostname.com/action_caching_test/layout_false') + body = body_to_string(read_fragment('hostname.com/action_caching_test/layout_false')) + assert_equal cached_time, body end def test_action_cache_conditional_options @@ -616,8 +619,10 @@ class FragmentCachingTest < ActionController::TestCase @store.write('views/expensive', 'fragment content') fragment_computed = false + view_context = @controller.view_context + buffer = 'generated till now -> '.html_safe - @controller.fragment_for(buffer, 'expensive') { fragment_computed = true } + buffer << view_context.send(:fragment_for, 'expensive') { fragment_computed = true } assert fragment_computed assert_equal 'generated till now -> ', buffer @@ -627,8 +632,10 @@ class FragmentCachingTest < ActionController::TestCase @store.write('views/expensive', 'fragment content') fragment_computed = false + view_context = @controller.view_context + buffer = 'generated till now -> '.html_safe - @controller.fragment_for(buffer, 'expensive') { fragment_computed = true } + buffer << view_context.send(:fragment_for, 'expensive') { fragment_computed = true } assert !fragment_computed assert_equal 'generated till now -> fragment content', buffer @@ -704,8 +711,8 @@ CACHED def test_fragment_caching_in_partials get :html_fragment_cached_with_partial assert_response :success - assert_match /Fragment caching in a partial/, @response.body - assert_match "Fragment caching in a partial", @store.read('views/test.host/functional_caching/html_fragment_cached_with_partial') + assert_match /Old fragment caching in a partial/, @response.body + assert_match "Old fragment caching in a partial", @store.read('views/test.host/functional_caching/html_fragment_cached_with_partial') end def test_render_inline_before_fragment_caching @@ -719,14 +726,14 @@ CACHED def test_fragment_caching_in_rjs_partials xhr :get, :js_fragment_cached_with_partial assert_response :success - assert_match /Fragment caching in a partial/, @response.body - assert_match "Fragment caching in a partial", @store.read('views/test.host/functional_caching/js_fragment_cached_with_partial') + assert_match /Old fragment caching in a partial/, @response.body + assert_match "Old fragment caching in a partial", @store.read('views/test.host/functional_caching/js_fragment_cached_with_partial') end def test_html_formatted_fragment_caching get :formatted_fragment_cached, :format => "html" assert_response :success - expected_body = "<body>\n<p>ERB</p>\n</body>" + expected_body = "<body>\n<p>ERB</p>\n</body>\n" assert_equal expected_body, @response.body @@ -742,15 +749,4 @@ CACHED assert_equal " <p>Builder</p>\n", @store.read('views/test.host/functional_caching/formatted_fragment_cached') end - - def test_js_formatted_fragment_caching - get :formatted_fragment_cached, :format => "js" - assert_response :success - expected_body = %(title = "Hey";\n$("element_1").visualEffect("highlight");\n) + - %($("element_2").visualEffect("highlight");\nfooter = "Bye";) - assert_equal expected_body, @response.body - - assert_equal ['$("element_1").visualEffect("highlight");', '$("element_2").visualEffect("highlight");'], - @store.read('views/test.host/functional_caching/formatted_fragment_cached') - end end diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb index 908967a110..36498d13a9 100644 --- a/actionpack/test/controller/cookie_test.rb +++ b/actionpack/test/controller/cookie_test.rb @@ -64,6 +64,12 @@ class CookieTest < ActionController::TestCase cookies.permanent.signed[:remember_me] = 100 head :ok end + + def delete_and_set_cookie + cookies.delete :user_name + cookies[:user_name] = { :value => "david", :expires => Time.utc(2005, 10, 10,5) } + head :ok + end end tests TestController @@ -152,6 +158,11 @@ class CookieTest < ActionController::TestCase assert_equal 100, @controller.send(:cookies).signed[:remember_me] end + def test_delete_and_set_cookie + get :delete_and_set_cookie + assert_cookie_header "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT" + assert_equal({"user_name" => "david"}, @response.cookies) + end private def assert_cookie_header(expected) diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index 004e1369d3..ea740f7233 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -651,9 +651,9 @@ class FilterTest < ActionController::TestCase assert_equal %w( ensure_login find_user ), assigns["ran_filter"] test_process(ConditionalSkippingController, "login") - assert_nil @controller.template.controller.instance_variable_get("@ran_after_filter") + assert_nil @controller.instance_variable_get("@ran_after_filter") test_process(ConditionalSkippingController, "change_password") - assert_equal %w( clean_up ), @controller.template.controller.instance_variable_get("@ran_after_filter") + assert_equal %w( clean_up ), @controller.instance_variable_get("@ran_after_filter") end def test_conditional_skipping_of_filters_when_parent_filter_is_also_conditional diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 2180466ca7..c9782856bd 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -173,14 +173,12 @@ class IntegrationTestTest < Test::Unit::TestCase end def test_opens_new_session - @test.class.expects(:fixture_table_names).times(2).returns(['foo']) - session1 = @test.open_session { |sess| } session2 = @test.open_session # implicit session - assert_kind_of ::ActionController::Integration::Session, session1 - assert_kind_of ::ActionController::Integration::Session, session2 - assert_not_equal session1, session2 + assert session1.respond_to?(:assert_template), "open_session makes assert_template available" + assert session2.respond_to?(:assert_template), "open_session makes assert_template available" + assert !session1.equal?(session2) end # RSpec mixes Matchers (which has a #method_missing) into diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb index f635253156..4d687c1ec6 100644 --- a/actionpack/test/controller/layout_test.rb +++ b/actionpack/test/controller/layout_test.rb @@ -120,19 +120,19 @@ class LayoutSetInResponseTest < ActionController::TestCase def test_layout_set_when_using_default_layout @controller = DefaultLayoutController.new get :hello - assert @controller.template.layout.include?('layouts/layout_test') + assert_template :layout => "layouts/layout_test" end def test_layout_set_when_set_in_controller @controller = HasOwnLayoutController.new get :hello - assert @controller.template.layout.include?('layouts/item') + assert_template :layout => "layouts/item" end def test_layout_only_exception_when_included @controller = OnlyLayoutController.new get :hello - assert @controller.template.layout.include?('layouts/item') + assert_template :layout => "layouts/item" end def test_layout_only_exception_when_excepted @@ -144,7 +144,7 @@ class LayoutSetInResponseTest < ActionController::TestCase def test_layout_except_exception_when_included @controller = ExceptLayoutController.new get :hello - assert @controller.template.layout.include?('layouts/item') + assert_template :layout => "layouts/item" end def test_layout_except_exception_when_excepted @@ -156,19 +156,19 @@ class LayoutSetInResponseTest < ActionController::TestCase def test_layout_set_when_using_render @controller = SetsLayoutInRenderController.new get :hello - assert @controller.template.layout.include?('layouts/third_party_template_library') + assert_template :layout => "layouts/third_party_template_library" end def test_layout_is_not_set_when_none_rendered @controller = RendersNoLayoutController.new get :hello - assert_nil @controller.template.layout + assert_template :layout => nil end def test_layout_is_picked_from_the_controller_instances_view_path @controller = PrependsViewPathController.new get :hello - assert @controller.template.layout =~ /layouts\/alt\.\w+/ + assert_template :layout => /layouts\/alt\.\w+/ end def test_absolute_pathed_layout @@ -219,7 +219,7 @@ unless RUBY_PLATFORM =~ /(:?mswin|mingw|bccwin)/ @controller = LayoutSymlinkedTest.new get :hello assert_response 200 - assert @controller.template.layout.include?("layouts/symlinked/symlinked_layout") + assert_template :layout => "layouts/symlinked/symlinked_layout" end end end diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index 5c1eaf453c..53cd3f0801 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -765,7 +765,7 @@ class RespondWithControllerTest < ActionController::TestCase Customer.any_instance.stubs(:errors).returns(errors) post :using_resource_with_action - assert_equal "foo - #{[:html].to_s}", @controller.response_body + assert_equal "foo - #{[:html].to_s}", @controller.response.body end def test_respond_as_responder_entry_point diff --git a/actionpack/test/controller/new_base/bare_metal_test.rb b/actionpack/test/controller/new_base/bare_metal_test.rb new file mode 100644 index 0000000000..df4b39a103 --- /dev/null +++ b/actionpack/test/controller/new_base/bare_metal_test.rb @@ -0,0 +1,27 @@ +require "abstract_unit" + +module BareMetalTest + class BareController < ActionController::Metal + def index + self.response_body = "Hello world" + end + end + + class BareTest < ActiveSupport::TestCase + test "response body is a Rack-compatible response" do + status, headers, body = BareController.action(:index).call(Rack::MockRequest.env_for("/")) + assert_equal 200, status + string = "" + + body.each do |part| + assert part.is_a?(String), "Each part of the body must be a String" + string << part + end + + assert headers.is_a?(Hash), "Headers must be a Hash" + assert headers["Content-Type"], "Content-Type must exist" + + assert_equal "Hello world", string + end + end +end
\ No newline at end of file diff --git a/actionpack/test/controller/new_base/metal_test.rb b/actionpack/test/controller/new_base/metal_test.rb index ab61fd98ee..45a6619eb4 100644 --- a/actionpack/test/controller/new_base/metal_test.rb +++ b/actionpack/test/controller/new_base/metal_test.rb @@ -18,6 +18,8 @@ module MetalTest end class TestMiddleware < ActiveSupport::TestCase + include RackTestUtils + def setup @app = Rack::Builder.new do use MetalTest::MetalMiddleware @@ -29,14 +31,14 @@ module MetalTest env = Rack::MockRequest.env_for("/authed") response = @app.call(env) - assert_equal "Hello World", response[2] + assert_equal "Hello World", body_to_string(response[2]) end test "it can return a response using the normal AC::Metal techniques" do env = Rack::MockRequest.env_for("/") response = @app.call(env) - assert_equal "Not authed!", response[2] + assert_equal "Not authed!", body_to_string(response[2]) assert_equal 401, response[0] end end diff --git a/actionpack/test/controller/new_base/middleware_test.rb b/actionpack/test/controller/new_base/middleware_test.rb index ada0215b1a..65942ebc15 100644 --- a/actionpack/test/controller/new_base/middleware_test.rb +++ b/actionpack/test/controller/new_base/middleware_test.rb @@ -44,7 +44,7 @@ module MiddlewareTest test "middleware that is 'use'd is called as part of the Rack application" do result = @app.call(env_for("/")) - assert_equal "Hello World", result[2] + assert_equal "Hello World", RackTestUtils.body_to_string(result[2]) assert_equal "Success", result[1]["Middleware-Test"] end diff --git a/actionpack/test/controller/new_base/render_action_test.rb b/actionpack/test/controller/new_base/render_action_test.rb index 0804d7b09d..d92e9c4bf2 100644 --- a/actionpack/test/controller/new_base/render_action_test.rb +++ b/actionpack/test/controller/new_base/render_action_test.rb @@ -117,7 +117,7 @@ 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::FixtureResolver.new( + self.view_paths = [ActionView::FixtureResolver.new( "render_action_with_application_layout/basic/hello_world.html.erb" => "Hello World!", "render_action_with_application_layout/basic/hello.html.builder" => "xml.p 'Hello'", "layouts/application.html.erb" => "Hi <%= yield %> OK, Bye", @@ -202,7 +202,7 @@ end module RenderActionWithControllerLayout class BasicController < ActionController::Base - self.view_paths = self.view_paths = [ActionView::FixtureResolver.new( + self.view_paths = [ActionView::FixtureResolver.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 %> Bye" )] diff --git a/actionpack/test/controller/new_base/render_rjs_test.rb b/actionpack/test/controller/new_base/render_rjs_test.rb index f4516ade63..b602b9f8e9 100644 --- a/actionpack/test/controller/new_base/render_rjs_test.rb +++ b/actionpack/test/controller/new_base/render_rjs_test.rb @@ -5,8 +5,10 @@ module RenderRjs self.view_paths = [ActionView::FixtureResolver.new( "render_rjs/basic/index.js.rjs" => "page[:customer].replace_html render(:partial => 'customer')", "render_rjs/basic/index_html.js.rjs" => "page[:customer].replace_html :partial => 'customer'", + "render_rjs/basic/index_no_js.js.erb" => "<%= render(:partial => 'developer') %>", "render_rjs/basic/_customer.js.erb" => "JS Partial", "render_rjs/basic/_customer.html.erb" => "HTML Partial", + "render_rjs/basic/_developer.html.erb" => "HTML Partial", "render_rjs/basic/index_locale.js.rjs" => "page[:customer].replace_html :partial => 'customer'", "render_rjs/basic/_customer.da.html.erb" => "Danish HTML Partial", "render_rjs/basic/_customer.da.js.erb" => "Danish JS Partial" @@ -16,6 +18,12 @@ module RenderRjs render end + def index_respond_to + respond_to do |format| + format.js { render :action => "index_no_js" } + end + end + def index_locale self.locale = :da end @@ -37,6 +45,16 @@ module RenderRjs assert_response("$(\"customer\").update(\"JS Partial\");") end + test "rendering a partial in an RJS template should pick the HTML one if no JS is available" do + get :index_no_js, "format" => "js" + assert_response("HTML Partial") + end + + test "rendering a partial in an RJS template should pick the HTML one if no JS is available on respond_to" do + get :index_respond_to, "format" => "js" + assert_response("HTML Partial") + end + test "replacing an element with a partial in an RJS template should pick the HTML template over the JS one" do get :index_html, "format" => "js" assert_response("$(\"customer\").update(\"HTML Partial\");") diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 20fcb87da6..2f3997518f 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -18,6 +18,13 @@ class TestController < ActionController::Base layout :determine_layout + def name + nil + end + + private :name + helper_method :name + def hello_world end @@ -418,7 +425,6 @@ class TestController < ActionController::Base def rendering_with_conflicting_local_vars @name = "David" - def @template.name() nil end render :action => "potential_conflicts" end @@ -507,10 +513,6 @@ class TestController < ActionController::Base end end - def partial_only_with_layout - render :partial => "partial_only", :layout => true - end - def render_to_string_with_partial @partial_only = render_to_string :partial => "partial_only" @partial_with_locals = render_to_string :partial => "customer", :locals => { :customer => Customer.new("david") } @@ -526,11 +528,11 @@ class TestController < ActionController::Base end def partial_with_form_builder - render :partial => ActionView::Helpers::FormBuilder.new(:post, nil, @template, {}, Proc.new {}) + render :partial => ActionView::Helpers::FormBuilder.new(:post, nil, view_context, {}, Proc.new {}) end def partial_with_form_builder_subclass - render :partial => LabellingFormBuilder.new(:post, nil, @template, {}, Proc.new {}) + render :partial => LabellingFormBuilder.new(:post, nil, view_context, {}, Proc.new {}) end def partial_collection @@ -634,8 +636,7 @@ class TestController < ActionController::Base "rendering_nothing_on_layout", "render_text_hello_world", "render_text_hello_world_with_layout", "hello_world_with_layout_false", - "partial_only", "partial_only_with_layout", - "accessing_params_in_template", + "partial_only", "accessing_params_in_template", "accessing_params_in_template_with_layout", "render_with_explicit_template", "render_with_explicit_string_template", @@ -1198,11 +1199,6 @@ class RenderTest < ActionController::TestCase assert_equal 'partial html', @response.body end - def test_partial_only_with_layout - get :partial_only_with_layout - assert_equal "<html>only partial</html>", @response.body - end - def test_render_to_string_partial get :render_to_string_with_partial assert_equal "only partial", assigns(:partial_only) |