From ad46884af567d6f8d6d8d777f372c39e81a560ba Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 19 Feb 2012 19:31:35 -0700 Subject: [PATCH] Integration tests support the OPTIONS http method --- actionpack/CHANGELOG.md | 2 ++ .../lib/action_dispatch/testing/integration.rb | 8 +++++++- actionpack/test/controller/integration_test.rb | 18 +++++++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index ec53efa6b7..cf662500a4 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,7 @@ ## Rails 4.0.0 (unreleased) ## +* Integration tests support the `OPTIONS` method. *Jeremy Kemper* + * `expires_in` accepts a `must_revalidate` flag. If true, "must-revalidate" is added to the Cache-Control header. *fxn* diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 08b7ff49c2..0287e7728b 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -56,6 +56,12 @@ def head(path, parameters = nil, headers = nil) process :head, path, parameters, headers end + # Performs a OPTIONS request with the given parameters. See +#get+ for + # more details. + def options(path, parameters = nil, headers = nil) + process :options, path, parameters, headers + end + # Performs an XMLHttpRequest request with the given parameters, mirroring # a request from the Prototype library. # @@ -312,7 +318,7 @@ def reset! @integration_session = Integration::Session.new(app) end - %w(get post put head delete cookies assigns + %w(get post put head delete options cookies assigns xml_http_request xhr get_via_redirect post_via_redirect).each do |method| define_method(method) do |*args| reset! unless integration_session diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 99e1dc7966..64c4682015 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -105,6 +105,12 @@ def test_head @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( @@ -155,6 +161,16 @@ def test_xml_http_request_head @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( @@ -212,7 +228,7 @@ def test_integration_methods_called @integration_session.stubs(:generic_url_rewriter) @integration_session.stubs(:process) - %w( get post head put delete ).each do |verb| + %w( get post head put delete options ).each do |verb| assert_nothing_raised("'#{verb}' should use integration test methods") { __send__(verb, '/') } end end -- GitLab