aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/dispatch')
-rw-r--r--actionpack/test/dispatch/request/multipart_params_parsing_test.rb7
-rw-r--r--actionpack/test/dispatch/response_test.rb11
-rw-r--r--actionpack/test/dispatch/session/cookie_store_test.rb12
-rw-r--r--actionpack/test/dispatch/show_exceptions_test.rb14
-rw-r--r--actionpack/test/dispatch/static_test.rb47
-rw-r--r--actionpack/test/dispatch/uploaded_file_test.rb58
6 files changed, 88 insertions, 61 deletions
diff --git a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb
index 073dd3ddad..3ff558ec5a 100644
--- a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb
+++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb
@@ -36,7 +36,6 @@ class MultipartParamsParsingTest < ActionDispatch::IntegrationTest
assert_equal 'bar', params['foo']
file = params['file']
- assert_kind_of Tempfile, file
assert_equal 'file.txt', file.original_filename
assert_equal "text/plain", file.content_type
assert_equal 'contents', file.read
@@ -49,8 +48,6 @@ class MultipartParamsParsingTest < ActionDispatch::IntegrationTest
file = params['file']
foo = params['foo']
- assert_kind_of Tempfile, file
-
assert_equal 'file.txt', file.original_filename
assert_equal "text/plain", file.content_type
@@ -64,8 +61,6 @@ class MultipartParamsParsingTest < ActionDispatch::IntegrationTest
file = params['file']
- assert_kind_of Tempfile, file
-
assert_equal 'file.txt', file.original_filename
assert_equal "text/plain", file.content_type
assert_equal(('a' * 20480), file.read)
@@ -77,13 +72,11 @@ class MultipartParamsParsingTest < ActionDispatch::IntegrationTest
assert_equal 'bar', params['foo']
file = params['file']
- assert_kind_of Tempfile, file
assert_equal 'file.csv', file.original_filename
assert_nil file.content_type
assert_equal 'contents', file.read
file = params['flowers']
- assert_kind_of Tempfile, file
assert_equal 'flowers.jpg', file.original_filename
assert_equal "image/jpeg", file.content_type
assert_equal 19512, file.size
diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb
index cd0418c338..be6398fead 100644
--- a/actionpack/test/dispatch/response_test.rb
+++ b/actionpack/test/dispatch/response_test.rb
@@ -11,9 +11,7 @@ class ResponseTest < ActiveSupport::TestCase
status, headers, body = @response.to_a
assert_equal 200, status
assert_equal({
- "Content-Type" => "text/html; charset=utf-8",
- "Cache-Control" => "max-age=0, private, must-revalidate",
- "ETag" => '"65a8e27d8879283831b664bd8b7f0ad4"'
+ "Content-Type" => "text/html; charset=utf-8"
}, headers)
parts = []
@@ -27,9 +25,7 @@ class ResponseTest < ActiveSupport::TestCase
status, headers, body = @response.to_a
assert_equal 200, status
assert_equal({
- "Content-Type" => "text/html; charset=utf-8",
- "Cache-Control" => "max-age=0, private, must-revalidate",
- "ETag" => '"ebb5e89e8a94e9dd22abf5d915d112b2"'
+ "Content-Type" => "text/html; charset=utf-8"
}, headers)
end
@@ -41,8 +37,7 @@ class ResponseTest < ActiveSupport::TestCase
status, headers, body = @response.to_a
assert_equal 200, status
assert_equal({
- "Content-Type" => "text/html; charset=utf-8",
- "Cache-Control" => "no-cache"
+ "Content-Type" => "text/html; charset=utf-8"
}, headers)
parts = []
diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb
index 3489f628ed..256d0781c7 100644
--- a/actionpack/test/dispatch/session/cookie_store_test.rb
+++ b/actionpack/test/dispatch/session/cookie_store_test.rb
@@ -53,18 +53,6 @@ class CookieStoreTest < ActionDispatch::IntegrationTest
def rescue_action(e) raise end
end
- def test_raises_argument_error_if_missing_session_key
- assert_raise(ArgumentError, nil.inspect) {
- ActionDispatch::Session::CookieStore.new(nil,
- :key => nil, :secret => SessionSecret)
- }
-
- assert_raise(ArgumentError, ''.inspect) {
- ActionDispatch::Session::CookieStore.new(nil,
- :key => '', :secret => SessionSecret)
- }
- end
-
def test_setting_session_value
with_test_route_set do
get '/set_session_value'
diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb
index 4ede1ab47c..ce6c397e32 100644
--- a/actionpack/test/dispatch/show_exceptions_test.rb
+++ b/actionpack/test/dispatch/show_exceptions_test.rb
@@ -1,19 +1,5 @@
require 'abstract_unit'
-module ActionDispatch
- class ShowExceptions
- private
- def public_path
- "#{FIXTURE_LOAD_PATH}/public"
- end
-
- # Silence logger
- def logger
- nil
- end
- end
-end
-
class ShowExceptionsTest < ActionDispatch::IntegrationTest
Boomer = lambda do |env|
req = ActionDispatch::Request.new(env)
diff --git a/actionpack/test/dispatch/static_test.rb b/actionpack/test/dispatch/static_test.rb
index 2eb82fc5d8..655745a848 100644
--- a/actionpack/test/dispatch/static_test.rb
+++ b/actionpack/test/dispatch/static_test.rb
@@ -2,30 +2,37 @@ require 'abstract_unit'
module StaticTests
def test_serves_dynamic_content
- assert_equal "Hello, World!", get("/nofile")
+ assert_equal "Hello, World!", get("/nofile").body
end
def test_serves_static_index_at_root
- assert_equal "/index.html", get("/index.html")
- assert_equal "/index.html", get("/index")
- assert_equal "/index.html", get("/")
+ assert_html "/index.html", get("/index.html")
+ assert_html "/index.html", get("/index")
+ assert_html "/index.html", get("/")
+ assert_html "/index.html", get("")
end
def test_serves_static_file_in_directory
- assert_equal "/foo/bar.html", get("/foo/bar.html")
- assert_equal "/foo/bar.html", get("/foo/bar/")
- assert_equal "/foo/bar.html", get("/foo/bar")
+ assert_html "/foo/bar.html", get("/foo/bar.html")
+ assert_html "/foo/bar.html", get("/foo/bar/")
+ assert_html "/foo/bar.html", get("/foo/bar")
end
def test_serves_static_index_file_in_directory
- assert_equal "/foo/index.html", get("/foo/index.html")
- assert_equal "/foo/index.html", get("/foo/")
- assert_equal "/foo/index.html", get("/foo")
+ assert_html "/foo/index.html", get("/foo/index.html")
+ assert_html "/foo/index.html", get("/foo/")
+ assert_html "/foo/index.html", get("/foo")
end
private
+
+ def assert_html(body, response)
+ assert_equal body, response.body
+ assert_equal "text/html", response.headers["Content-Type"]
+ end
+
def get(path)
- Rack::MockRequest.new(@app).request("GET", path).body
+ Rack::MockRequest.new(@app).request("GET", path)
end
end
@@ -59,16 +66,16 @@ class MultipleDirectorisStaticTest < ActiveSupport::TestCase
include StaticTests
test "serves files from other mounted directories" do
- assert_equal "/blog/index.html", get("/blog/index.html")
- assert_equal "/blog/index.html", get("/blog/index")
- assert_equal "/blog/index.html", get("/blog/")
+ assert_html "/blog/index.html", get("/blog/index.html")
+ assert_html "/blog/index.html", get("/blog/index")
+ assert_html "/blog/index.html", get("/blog/")
- assert_equal "/blog/blog.html", get("/blog/blog/")
- assert_equal "/blog/blog.html", get("/blog/blog.html")
- assert_equal "/blog/blog.html", get("/blog/blog")
+ assert_html "/blog/blog.html", get("/blog/blog/")
+ assert_html "/blog/blog.html", get("/blog/blog.html")
+ assert_html "/blog/blog.html", get("/blog/blog")
- assert_equal "/blog/subdir/index.html", get("/blog/subdir/index.html")
- assert_equal "/blog/subdir/index.html", get("/blog/subdir/")
- assert_equal "/blog/subdir/index.html", get("/blog/subdir")
+ assert_html "/blog/subdir/index.html", get("/blog/subdir/index.html")
+ assert_html "/blog/subdir/index.html", get("/blog/subdir/")
+ assert_html "/blog/subdir/index.html", get("/blog/subdir")
end
end
diff --git a/actionpack/test/dispatch/uploaded_file_test.rb b/actionpack/test/dispatch/uploaded_file_test.rb
new file mode 100644
index 0000000000..b51697b930
--- /dev/null
+++ b/actionpack/test/dispatch/uploaded_file_test.rb
@@ -0,0 +1,58 @@
+require 'abstract_unit'
+
+module ActionDispatch
+ class UploadedFileTest < ActiveSupport::TestCase
+ def test_constructor_with_argument_error
+ assert_raises(ArgumentError) do
+ Http::UploadedFile.new({})
+ end
+ end
+
+ def test_original_filename
+ uf = Http::UploadedFile.new(:filename => 'foo', :tempfile => Object.new)
+ assert_equal 'foo', uf.original_filename
+ end
+
+ def test_content_type
+ uf = Http::UploadedFile.new(:type => 'foo', :tempfile => Object.new)
+ assert_equal 'foo', uf.content_type
+ end
+
+ def test_headers
+ uf = Http::UploadedFile.new(:head => 'foo', :tempfile => Object.new)
+ assert_equal 'foo', uf.headers
+ end
+
+ def test_tempfile
+ uf = Http::UploadedFile.new(:tempfile => 'foo')
+ assert_equal 'foo', uf.tempfile
+ end
+
+ def test_delegates_to_tempfile
+ tf = Class.new { def read; 'thunderhorse' end }
+ uf = Http::UploadedFile.new(:tempfile => tf.new)
+ assert_equal 'thunderhorse', uf.read
+ end
+
+ def test_delegates_to_tempfile_with_params
+ tf = Class.new { def read *args; args end }
+ uf = Http::UploadedFile.new(:tempfile => tf.new)
+ assert_equal %w{ thunder horse }, uf.read(*%w{ thunder horse })
+ end
+
+ def test_delegate_respects_respond_to?
+ tf = Class.new { def read; yield end; private :read }
+ uf = Http::UploadedFile.new(:tempfile => tf.new)
+ assert_raises(NoMethodError) do
+ uf.read
+ end
+ end
+
+ def test_respond_to?
+ tf = Class.new { def read; yield end }
+ uf = Http::UploadedFile.new(:tempfile => tf.new)
+ assert uf.respond_to?(:headers), 'responds to headers'
+ assert uf.respond_to?(:read), 'responds to read'
+ end
+ end
+end