Sha256: 219dec95a3487b6098226301b14a0a0c0789ed3e3fef6685df209be85be1f905

Contents?: true

Size: 1.57 KB

Versions: 8

Compression:

Stored size: 1.57 KB

Contents

require 'test_helper'

require 'paperdragon/paperclip'

class PaperclipUidTest < MiniTest::Spec
  Uid = Paperdragon::Paperclip::Uid

  let (:options) { {:class_name => :avatars, :attachment => :image, :id => 1234,
    :style => :original, :updated_at => Time.parse("20-06-2014 9:40:59").to_i,
    :file_name => "kristylee.jpg", :hash_secret => "secret"} }

  it { Uid.from(options).
    must_equal "system/avatars/image/000/001/234/9bf15e5874b3234c133f7500e6d615747f709e64/original/kristylee.jpg" }


  class UidWithFingerprint < Paperdragon::Paperclip::Uid
    def call
      "#{root}/#{class_name}/#{attachment}/#{id_partition}/#{hash}/#{style}/#{fingerprint}-#{file_name}"
    end
  end

  it { UidWithFingerprint.from(options.merge(:fingerprint => 8675309)).
    must_equal "system/avatars/image/000/001/234/9bf15e5874b3234c133f7500e6d615747f709e64/original/8675309-kristylee.jpg" }
end


class PaperclipModelTest < MiniTest::Spec
  class Avatar
    class Photo < Paperdragon::File
    end

    class Attachment < Paperdragon::Attachment
      self.file_class = Photo

      def exists?
        "Of course!"
      end
    end

    include Paperdragon::Paperclip::Model
    processable :image, Attachment


    def image_meta_data
      {:thumb => {:uid => "Avatar-thumb"}}
    end
  end

  # old paperclip style
  it { Avatar.new.image.url(:thumb).must_equal "/paperdragon/Avatar-thumb" }

  # paperdragon style
  it { Avatar.new.image[:thumb].url.must_equal "/paperdragon/Avatar-thumb" }

  # delegates all unknown methods back to Attachment.
  it { Avatar.new.image.exists?.must_equal "Of course!" }
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
paperdragon-0.0.9 test/paperclip_uid_test.rb
paperdragon-0.0.8 test/paperclip_uid_test.rb
paperdragon-0.0.7 test/paperclip_uid_test.rb
paperdragon-0.0.6 test/paperclip_uid_test.rb
paperdragon-0.0.5 test/paperclip_uid_test.rb
paperdragon-0.0.4 test/paperclip_uid_test.rb
paperdragon-0.0.3 test/paperclip_uid_test.rb
paperdragon-0.0.2 test/paperclip_uid_test.rb