Sha256: 33753ea11c8f8c12c5279bfe58c986ac00cf35bc48c66b73d3c5266e47d50e63

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

require 'test/helper'
require 'digest/md5'

class Photo
  include Thumbo
  def self.thumbo_storage
    @thumbo_storage ||= Thumbo::Filesystem.new(:path => 'tmp', :prefix_size => 2)
  end

  def self.thumbo_common
    {:common => 200}
  end

  def self.thumbo_square
    {:square => 50}
  end

  def thumbo_filename thumbo
    "#{self.object_id}_#{thumbo.title}.#{thumbo.fileext}"
  end

  def thumbo_uri thumbo
    first, last = thumbo.filename.split('_')
    "http://img.godfat.org/photos/#{first}_zzz_#{last}"
  end

  def thumbo_default_fileext
    'png'
  end

end

class ThumboDefault
  include Thumbo

  def self.thumbo_common
    {:common => 200}
  end

  def self.thumbo_square
    {:square => 50}
  end

  def thumbo_default_fileext
    'png'
  end
end

class StorageTest < TestCase
  def test_uri
    p = Photo.new
    t = p.thumbos[:original]
    t.from_blob(File.open('test/ruby.png').read)

    assert_equal( "http://img.godfat.org/photos/#{p.object_id}_zzz_original.png",
                  p.thumbos[:original].uri )
  end

  def test_default
    p = ThumboDefault.new
    t = p.thumbos[:original]
    t.from_blob(File.open('test/ruby.png').read)
    t.write

    assert_equal( "public/images/thumbo/#{Digest::MD5.hexdigest(t.filename)[0,1]}" +
                  "/#{p.object_id}_original.png",
                  p.thumbos[:original].uri )
  ensure
    File.delete(t.uri)
  end

  def test_raises
    assert_raises(Thumbo::FileNotFound) do
      Photo.new.thumbos[:original].delete
    end
  end

  def test_write_file
    target = "public/images/thumbo/#{Digest::MD5.hexdigest('LICENSE')[0,1]}/LICENSE"
    ThumboDefault.thumbo_storage.write_file('LICENSE', File.open('LICENSE'))
    assert_equal(File.read('LICENSE'), File.read(target))
  ensure
    File.delete(target)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thumbo-0.6.0 test/test_storage.rb