aboutsummaryrefslogblamecommitdiffstats
path: root/test/blob_test.rb
blob: c7b4aeed39f40be7f6f00d488229f486c039c5b1 (plain) (tree)
1
2
3
4
5
6
7
8
                     
                        
                           
 
                                                     

                                                           
                                 



                                                           
     
 
                                      
                      

                         

                                                                                                       
       


         
                                                    
                                                                                                                                 
       
   
require "test_helper"
require "database/setup"
require "active_vault/blob"

class ActiveVault::BlobTest < ActiveSupport::TestCase
  test "create after upload sets byte size and checksum" do
    data = "Hello world!"
    blob = create_blob data: data

    assert_equal data, blob.download
    assert_equal data.length, blob.byte_size
    assert_equal Digest::MD5.hexdigest(data), blob.checksum
  end

  test "urls expiring in 5 minutes" do
    blob = create_blob

    travel_to Time.now do
      assert_equal expected_url_for(blob), blob.url
      assert_equal expected_url_for(blob, disposition: :attachment), blob.url(disposition: :attachment)
    end
  end

  private
    def expected_url_for(blob, disposition: :inline)
      "/rails/blobs/#{ActiveVault::VerifiedKeyWithExpiration.encode(blob.key, expires_in: 5.minutes)}?disposition=#{disposition}"
    end
end