Skip to content

Commit 8065fbf

Browse files
authored
Merge pull request #36 from blocknotes/feat/minor-improvements
feat: minor internal improvements
2 parents 4a6e7e8 + cf69436 commit 8065fbf

11 files changed

Lines changed: 32 additions & 37 deletions

File tree

.rubocop.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ Lint/UnusedMethodArgument:
2222
AllowUnusedKeywordArguments: true
2323

2424
RSpec/DescribeClass:
25-
Exclude:
26-
- spec/tasks/active_storage_db_tasks_spec.rb
25+
Enabled: false
2726

2827
RSpec/ExampleLength:
2928
# Default is 5

active_storage_db.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
2727
spec.add_dependency 'activestorage', '>= 6.0'
2828
spec.add_dependency 'rails', '>= 6.0'
2929

30-
spec.add_development_dependency 'appraisal', '~> 2.4'
31-
spec.add_development_dependency 'factory_bot_rails', '~> 6.1'
30+
spec.add_development_dependency 'appraisal', '~> 2.4' # rubocop:disable Gemspec/DevelopmentDependencies
31+
spec.add_development_dependency 'factory_bot_rails', '~> 6.1' # rubocop:disable Gemspec/DevelopmentDependencies
3232
end

lib/tasks/active_storage_db_tasks.rake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ end
1919
namespace :asdb do
2020
desc 'ActiveStorageDB: list attachments ordered by blob id desc'
2121
task list: [:environment] do |_t, _args|
22-
query = ::ActiveStorage::Blob.order(id: :desc).limit(100)
22+
query = ActiveStorage::Blob.order(id: :desc).limit(100)
2323
digits = query.ids.inject(0) { |ret, id| size = id.to_s.size; [size, ret].max }
2424

25-
::ActiveStorage::Tasks.print_blob_header(digits: digits)
25+
ActiveStorage::Tasks.print_blob_header(digits: digits)
2626
query.each do |blob|
27-
::ActiveStorage::Tasks.print_blob(blob, digits: digits)
27+
ActiveStorage::Tasks.print_blob(blob, digits: digits)
2828
end
2929
end
3030

@@ -34,7 +34,7 @@ namespace :asdb do
3434
destination = args[:destination]&.strip || Dir.pwd
3535
abort('Required arguments: source blob id, destination path') if blob_id.blank? || destination.blank?
3636

37-
blob = ::ActiveStorage::Blob.find_by(id: blob_id)
37+
blob = ActiveStorage::Blob.find_by(id: blob_id)
3838
abort('Source file not found') unless blob
3939

4040
destination = "#{destination}/#{blob.filename}" if Dir.exist?(destination)
@@ -50,12 +50,12 @@ namespace :asdb do
5050
filename = args[:filename]&.strip
5151
abort('Required arguments: filename') if filename.blank?
5252

53-
blobs = ::ActiveStorage::Blob.where('filename LIKE ?', "%#{filename}%").order(id: :desc)
53+
blobs = ActiveStorage::Blob.where('filename LIKE ?', "%#{filename}%").order(id: :desc)
5454
if blobs.any?
5555
digits = blobs.ids.inject(0) { |ret, id| size = id.to_s.size; [size, ret].max }
56-
::ActiveStorage::Tasks.print_blob_header(digits: digits)
56+
ActiveStorage::Tasks.print_blob_header(digits: digits)
5757
blobs.each do |blob|
58-
::ActiveStorage::Tasks.print_blob(blob, digits: digits)
58+
ActiveStorage::Tasks.print_blob(blob, digits: digits)
5959
end
6060
else
6161
puts 'No results'
File renamed without changes.
File renamed without changes.

spec/models/active_storage_db/file_spec.rb

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

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

66
context 'when creating a file with an already existing key' do

spec/rails_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
add_filter %r{^/spec/}
2121
add_filter %r{^/vendor/}
2222

23-
case ENV['RAILS']
23+
case ENV.fetch('RAILS', nil)
2424
when '6.0' then add_filter /_rails61|_rails70/
2525
when '6.1' then add_filter /_rails60|_rails70/
2626
when '7.0' then add_filter /_rails60|_rails61/
@@ -49,7 +49,7 @@
4949

