11# frozen_string_literal: true
22
3- RSpec . describe ' File controller' do
4- def create_blob ( data : ' Hello world!' , filename : ' hello.txt' , content_type : ' text/plain' , identify : true , record : nil )
3+ RSpec . describe " File controller" do
4+ def create_blob ( data : " Hello world!" , filename : " hello.txt" , content_type : " text/plain" , identify : true , record : nil )
55 ActiveStorage ::Blob . create_and_upload! (
66 io : StringIO . new ( data ) ,
77 filename : filename ,
@@ -11,7 +11,7 @@ def create_blob(data: 'Hello world!', filename: 'hello.txt', content_type: 'text
1111 )
1212 end
1313
14- def create_blob_before_direct_upload ( byte_size :, checksum :, filename : ' hello.txt' , content_type : ' text/plain' )
14+ def create_blob_before_direct_upload ( byte_size :, checksum :, filename : " hello.txt" , content_type : " text/plain" )
1515 ActiveStorage ::Blob . create_before_direct_upload! (
1616 filename : filename ,
1717 byte_size : byte_size ,
@@ -24,12 +24,12 @@ def unprocessable
2424 Gem ::Version . new ( Rails . version ) >= Gem ::Version . new ( "7.1" ) ? :unprocessable_content : :unprocessable_entity
2525 end
2626
27- let ( :blob ) { create_blob ( filename : ' img.jpg' , content_type : ' image/jpeg' ) }
27+ let ( :blob ) { create_blob ( filename : " img.jpg" , content_type : " image/jpeg" ) }
2828 let ( :url_options ) do
2929 {
30- protocol : ' http://' ,
31- host : ' test.example.com' ,
32- port : ' 3001' ,
30+ protocol : " http://" ,
31+ host : " test.example.com" ,
32+ port : " 3001"
3333 }
3434 end
3535 let ( :host ) { "#{ url_options [ :protocol ] } #{ url_options [ :host ] } :#{ url_options [ :port ] } " }
@@ -43,120 +43,120 @@ def unprocessable
4343 end
4444 end
4545
46- it ' creates a new File entity in the DB' do
46+ it " creates a new File entity in the DB" do
4747 expect { create_blob } . to change ( ActiveStorageDB ::File , :count ) . from ( 0 ) . to ( 1 )
4848 end
4949
50- describe ' .show' do
51- it ' returns the blob as inline' do
50+ describe " .show" do
51+ it " returns the blob as inline" do
5252 blob_url = blob . respond_to? ( :url ) ? blob . url : blob . service_url
5353
5454 get blob_url
5555
5656 expect ( response ) . to have_http_status ( :ok )
57- expect ( response . content_type ) . to eq ( ' image/jpeg' )
58- content_disposition = response . headers [ ' Content-Disposition' ]
57+ expect ( response . content_type ) . to eq ( " image/jpeg" )
58+ content_disposition = response . headers [ " Content-Disposition" ]
5959 expect ( content_disposition ) . to eq ( "inline; filename=\" img.jpg\" ; filename*=UTF-8''img.jpg" )
60- expect ( response . body ) . to eq ' Hello world!'
60+ expect ( response . body ) . to eq " Hello world!"
6161 end
6262
63- it ' returns the blob as attachment' do
63+ it " returns the blob as attachment" do
6464 url = blob . respond_to? ( :url ) ? blob . url ( disposition : :attachment ) : blob . service_url ( disposition : :attachment )
6565 get url
6666
6767 expect ( response ) . to have_http_status ( :ok )
68- expect ( response . content_type ) . to eq ( ' image/jpeg' )
69- content_disposition = response . headers [ ' Content-Disposition' ]
68+ expect ( response . content_type ) . to eq ( " image/jpeg" )
69+ content_disposition = response . headers [ " Content-Disposition" ]
7070 expect ( content_disposition ) . to eq ( "attachment; filename=\" img.jpg\" ; filename*=UTF-8''img.jpg" )
71- expect ( response . body ) . to eq ' Hello world!'
71+ expect ( response . body ) . to eq " Hello world!"
7272 end
7373
74- context ' with a deleted blob' do
74+ context " with a deleted blob" do
7575 let! ( :blob ) { create_blob }
7676
7777 before { blob . delete }
7878
79- it ' returns not found' do
79+ it " returns not found" do
8080 blob_url = blob . respond_to? ( :url ) ? blob . url : blob . service_url
8181 get blob_url
8282
8383 expect ( response ) . to have_http_status ( :not_found )
8484 end
8585 end
8686
87- context ' with an invalid key' do
88- it ' returns not found' , :aggregate_failures do
87+ context " with an invalid key" do
88+ it " returns not found" , :aggregate_failures do
8989 get blob . respond_to? ( :url ) ? blob . url : blob . service_url
9090 expect ( response ) . to have_http_status ( :ok )
9191
92- invalid_key = [ blob . key , '_' ] . join
93- get engine_url_helpers . service_path ( encoded_key : invalid_key , filename : ' hello.txt' )
92+ invalid_key = [ blob . key , "_" ] . join
93+ get engine_url_helpers . service_path ( encoded_key : invalid_key , filename : " hello.txt" )
9494 expect ( response ) . to have_http_status ( :not_found )
9595 end
9696 end
9797 end
9898
99- describe ' .update' do
100- let ( :data ) { ' Something else entirely!' }
99+ describe " .update" do
100+ let ( :data ) { " Something else entirely!" }
101101 let ( :blob ) { create_blob_before_direct_upload ( byte_size : data . size , checksum : Digest ::MD5 . base64digest ( data ) ) }
102102
103- it ' uses blob direct upload with integrity' do
104- put blob . service_url_for_direct_upload , params : data , headers : { ' Content-Type' => ' text/plain' }
103+ it " uses blob direct upload with integrity" do
104+ put blob . service_url_for_direct_upload , params : data , headers : { " Content-Type" => " text/plain" }
105105
106106 expect ( response ) . to have_http_status ( :no_content )
107107 expect ( data ) . to eq blob . download
108108 end
109109
110- it ' uses blob direct upload with mismatched content type' do
111- put blob . service_url_for_direct_upload , params : data , headers : { ' Content-Type' => ' application/octet-stream' }
110+ it " uses blob direct upload with mismatched content type" do
111+ put blob . service_url_for_direct_upload , params : data , headers : { " Content-Type" => " application/octet-stream" }
112112
113113 expect ( response ) . to have_http_status ( unprocessable )
114114 expect ( blob . service ) . not_to exist ( blob . key )
115115 end
116116
117- context ' with an invalid checksum' do
117+ context " with an invalid checksum" do
118118 let ( :blob ) do
119- create_blob_before_direct_upload ( byte_size : data . size , checksum : Digest ::MD5 . base64digest ( ' bad data' ) )
119+ create_blob_before_direct_upload ( byte_size : data . size , checksum : Digest ::MD5 . base64digest ( " bad data" ) )
120120 end
121121
122- it ' fails to upload' do
122+ it " fails to upload" do
123123 put blob . service_url_for_direct_upload , params : data
124124
125125 expect ( response ) . to have_http_status ( unprocessable )
126126 expect ( blob . service ) . not_to exist ( blob . key )
127127 end
128128 end
129129
130- context ' with an invalid content length' do
130+ context " with an invalid content length" do
131131 let ( :blob ) { create_blob_before_direct_upload byte_size : data . size - 1 , checksum : Digest ::MD5 . base64digest ( data ) }
132132
133- it ' fails to upload' do
134- put blob . service_url_for_direct_upload , params : data , headers : { ' Content-Type' => ' text/plain' }
133+ it " fails to upload" do
134+ put blob . service_url_for_direct_upload , params : data , headers : { " Content-Type" => " text/plain" }
135135
136136 expect ( response ) . to have_http_status ( unprocessable )
137137 expect ( blob . service ) . not_to exist ( blob . key )
138138 end
139139 end
140140
141- context ' with an invalid token' do
142- it ' returns not found' , :aggregate_failures do
141+ context " with an invalid token" do
142+ it " returns not found" , :aggregate_failures do
143143 get blob . respond_to? ( :url ) ? blob . url : blob . service_url
144144 expect ( response ) . to have_http_status ( :not_found )
145145
146- put engine_url_helpers . update_service_path ( encoded_token : ' Invalid token' )
146+ put engine_url_helpers . update_service_path ( encoded_token : " Invalid token" )
147147 expect ( response ) . to have_http_status ( :not_found )
148148 end
149149 end
150150
151- context ' when the integrity check fails' do
152- let ( :invalid_file ) { create ( :active_storage_db_file , data : ' Some other data' ) }
151+ context " when the integrity check fails" do
152+ let ( :invalid_file ) { create ( :active_storage_db_file , data : " Some other data" ) }
153153
154154 before do
155155 allow ( ActiveStorageDB ::File ) . to receive ( :find_by ) . and_return ( invalid_file )
156156 end
157157
158- it ' fails to upload' do
159- put blob . service_url_for_direct_upload , params : data , headers : { ' Content-Type' => ' text/plain' }
158+ it " fails to upload" do
159+ put blob . service_url_for_direct_upload , params : data , headers : { " Content-Type" => " text/plain" }
160160
161161 expect ( response ) . to have_http_status ( unprocessable )
162162 end
0 commit comments