diff options
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/controller/caching_test.rb | 58 | ||||
-rw-r--r-- | actionpack/test/controller/filters_test.rb | 8 | ||||
-rw-r--r-- | actionpack/test/controller/integration_test.rb | 34 | ||||
-rw-r--r-- | actionpack/test/controller/test_case_test.rb | 46 | ||||
-rw-r--r-- | actionpack/test/dispatch/response_test.rb | 6 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing/inspector_test.rb | 8 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 17 | ||||
-rw-r--r-- | actionpack/test/fixtures/collection_cache/index.html.erb | 1 | ||||
-rw-r--r-- | actionpack/test/fixtures/customers/_commented_customer.html.erb | 4 | ||||
-rw-r--r-- | actionpack/test/fixtures/customers/_customer.html.erb | 3 |
10 files changed, 155 insertions, 30 deletions
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 4760ec1698..2d6607041d 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -1,5 +1,6 @@ require 'fileutils' require 'abstract_unit' +require 'lib/controller/fake_models' CACHE_DIR = 'test_cache' # Don't change '/../temp/' cavalierly or you might hose something you don't want hosed @@ -349,3 +350,60 @@ class ViewCacheDependencyTest < ActionController::TestCase assert_equal %w(trombone flute), HasDependenciesController.new.view_cache_dependencies end end + +class CollectionCacheController < ActionController::Base + def index + @customers = [Customer.new('david', params[:id] || 1)] + end + + def index_ordered + @customers = [Customer.new('david', 1), Customer.new('david', 2), Customer.new('david', 3)] + render 'index' + end + + def index_explicit_render + @customers = [Customer.new('david', 1)] + render partial: 'customers/customer', collection: @customers + end + + def index_with_comment + @customers = [Customer.new('david', 1)] + render partial: 'customers/commented_customer', collection: @customers, as: :customer + end +end + +class AutomaticCollectionCacheTest < ActionController::TestCase + def setup + super + @controller = CollectionCacheController.new + @controller.perform_caching = true + @controller.cache_store = ActiveSupport::Cache::MemoryStore.new + end + + def test_collection_fetches_cached_views + get :index + + ActionView::PartialRenderer.expects(:collection_with_template).never + get :index + end + + def test_preserves_order_when_reading_from_cache_plus_rendering + get :index, params: { id: 2 } + get :index_ordered + + assert_select ':root', "david, 1\n david, 2\n david, 3" + end + + def test_explicit_render_call_with_options + get :index_explicit_render + + assert_select ':root', "david, 1" + end + + def test_caching_works_with_beginning_comment + get :index_with_comment + + ActionView::PartialRenderer.expects(:collection_with_template).never + get :index_with_comment + end +end diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index 26b94f0db8..a1ce12a13e 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -1074,6 +1074,14 @@ class YieldingAroundFiltersTest < ActionController::TestCase end end + def test_deprecated_skip_filter + assert_deprecated do + Class.new(PostsController) do + skip_filter :clean_up + end + end + end + protected def test_process(controller, action = "show") @controller = controller.is_a?(Class) ? controller.new : controller diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 9ab1549e8e..438c044da2 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -397,9 +397,9 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest redirect_to action_url('get') end - def remove_default_header - response.headers.except! 'X-Frame-Options' - head :ok + def remove_header + response.headers.delete params[:header] + head :ok, 'c' => '3' end end @@ -640,25 +640,27 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest end end - def test_removed_default_headers_on_test_response_are_not_reapplied + def test_respect_removal_of_default_headers_by_a_controller_action with_test_route_set do - begin - header_to_remove = 'X-Frame-Options' - original_default_headers = ActionDispatch::Response.default_headers - ActionDispatch::Response.default_headers = { - 'X-Content-Type-Options' => 'nosniff', - header_to_remove => 'SAMEORIGIN', - } - get '/remove_default_header' - assert_includes headers, 'X-Content-Type-Options' - assert_not_includes headers, header_to_remove, "Should not contain removed default header" - ensure - ActionDispatch::Response.default_headers = original_default_headers + with_default_headers 'a' => '1', 'b' => '2' do + get '/remove_header', params: { header: 'a' } end end + + assert_not_includes @response.headers, 'a', 'Response should not include default header removed by the controller action' + assert_includes @response.headers, 'b' + assert_includes @response.headers, 'c' end private + def with_default_headers(headers) + original = ActionDispatch::Response.default_headers + ActionDispatch::Response.default_headers = headers + yield + ensure + ActionDispatch::Response.default_headers = original + end + def with_test_route_set with_routing do |set| controller = ::IntegrationProcessTest::IntegrationController.clone diff --git a/actionpack/test/controller/test_case_test.rb b/actionpack/test/controller/test_case_test.rb index ca854040b7..e348749f78 100644 --- a/actionpack/test/controller/test_case_test.rb +++ b/actionpack/test/controller/test_case_test.rb @@ -965,6 +965,52 @@ XML end end +class ResponseDefaultHeadersTest < ActionController::TestCase + class TestController < ActionController::Base + def remove_header + headers.delete params[:header] + head :ok, 'C' => '3' + end + end + + setup do + @original = ActionDispatch::Response.default_headers + @defaults = { 'A' => '1', 'B' => '2' } + ActionDispatch::Response.default_headers = @defaults + end + + teardown do + ActionDispatch::Response.default_headers = @original + end + + def setup + super + @controller = TestController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @request.env['PATH_INFO'] = nil + @routes = ActionDispatch::Routing::RouteSet.new.tap do |r| + r.draw do + get ':controller(/:action(/:id))' + end + end + end + + test "response contains default headers" do + # Response headers start out with the defaults + assert_equal @defaults, response.headers + + get :remove_header, params: { header: 'A' } + assert_response :ok + + # After a request, the response in the test case doesn't have the + # defaults merged on top again. + assert_not_includes response.headers, 'A' + assert_includes response.headers, 'B' + assert_includes response.headers, 'C' + end +end + module EngineControllerTests class Engine < ::Rails::Engine isolate_namespace EngineControllerTests diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 5fbd19acdf..f4c0b421d6 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -172,7 +172,7 @@ class ResponseTest < ActiveSupport::TestCase original = ActionDispatch::Response.default_charset begin ActionDispatch::Response.default_charset = 'utf-16' - resp = ActionDispatch::Response.new(200, { "Content-Type" => "text/xml" }) + resp = ActionDispatch::Response.new(200, { "Content-Type" => "text/xml" }, default_headers: nil) assert_equal('utf-16', resp.charset) ensure ActionDispatch::Response.default_charset = original @@ -254,6 +254,10 @@ class ResponseTest < ActiveSupport::TestCase end class ResponseIntegrationTest < ActionDispatch::IntegrationTest + def app + @app + end + test "response cache control from railsish app" do @app = lambda { |env| ActionDispatch::Response.new.tap { |resp| diff --git a/actionpack/test/dispatch/routing/inspector_test.rb b/actionpack/test/dispatch/routing/inspector_test.rb index 3d3d4b74ae..3df022c64b 100644 --- a/actionpack/test/dispatch/routing/inspector_test.rb +++ b/actionpack/test/dispatch/routing/inspector_test.rb @@ -26,14 +26,6 @@ module ActionDispatch inspector.format(ActionDispatch::Routing::ConsoleFormatter.new, options[:filter]).split("\n") end - def test_json_regexp_converter - @set.draw do - get '/cart', :to => 'cart#show' - end - route = ActionDispatch::Routing::RouteWrapper.new(@set.routes.first) - assert_equal "^\\/cart(?:\\.([^\\/.?]+))?$", route.json_regexp - end - def test_displaying_routes_for_engines engine = Class.new(Rails::Engine) do def self.inspect diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index deb289bd57..b4502c19d6 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -3489,13 +3489,20 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_head_fetch_with_mount_on_root draw do get '/home' => 'test#index' - mount lambda { |env| [404, {"Content-Type" => "text/html"}, ["testing"]] }, at: '/' + mount lambda { |env| [200, {}, [env['REQUEST_METHOD']]] }, at: '/' end - head '/home' - assert_response :success - head '/' - assert_response :not_found + # TODO: HEAD request should match `get /home` rather than the + # lower-precedence Rack app mounted at `/`. + head '/home' + assert_response :ok + #assert_equal 'test#index', @response.body + assert_equal 'HEAD', @response.body + + # But the Rack app can still respond to its own HEAD requests. + head '/foobar' + assert_response :ok + assert_equal 'HEAD', @response.body end private diff --git a/actionpack/test/fixtures/collection_cache/index.html.erb b/actionpack/test/fixtures/collection_cache/index.html.erb new file mode 100644 index 0000000000..521b1450df --- /dev/null +++ b/actionpack/test/fixtures/collection_cache/index.html.erb @@ -0,0 +1 @@ +<%= render @customers %>
\ No newline at end of file diff --git a/actionpack/test/fixtures/customers/_commented_customer.html.erb b/actionpack/test/fixtures/customers/_commented_customer.html.erb new file mode 100644 index 0000000000..d5f6e3b491 --- /dev/null +++ b/actionpack/test/fixtures/customers/_commented_customer.html.erb @@ -0,0 +1,4 @@ +<%# I'm a comment %> +<% cache customer do %> + <%= customer.name %>, <%= customer.id %> +<% end %>
\ No newline at end of file diff --git a/actionpack/test/fixtures/customers/_customer.html.erb b/actionpack/test/fixtures/customers/_customer.html.erb new file mode 100644 index 0000000000..67e9f6d411 --- /dev/null +++ b/actionpack/test/fixtures/customers/_customer.html.erb @@ -0,0 +1,3 @@ +<% cache customer do %> + <%= customer.name %>, <%= customer.id %> +<% end %>
\ No newline at end of file |