|
@@ -5,9 +5,9 @@ require 'rails_helper'
|
|
|
RSpec.describe ApplicationController::HasDownload::DownloadFile do
|
|
|
subject(:download_file) { described_class.new(stored_file.id, disposition: 'inline') }
|
|
|
|
|
|
- let(:file_content_type) { 'application/pdf' }
|
|
|
+ let(:file_content_type) { 'image/jpeg' }
|
|
|
let(:file_data) { 'A example file.' }
|
|
|
- let(:file_name) { 'example.pdf' }
|
|
|
+ let(:file_name) { 'example.jpg' }
|
|
|
|
|
|
let(:stored_file) do
|
|
|
create(:store,
|
|
@@ -22,7 +22,13 @@ RSpec.describe ApplicationController::HasDownload::DownloadFile do
|
|
|
end
|
|
|
|
|
|
describe '#disposition' do
|
|
|
- context "with given object dispostion 'inline'" do
|
|
|
+ shared_examples 'forcing disposition to attachment' do
|
|
|
+ it 'forces disposition to attachment' do
|
|
|
+ expect(download_file.disposition).to eq('attachment')
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ context "with given object disposition 'inline'" do
|
|
|
context 'with allowed inline content type (from ActiveStorage.content_types_allowed_inline)' do
|
|
|
it 'disposition is inline' do
|
|
|
expect(download_file.disposition).to eq('inline')
|
|
@@ -32,25 +38,27 @@ RSpec.describe ApplicationController::HasDownload::DownloadFile do
|
|
|
context 'with binary content type (ActiveStorage.content_types_to_serve_as_binary)' do
|
|
|
let(:file_content_type) { 'image/svg+xml' }
|
|
|
|
|
|
- it 'disposition forced to attachment' do
|
|
|
- expect(download_file.disposition).to eq('attachment')
|
|
|
- end
|
|
|
+ it_behaves_like 'forcing disposition to attachment'
|
|
|
+ end
|
|
|
+
|
|
|
+ context 'with PDF content type (#4479)' do
|
|
|
+ let(:file_content_type) { 'application/pdf' }
|
|
|
+
|
|
|
+ it_behaves_like 'forcing disposition to attachment'
|
|
|
end
|
|
|
end
|
|
|
|
|
|
context "with given object dispostion 'attachment'" do
|
|
|
subject(:download_file) { described_class.new(stored_file.id, disposition: 'attachment') }
|
|
|
|
|
|
- it 'disposition is attachment' do
|
|
|
- expect(download_file.disposition).to eq('attachment')
|
|
|
- end
|
|
|
+ it_behaves_like 'forcing disposition to attachment'
|
|
|
end
|
|
|
end
|
|
|
|
|
|
describe '#content_type' do
|
|
|
context 'with none binary content type' do
|
|
|
it 'check content type' do
|
|
|
- expect(download_file.content_type).to eq('application/pdf')
|
|
|
+ expect(download_file.content_type).to eq('image/jpeg')
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -72,8 +80,8 @@ RSpec.describe ApplicationController::HasDownload::DownloadFile do
|
|
|
|
|
|
context 'with image content type' do
|
|
|
let(:file_content_type) { 'image/jpg' }
|
|
|
- let(:file_data) { Rails.root.join('test/data/upload/upload2.jpg').binread }
|
|
|
- let(:file_name) { 'image.jpg' }
|
|
|
+ let(:file_data) { Rails.root.join('test/data/upload/upload2.jpg').binread }
|
|
|
+ let(:file_name) { 'image.jpg' }
|
|
|
|
|
|
it 'check that inline content will be returned' do
|
|
|
expect(download_file.content('inline')).to not_eq(file_data)
|