aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/controller')
-rwxr-xr-xactionpack/test/controller/cgi_test.rb9
-rw-r--r--actionpack/test/controller/raw_post_test.rb67
2 files changed, 61 insertions, 15 deletions
diff --git a/actionpack/test/controller/cgi_test.rb b/actionpack/test/controller/cgi_test.rb
index 06f721997d..0415a1384c 100755
--- a/actionpack/test/controller/cgi_test.rb
+++ b/actionpack/test/controller/cgi_test.rb
@@ -235,6 +235,7 @@ class CGITest < Test::Unit::TestCase
end
end
+
class MultipartCGITest < Test::Unit::TestCase
FIXTURE_PATH = File.dirname(__FILE__) + '/../fixtures/multipart'
@@ -315,6 +316,14 @@ class MultipartCGITest < Test::Unit::TestCase
end
end
+# Ensures that PUT works with multipart as well as POST.
+class PutMultipartCGITest < MultipartCGITest
+ def setup
+ super
+ ENV['REQUEST_METHOD'] = 'PUT'
+ end
+end
+
class CGIRequestTest < Test::Unit::TestCase
def setup
diff --git a/actionpack/test/controller/raw_post_test.rb b/actionpack/test/controller/raw_post_test.rb
index 98dc7f6ba7..b6895bc3cc 100644
--- a/actionpack/test/controller/raw_post_test.rb
+++ b/actionpack/test/controller/raw_post_test.rb
@@ -5,27 +5,64 @@ require File.dirname(__FILE__) + '/../../lib/action_controller/cgi_ext/raw_post_
class RawPostDataTest < Test::Unit::TestCase
def setup
+ ENV.delete('RAW_POST_DATA')
+ @request_body = 'a=1'
+ end
+
+ def test_post_with_urlencoded_body
+ ENV['REQUEST_METHOD'] = 'POST'
+ ENV['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
+ assert_equal ['1'], cgi_params['a']
+ assert_has_raw_post_data
+ end
+
+ def test_post_with_empty_content_type_treated_as_urlencoded
ENV['REQUEST_METHOD'] = 'POST'
ENV['CONTENT_TYPE'] = ''
- ENV['CONTENT_LENGTH'] = '0'
+ assert_equal ['1'], cgi_params['a']
+ assert_has_raw_post_data
+ end
+
+ def test_post_with_unrecognized_content_type_reads_body_but_doesnt_parse_params
+ ENV['REQUEST_METHOD'] = 'POST'
+ ENV['CONTENT_TYPE'] = 'foo/bar'
+ assert cgi_params.empty?
+ assert_has_raw_post_data
end
- def test_raw_post_data
- process_raw "action=create_customer&full_name=David%20Heinemeier%20Hansson&customerId=1"
+ def test_put_with_urlencoded_body
+ ENV['REQUEST_METHOD'] = 'PUT'
+ ENV['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
+ assert_equal ['1'], cgi_params['a']
+ assert_has_raw_post_data
+ end
+
+ def test_put_with_empty_content_type_ignores_body
+ ENV['REQUEST_METHOD'] = 'PUT'
+ ENV['CONTENT_TYPE'] = ''
+ assert cgi_params.empty?
+ assert_has_raw_post_data
+ end
+
+ def test_put_with_unrecognized_content_type_ignores_body
+ ENV['REQUEST_METHOD'] = 'PUT'
+ ENV['CONTENT_TYPE'] = 'foo/bar'
+ assert cgi_params.empty?
+ assert_has_raw_post_data
end
private
- def process_raw(query_string)
- old_stdin = $stdin
- begin
- $stdin = StringIO.new(query_string.dup)
- ENV['CONTENT_LENGTH'] = $stdin.size.to_s
- CGI.new
- assert_not_nil ENV['RAW_POST_DATA']
- assert ENV['RAW_POST_DATA'].frozen?
- assert_equal query_string, ENV['RAW_POST_DATA']
- ensure
- $stdin = old_stdin
- end
+ def cgi_params
+ old_stdin, $stdin = $stdin, StringIO.new(@request_body.dup)
+ ENV['CONTENT_LENGTH'] = $stdin.size.to_s
+ CGI.new.params
+ ensure
+ $stdin = old_stdin
+ end
+
+ def assert_has_raw_post_data(expected_body = @request_body)
+ assert_not_nil ENV['RAW_POST_DATA']
+ assert ENV['RAW_POST_DATA'].frozen?
+ assert_equal expected_body, ENV['RAW_POST_DATA']
end
end