Skip to content

Commit

Permalink
feat: correct RuboCop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
blocknotes committed Nov 1, 2023
1 parent 25a6aa3 commit 694976d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 19 deletions.
3 changes: 1 addition & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ Lint/UnusedMethodArgument:
AllowUnusedKeywordArguments: true

RSpec/DescribeClass:
Exclude:
- spec/tasks/active_storage_db_tasks_spec.rb
Enabled: false

RSpec/ExampleLength:
# Default is 5
Expand Down
2 changes: 1 addition & 1 deletion spec/models/active_storage_db/file_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe ActiveStorageDB::File, type: :model do
RSpec.describe ActiveStorageDB::File do
let(:file) { create(:active_storage_db_file, ref: 'just_some_key') }

context 'when creating a file with an already existing key' do
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/file_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe 'File controller', type: :request do
RSpec.describe 'File controller' do
def create_blob(data: 'Hello world!', filename: 'hello.txt', content_type: 'text/plain', identify: true, record: nil)
ActiveStorage::Blob.create_and_upload!(
io: StringIO.new(data),
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/file_url_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe 'File URL', type: :request do
RSpec.describe 'File URL' do
let(:app_url_helpers) { Rails.application.routes.url_helpers }
let(:engine_url_helpers) { ActiveStorageDB::Engine.routes.url_helpers }

Expand Down
12 changes: 6 additions & 6 deletions spec/service/active_storage/service/db_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@
describe '.compose' do
subject(:compose) { service.compose(%w[key1 key2 key3], 'dest_key') }

let!(:db_file1) { create(:active_storage_db_file, ref: 'key1', data: 'first file') }
let!(:db_file2) { create(:active_storage_db_file, ref: 'key2', data: 'second file') }
let!(:db_file3) { create(:active_storage_db_file, ref: 'key3', data: 'third file') }
let!(:first_db_file) { create(:active_storage_db_file, ref: 'key1', data: 'first file') }
let!(:second_db_file) { create(:active_storage_db_file, ref: 'key2', data: 'second file') }
let!(:third_db_file) { create(:active_storage_db_file, ref: 'key3', data: 'third file') }

it 'composes the source files' do
expect { compose }.to change { ActiveStorageDB::File.where(ref: 'dest_key').count }.by(1)
expect(compose).to be_a ActiveStorageDB::File
expect(compose.data).to eq [db_file1.data, db_file2.data, db_file3.data].join
expect(compose.data).to eq [first_db_file.data, second_db_file.data, third_db_file.data].join
end
end
end
Expand All @@ -70,7 +70,7 @@
before { upload }

it 'deletes the file' do
expect { delete }.to change { ActiveStorageDB::File.count }.from(1).to(0)
expect { delete }.to change(ActiveStorageDB::File, :count).from(1).to(0)
end
end

Expand All @@ -80,7 +80,7 @@
before { upload }

it 'deletes the files' do
expect { delete_prefixed }.to change { ActiveStorageDB::File.count }.from(1).to(0)
expect { delete_prefixed }.to change(ActiveStorageDB::File, :count).from(1).to(0)
end
end

Expand Down
12 changes: 4 additions & 8 deletions spec/tasks/active_storage_db_tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@
describe 'asdb:list' do
subject(:task) { execute_task('asdb:list') }

let(:file1) { create(:active_storage_blob, filename: 'some file 1', created_at: Time.now - 1.hour) }
let(:file2) { create(:active_storage_blob, filename: 'some file 2', created_at: Time.now - 5.hour) }
let(:file3) { create(:active_storage_blob, filename: 'some file 3', created_at: Time.now - 3.hour) }

before do
[file1, file2, file3]
end
let!(:first_file) { create(:active_storage_blob, filename: 'some file 1', created_at: Time.now - 1.hour) }
let!(:second_file) { create(:active_storage_blob, filename: 'some file 2', created_at: Time.now - 5.hour) }
let!(:third_file) { create(:active_storage_blob, filename: 'some file 3', created_at: Time.now - 3.hour) }

it 'prints the columns header + the list of 3 files', :aggregate_failures do
pattern = /#{file3.id} #{file3.filename}.+#{file2.id} #{file2.filename}.+#{file1.id} #{file1.filename}/m
pattern = /#{third_file.id} #{third_file.filename}.+#{second_file.id} #{second_file.filename}.+#{first_file.id} #{first_file.filename}/m
expect(task).to match pattern
expect(task.split("\n").size).to be 4
end
Expand Down

0 comments on commit 694976d

Please sign in to comment.