From ca0275d36b395631725c4583db5a45c06443fdb9 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Tue, 7 May 2013 08:37:20 -0400 Subject: Test that #fresh_when accepts an array https://github.com/rails/etagger/pull/3 --- actionpack/test/controller/render_test.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 0e5bad7482..72411ec900 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -32,6 +32,10 @@ class TestControllerWithExtraEtags < ActionController::Base def fresh render text: "stale" if stale?(etag: '123') end + + def array + render text: "stale" if stale?(etag: %w(1 2 3)) + end end class TestController < ActionController::Base @@ -1649,7 +1653,6 @@ class LastModifiedRenderTest < ActionController::TestCase assert_equal @last_modified, @response.headers['Last-Modified'] end - def test_request_with_bang_gets_last_modified get :conditional_hello_with_bangs assert_equal @last_modified, @response.headers['Last-Modified'] @@ -1678,7 +1681,7 @@ class EtagRenderTest < ActionController::TestCase end def test_multiple_etags - @request.if_none_match = %("#{Digest::MD5.hexdigest(ActiveSupport::Cache.expand_cache_key([ "123", 'ab', :cde, [:f] ]))}") + @request.if_none_match = etag(["123", 'ab', :cde, [:f]]) get :fresh assert_response :not_modified @@ -1686,6 +1689,20 @@ class EtagRenderTest < ActionController::TestCase get :fresh assert_response :success end + + def test_array + @request.if_none_match = etag([%w(1 2 3), 'ab', :cde, [:f]]) + get :array + assert_response :not_modified + + @request.if_none_match = %("nomatch") + get :array + assert_response :success + end + + def etag(record) + Digest::MD5.hexdigest(ActiveSupport::Cache.expand_cache_key(record)).inspect + end end -- cgit v1.2.3 From 5e03239d59db7b21ceda576ce52b7fab3ad58c2d Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 8 May 2013 21:28:27 -0700 Subject: Fix that JSON and XML exception responses should give the HTTP error message for their status, by default, not the message from the underlying exception --- actionpack/test/controller/show_exceptions_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/show_exceptions_test.rb b/actionpack/test/controller/show_exceptions_test.rb index 69bf4b7720..ff23b22040 100644 --- a/actionpack/test/controller/show_exceptions_test.rb +++ b/actionpack/test/controller/show_exceptions_test.rb @@ -75,7 +75,7 @@ module ShowExceptions get "/", {}, 'HTTP_ACCEPT' => 'application/json' assert_response :internal_server_error assert_equal 'application/json', response.content_type.to_s - assert_equal({ :status => '500', :error => 'boom!' }.to_json, response.body) + assert_equal({ :status => '500', :error => 'Internal Server Error' }.to_json, response.body) end def test_render_xml_exception @@ -83,7 +83,7 @@ module ShowExceptions get "/", {}, 'HTTP_ACCEPT' => 'application/xml' assert_response :internal_server_error assert_equal 'application/xml', response.content_type.to_s - assert_equal({ :status => '500', :error => 'boom!' }.to_xml, response.body) + assert_equal({ :status => '500', :error => 'Internal Server Error' }.to_xml, response.body) end def test_render_fallback_exception -- cgit v1.2.3 From 8da819eef5f11cc016ffa9ad747421ee50be32fa Mon Sep 17 00:00:00 2001 From: Angelo capilleri Date: Mon, 13 May 2013 10:38:34 +0200 Subject: add test for skip_before_filter with condition --- actionpack/test/controller/filters_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index 3b79161ad3..b5f22066af 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -213,6 +213,14 @@ class FilterTest < ActionController::TestCase before_filter :clean_up_tmp, :if => Proc.new { |c| false } end + class ConditionalOptionsSkipFilter < ConditionalFilterController + before_filter :ensure_login + before_filter :clean_up_tmp + + skip_before_filter :ensure_login, if: -> { false } + skip_before_filter :clean_up_tmp, if: -> { true } + end + class PrependingController < TestController prepend_before_filter :wonderful_life # skip_before_filter :fire_flash @@ -593,6 +601,11 @@ class FilterTest < ActionController::TestCase assert_equal %w( ensure_login ), assigns["ran_filter"] end + def test_running_conditional_skip_options + test_process(ConditionalOptionsSkipFilter) + assert_equal %w( ensure_login ), assigns["ran_filter"] + end + def test_running_collection_condition_filters test_process(ConditionalCollectionFilterController) assert_equal %w( ensure_login ), assigns["ran_filter"] -- cgit v1.2.3 From 8ece52f731d3ae9dfc52033e3652b8f011632877 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 14 May 2013 14:11:03 -0700 Subject: use public api for testing rather than grabbing instance variables --- actionpack/test/controller/filters_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index 3b79161ad3..e74bc2bb3d 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -10,7 +10,7 @@ class ActionController::Base def before_filters filters = _process_action_callbacks.select { |c| c.kind == :before } - filters.map! { |c| c.instance_variable_get(:@raw_filter) } + filters.map! { |c| c.raw_filter } end end -- cgit v1.2.3 From 6a4ff5cc0907d7dd9d1b5d606dd045116a3434ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 16 May 2013 11:09:31 -0300 Subject: Revert "Add the options method to action_controller testcase." This reverts commit 0303c2325fab253adf5e4a0b738cb469c048f008. Conflicts: actionpack/lib/action_controller/test_case.rb REASON: It will conflict with a lot of test cases. Better to call `process` directly since this is a very uncommon HTTP method. Fixes #10638. --- actionpack/test/controller/test_case_test.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/test_case_test.rb b/actionpack/test/controller/test_case_test.rb index 38b9794b4d..7c27458f46 100644 --- a/actionpack/test/controller/test_case_test.rb +++ b/actionpack/test/controller/test_case_test.rb @@ -201,11 +201,6 @@ XML assert_raise(NoMethodError) { head :test_params, "document body", :id => 10 } end - def test_options - options :test_params - assert_equal 200, @response.status - end - def test_process_without_flash process :set_flash assert_equal '><', flash['test'] -- cgit v1.2.3 From c9d75e0814a3fa5797c58e3d98f76fa2990c5b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 16 May 2013 14:39:18 -0300 Subject: Revert "Integration tests support the OPTIONS http method" This reverts commit ad46884af567d6f8d6d8d777f372c39e81a560ba. Conflicts: actionpack/CHANGELOG.md actionpack/lib/action_dispatch/testing/integration.rb actionpack/test/controller/integration_test.rb Reason: It will conflict with a lot of test cases. Better to call `process` directly since this is a very uncommon HTTP method. Fixes #10638. --- actionpack/test/controller/integration_test.rb | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index c3bdf74d93..f7ec6d71b3 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -117,12 +117,6 @@ class SessionTest < ActiveSupport::TestCase @session.head(path,params,headers) end - def test_options - path = "/index"; params = "blah"; headers = {:location => 'blah'} - @session.expects(:process).with(:options,path,params,headers) - @session.options(path,params,headers) - end - def test_xml_http_request_get path = "/index"; params = "blah"; headers = {:location => 'blah'} headers_after_xhr = headers.merge( @@ -183,16 +177,6 @@ class SessionTest < ActiveSupport::TestCase @session.xml_http_request(:head,path,params,headers) end - def test_xml_http_request_options - path = "/index"; params = "blah"; headers = {:location => 'blah'} - headers_after_xhr = headers.merge( - "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest", - "HTTP_ACCEPT" => "text/javascript, text/html, application/xml, text/xml, */*" - ) - @session.expects(:process).with(:options,path,params,headers_after_xhr) - @session.xml_http_request(:options,path,params,headers) - end - def test_xml_http_request_override_accept path = "/index"; params = "blah"; headers = {:location => 'blah', "HTTP_ACCEPT" => "application/xml"} headers_after_xhr = headers.merge( @@ -250,7 +234,7 @@ class IntegrationTestUsesCorrectClass < ActionDispatch::IntegrationTest @integration_session.stubs(:generic_url_rewriter) @integration_session.stubs(:process) - %w( get post head patch put delete options ).each do |verb| + %w( get post head patch put delete ).each do |verb| assert_nothing_raised("'#{verb}' should use integration test methods") { __send__(verb, '/') } end end -- cgit v1.2.3