Module: AttachmentHelpers
- Defined in:
- lib/decidim/dev/test/rspec_support/attachment_helpers.rb
Overview
A collection of methods to help dealing with attachments.
Instance Method Summary collapse
-
#attachment_file_size(attachment) ⇒ Object
Gives the file size in an human readable form.
-
#upload_test_file(file, options = {}) ⇒ Object
Creates ActiveStorage::Blob object and returns its signed_id Used in non-system tests that need files.
Instance Method Details
#attachment_file_size(attachment) ⇒ Object
Gives the file size in an human readable form
It is intended to be used to avoid the implementation details, so that the attachment file size presentation can change more easily.
9 10 11 |
# File 'lib/decidim/dev/test/rspec_support/attachment_helpers.rb', line 9 def () ActiveSupport::NumberHelper.number_to_human_size(.file_size) end |
#upload_test_file(file, options = {}) ⇒ Object
Creates ActiveStorage::Blob object and returns its signed_id Used in non-system tests that need files.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/decidim/dev/test/rspec_support/attachment_helpers.rb', line 15 def upload_test_file(file, = {}) filename = [:filename] || upload_test_file_filename(file) content_type = [:content_type] || upload_test_file_content_type(file) blob = ActiveStorage::Blob.create_and_upload!( io: File.open(file), filename:, content_type: ) return blob if [:return_blob] blob.signed_id end |