|
4 | 4 |
|
5 | 5 | RSpec.describe 'Creating a Scratch asset', type: :request do |
6 | 6 | let(:basename) { 'test_image_1' } |
| 7 | + let(:svg_filename) { 'test_svg_image.svg' } |
7 | 8 | let(:format) { 'png' } |
8 | 9 | let(:filename) { "#{basename}.#{format}" } |
9 | 10 | let(:school) { create(:school) } |
10 | 11 | let(:teacher) { create(:teacher, school:) } |
11 | 12 | let(:cookie_headers) { { 'Cookie' => "scratch_auth=#{UserProfileMock::TOKEN}" } } |
12 | 13 |
|
13 | 14 | describe 'GET #show' do |
14 | | - let(:make_request) { get '/api/scratch/assets/internalapi/asset/test_image_1.png/get/' } |
| 15 | + context 'when the asset is PNG' do |
| 16 | + before do |
| 17 | + create(:scratch_asset, :with_file, filename:, asset_path: file_fixture(filename)) |
| 18 | + end |
15 | 19 |
|
16 | | - context 'when the asset exists' do |
17 | | - let!(:scratch_asset) { create(:scratch_asset, :with_file, filename:, asset_path: file_fixture(filename)) } |
| 20 | + let(:make_request) { get '/api/scratch/assets/internalapi/asset/test_image_1.png/get/' } |
18 | 21 |
|
19 | | - it 'redirects to the asset file URL' do |
| 22 | + it 'serves the file with png content type' do |
20 | 23 | make_request |
21 | 24 |
|
22 | | - expect(response).to redirect_to(rails_storage_redirect_url(scratch_asset.file, only_path: true)) |
| 25 | + follow_redirect! while response.redirect? |
| 26 | + |
| 27 | + expect(response.media_type).to eq('image/png') |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + context 'when the asset is SVG' do |
| 32 | + before do |
| 33 | + create(:scratch_asset, :with_file, filename: svg_filename, asset_path: file_fixture(svg_filename)) |
| 34 | + end |
| 35 | + |
| 36 | + let(:make_request) { get '/api/scratch/assets/internalapi/asset/test_svg_image.svg/get/' } |
| 37 | + |
| 38 | + it 'serves the file with image/svg+xml content type' do |
| 39 | + make_request |
| 40 | + |
| 41 | + follow_redirect! while response.redirect? |
| 42 | + |
| 43 | + expect(response.media_type).to eq('image/svg+xml') |
23 | 44 | end |
24 | 45 | end |
25 | 46 | end |
|
0 commit comments