Skip to content

Commit

Permalink
added default thumbo_uri and corresponded test. TODO: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
godfat committed Nov 22, 2008
1 parent 683c557 commit 791816b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/thumbo.rb
Expand Up @@ -53,11 +53,15 @@ def thumbos
@thumbos ||= init_thumbos
end

# same as thumbnail.filename, for writing
def thumbo_filename thumbo
"#{object_id}_#{thumbo.title}.#{thumbo.fileext}"
end

def thumbo_uri thumbo
paths = thumbo.paths
paths[rand(paths.size)]
end

def thumbo_mime_type
thumbos[:original].mime_type
end
Expand Down
30 changes: 30 additions & 0 deletions test/test_storage.rb
@@ -1,5 +1,6 @@

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

class Photo
include Thumbo
Expand Down Expand Up @@ -30,6 +31,22 @@ def thumbo_default_fileext

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 < MiniTest::Unit::TestCase
def test_uri
p = Photo.new
Expand All @@ -40,6 +57,19 @@ def test_uri
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
Expand Down

0 comments on commit 791816b

Please sign in to comment.