diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-04 18:11:06 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-04 18:11:06 +0200 |
commit | 4712e2361199c0becc216d392d3d84666bad076b (patch) | |
tree | 0d2547043a571050cbc975c3bdf5007e06a4502e /test | |
parent | 09878fb19d46674605fb6e48c1b86e2915ad7496 (diff) | |
download | rails-4712e2361199c0becc216d392d3d84666bad076b.tar.gz rails-4712e2361199c0becc216d392d3d84666bad076b.tar.bz2 rails-4712e2361199c0becc216d392d3d84666bad076b.zip |
Fix up DiskController and add basic testing
Diffstat (limited to 'test')
-rw-r--r-- | test/disk_controller_test.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/disk_controller_test.rb b/test/disk_controller_test.rb new file mode 100644 index 0000000000..ee172b23f7 --- /dev/null +++ b/test/disk_controller_test.rb @@ -0,0 +1,34 @@ +require "test_helper" +require "database/setup" + +require "action_controller" +require "action_controller/test_case" + +require "active_file/disk_controller" +require "active_file/verified_key_with_expiration" + +class ActiveFile::DiskControllerTest < ActionController::TestCase + Routes = ActionDispatch::Routing::RouteSet.new.tap do |routes| + routes.draw do + get "/rails/blobs/:encoded_key" => "active_file/disk#show", as: :rails_disk_blob + end + end + + setup do + @blob = create_blob + @routes = Routes + @controller = ActiveFile::DiskController.new + end + + test "showing blob inline" do + get :show, params: { encoded_key: ActiveFile::VerifiedKeyWithExpiration.encode(@blob.key, expires_in: 5.minutes) } + assert_equal "inline; filename=\"#{@blob.filename}\"", @response.headers["Content-Disposition"] + assert_equal "text/plain", @response.headers["Content-Type"] + end + + test "sending blob as attachment" do + get :show, params: { encoded_key: ActiveFile::VerifiedKeyWithExpiration.encode(@blob.key, expires_in: 5.minutes), disposition: :attachment } + assert_equal "attachment; filename=\"#{@blob.filename}\"", @response.headers["Content-Disposition"] + assert_equal "text/plain", @response.headers["Content-Type"] + end +end |