Skip to content

Commit 3051529

Browse files
committed
chore: Address Rubocop offenses
1 parent 2c55477 commit 3051529

5 files changed

Lines changed: 51 additions & 47 deletions

File tree

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ RSpec/NestedGroups:
4545
# Default is 3
4646
Max: 5
4747

48+
RSpec/Output:
49+
Exclude:
50+
- spec/dummy/bin/*
51+
4852
Style/ClassAndModuleChildren:
4953
Exclude:
5054
- 'lib/active_storage/service/db_service.rb'

lib/active_storage/service/db_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def stream(key)
173173
data_size = adapter_sqlserver? ? "DATALENGTH(data)" : "OCTET_LENGTH(data)"
174174
size = object_for(key, fields: "#{data_size} AS size")&.size || raise(ActiveStorage::FileNotFoundError)
175175
(size / @chunk_size.to_f).ceil.times.each do |i|
176-
range = (i * @chunk_size..((i + 1) * @chunk_size) - 1)
176+
range = (i * @chunk_size)..(((i + 1) * @chunk_size) - 1)
177177
yield download_chunk(key, range)
178178
end
179179
end

spec/dummy/app/controllers/posts_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def create
2828

2929
respond_to do |format|
3030
if @post.save
31-
format.html { redirect_to @post, notice: 'Post was successfully created.' }
31+
format.html { redirect_to @post, notice: "Post was successfully created." }
3232
format.json { render :show, status: :created, location: @post }
3333
else
3434
format.html { render :new }
@@ -42,7 +42,7 @@ def create
4242
def update
4343
respond_to do |format|
4444
if @post.update(post_params)
45-
format.html { redirect_to @post, notice: 'Post was successfully updated.' }
45+
format.html { redirect_to @post, notice: "Post was successfully updated." }
4646
format.json { render :show, status: :ok, location: @post }
4747
else
4848
format.html { render :edit }
@@ -56,7 +56,7 @@ def update
5656
def destroy
5757
@post.destroy
5858
respond_to do |format|
59-
format.html { redirect_to posts_url, notice: 'Post was successfully destroyed.' }
59+
format.html { redirect_to posts_url, notice: "Post was successfully destroyed." }
6060
format.json { head :no_content }
6161
end
6262
end

spec/dummy/app/models/application_record.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
class ApplicationRecord < ActiveRecord::Base
4-
if Gem::Version.new(Rails.version) >= Gem::Version.new('7.0')
4+
if Rails::VERSION::MAJOR >= 7
55
primary_abstract_class
66
else
77
self.abstract_class = true

spec/requests/file_controller_spec.rb

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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

Comments
 (0)