5050
RSpec.configure do |config|
5151
config.filter_rails_from_backtrace!
52-
config.fixture_path = "#{::Rails.root}/spec/fixtures"
52+
config.fixture_path = "#{Rails.root}/spec/fixtures"
5353
config.infer_spec_type_from_file_location!
5454
config.use_transactional_fixtures = true
5555

spec/requests/file_controller_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
RSpec.describe 'File controller', type: :request do
3+
RSpec.describe 'File controller' do
44
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),
@@ -29,7 +29,7 @@ def create_blob_before_direct_upload(byte_size:, checksum:, filename: 'hello.txt
2929
}
3030
end
3131
let(:host) { "#{url_options[:protocol]}#{url_options[:host]}:#{url_options[:port]}" }
32-
let(:engine_url_helpers) { ::ActiveStorageDB::Engine.routes.url_helpers }
32+
let(:engine_url_helpers) { ActiveStorageDB::Engine.routes.url_helpers }
3333

3434
before do
3535
if ActiveStorage::Current.respond_to? :url_options
@@ -142,7 +142,7 @@ def create_blob_before_direct_upload(byte_size:, checksum:, filename: 'hello.txt
142142
let(:invalid_file) { create(:active_storage_db_file, data: 'Some other data') }
143143

144144
before do
145-
allow(::ActiveStorageDB::File).to receive(:find_by).and_return(invalid_file)
145+
allow(ActiveStorageDB::File).to receive(:find_by).and_return(invalid_file)
146146
end
147147

148148
it 'fails to upload' do

spec/requests/file_url_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# frozen_string_literal: true
22

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

77
it 'has the service URL in the engine URL helpers' do
88
expect(app_url_helpers).to respond_to :active_storage_db_path

spec/service/active_storage/service/db_service_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@
5252
describe '.compose' do
5353
subject(:compose) { service.compose(%w[key1 key2 key3], 'dest_key') }
5454

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

5959
it 'composes the source files' do
60-
expect { compose }.to change { ::ActiveStorageDB::File.where(ref: 'dest_key').count }.by(1)
61-
expect(compose).to be_kind_of ::ActiveStorageDB::File
62-
expect(compose.data).to eq [db_file1.data, db_file2.data, db_file3.data].join
60+
expect { compose }.to change { ActiveStorageDB::File.where(ref: 'dest_key').count }.by(1)
61+
expect(compose).to be_a ActiveStorageDB::File
62+
expect(compose.data).to eq [first_db_file.data, second_db_file.data, third_db_file.data].join
6363
end
6464
end
6565
end
@@ -70,7 +70,7 @@
7070
before { upload }
7171

7272
it 'deletes the file' do
73-
expect { delete }.to change { ActiveStorageDB::File.count }.from(1).to(0)
73+
expect { delete }.to change(ActiveStorageDB::File, :count).from(1).to(0)
7474
end
7575
end
7676

@@ -80,7 +80,7 @@
8080
before { upload }
8181

8282
it 'deletes the files' do
83-
expect { delete_prefixed }.to change { ActiveStorageDB::File.count }.from(1).to(0)
83+
expect { delete_prefixed }.to change(ActiveStorageDB::File, :count).from(1).to(0)
8484
end
8585
end
8686

@@ -154,7 +154,7 @@
154154

155155
describe '.upload' do
156156
it 'uploads the data' do
157-
expect(upload).to be_kind_of ActiveStorageDB::File
157+
expect(upload).to be_a ActiveStorageDB::File
158158
ensure
159159
service.delete(key)
160160
end
@@ -163,7 +163,7 @@
163163
let(:upload) { service.upload(key, StringIO.new(fixture_data), checksum: checksum) }
164164

165165
it 'uploads the data' do
166-
expect(upload).to be_kind_of ActiveStorageDB::File
166+
expect(upload).to be_a ActiveStorageDB::File
167167
ensure
168168
service.delete(key)
169169
end

0 commit comments

Comments
 (0)