Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/active_storage/service/db_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def delete(key)
def delete_prefixed(prefix)
instrument :delete_prefixed, prefix: prefix do
comment = "DBService#delete_prefixed"
sanitized_prefix = "#{ApplicationRecord.sanitize_sql_like(prefix)}%"
sanitized_prefix = "#{ActiveRecord::Base.sanitize_sql_like(prefix)}%"
::ActiveStorageDB::File.annotate(comment).where("ref LIKE ?", sanitized_prefix).destroy_all
end
end
Expand Down Expand Up @@ -165,8 +165,9 @@ def retrieve_file(key)

def object_for(key, fields: nil)
comment = "DBService#object_for"
as_file = fields ? ::ActiveStorageDB::File.annotate(comment).select(*fields) : ::ActiveStorageDB::File
as_file.find_by(ref: key)
scope = ::ActiveStorageDB::File.annotate(comment)
scope = scope.select(*fields) if fields
scope.find_by(ref: key)
end

def stream(key)
Expand Down
4 changes: 3 additions & 1 deletion spec/requests/file_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def unprocessable
let(:invalid_file) { create(:active_storage_db_file, data: "Some other data") }

before do
allow(ActiveStorageDB::File).to receive(:find_by).and_return(invalid_file)
annotated_scope = ActiveStorageDB::File.annotate("DBService#object_for")
allow(ActiveStorageDB::File).to receive(:annotate).and_return(annotated_scope)
allow(annotated_scope).to receive(:find_by).and_return(invalid_file)
end

it "fails to upload" do
Expand Down
Loading