1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/test/disk_controller_test.rb
David Heinemeier Hansson c624df326a ActiveVault -> ActiveStorage
Yaroslav agreed to hand over the gem name ❤️
2017-07-06 11:33:29 +02:00

34 lines
1.2 KiB
Ruby

require "test_helper"
require "database/setup"
require "action_controller"
require "action_controller/test_case"
require "active_storage/disk_controller"
require "active_storage/verified_key_with_expiration"
class ActiveStorage::DiskControllerTest < ActionController::TestCase
Routes = ActionDispatch::Routing::RouteSet.new.tap do |routes|
routes.draw do
get "/rails/blobs/:encoded_key" => "active_storage/disk#show", as: :rails_disk_blob
end
end
setup do
@blob = create_blob
@routes = Routes
@controller = ActiveStorage::DiskController.new
end
test "showing blob inline" do
get :show, params: { encoded_key: ActiveStorage::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: ActiveStorage::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