Sha256: 42800ebd64bfb19e7c0b03c3152c390470c72bd255b275f54629b95c9cb5e912
Contents?: true
Size: 1.96 KB
Versions: 1
Compression:
Stored size: 1.96 KB
Contents
require './test/helper' class DataUriAdapterTest < Test::Unit::TestCase def teardown if @subject @subject.close end end context "a new instance" do setup do @contents = "data:image/png;base64,#{original_base64_content}" @subject = Paperclip.io_adapters.for(@contents) end should "returns a file name based on the content type" do assert_equal "data.png", @subject.original_filename end should "return a content type" do assert_equal "image/png", @subject.content_type end should "return the size of the data" do assert_equal 4456, @subject.size end should "generate a correct MD5 hash of the contents" do assert_equal( Digest::MD5.hexdigest(Base64.decode64(original_base64_content)), @subject.fingerprint ) end should "generate correct fingerprint after read" do fingerprint = Digest::MD5.hexdigest(@subject.read) assert_equal fingerprint, @subject.fingerprint end should "generate same fingerprint" do assert_equal @subject.fingerprint, @subject.fingerprint end should 'accept a content_type' do @subject.content_type = 'image/png' assert_equal 'image/png', @subject.content_type end should 'accept an original_filename' do @subject.original_filename = 'image.png' assert_equal 'image.png', @subject.original_filename end should "not generate filenames that include restricted characters" do @subject.original_filename = 'image:restricted.png' assert_equal 'image_restricted.png', @subject.original_filename end should "not generate paths that include restricted characters" do @subject.original_filename = 'image:restricted.png' assert_no_match /:/, @subject.path end end def original_base64_content Base64.encode64(original_file_contents) end def original_file_contents @original_file_contents ||= File.read(fixture_file('5k.png')) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
paperclip-4.0.0 | test/io_adapters/data_uri_adapter_test.rb |