Module: FileBlobs::ActiveSupportTestFixtures
- Defined in:
- lib/file_blobs_rails/active_support_test_extensions.rb
Overview
Module mixed into ActiveRecord::FixtureSet.
Instance Method Summary collapse
-
#file_blob_data(path) ⇒ String
The contents of a blob.
-
#file_blob_id(path) ⇒ String
Computes the ID assigned to a blob.
-
#file_blob_size(path) ⇒ String
The size of a blob.
Instance Method Details
#file_blob_data(path) ⇒ String
The contents of a blob.
14 15 16 17 |
# File 'lib/file_blobs_rails/active_support_test_extensions.rb', line 14 def file_blob_data(path) file_path = Rails.root.join('test/fixtures'.freeze).join(path) File.binread file_path end |
#file_blob_id(path) ⇒ String
Computes the ID assigned to a blob.
24 25 26 27 |
# File 'lib/file_blobs_rails/active_support_test_extensions.rb', line 24 def file_blob_id(path) # This needs to be kept in sync with blob_model.rb. Base64.urlsafe_encode64(Digest::SHA256.digest(file_blob_data(path))) end |
#file_blob_size(path) ⇒ String
The size of a blob.
34 35 36 37 |
# File 'lib/file_blobs_rails/active_support_test_extensions.rb', line 34 def file_blob_size(path) file_path = Rails.root.join('test/fixtures'.freeze).join(path) File.stat(file_path).size end |