module FileBlobs::ActiveSupportTestFixtures
Module mixed into ActiveRecord::FixtureSet.
Public Instance Methods
file_blob_data(path)
click to toggle source
The contents of a blob.
@param [String] path the path of the file whose contents is used in the
fixture, relative to the Rails application's test/fixtures directory
@return [String] the blob contents
# 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)
click to toggle source
Computes the ID assigned to a blob.
@param [String] path the path of the file whose contents is used in the
fixture, relative to the Rails application's test/fixtures directory
@return [String] the ID used to represent the blob contents
# 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)
click to toggle source
The size of a blob.
@param [String] path the path of the file whose contents is used in the
fixture, relative to the Rails application's test/fixtures directory
@return [String] the blob contents
# 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