test/test_joint.rb in joint-0.5.1 vs test/test_joint.rb in joint-0.5.2
- old
+ new
@@ -1,47 +1,7 @@
require 'helper'
-class Asset
- include MongoMapper::Document
- plugin Joint
-
- key :title, String
- attachment :image
- attachment :file
-end
-
-class BaseModel
- include MongoMapper::Document
- plugin Joint
- attachment :file
-end
-
-class Image < BaseModel; attachment :image end
-class Video < BaseModel; attachment :video end
-
-module JointTestHelpers
- def all_files
- [@file, @image, @image2, @test1, @test2]
- end
-
- def rewind_files
- all_files.each { |file| file.rewind }
- end
-
- def open_file(name)
- File.open(File.join(File.dirname(__FILE__), 'fixtures', name), 'r')
- end
-
- def grid
- @grid ||= Mongo::Grid.new(MongoMapper.database)
- end
-
- def key_names
- [:id, :name, :type, :size]
- end
-end
-
class JointTest < Test::Unit::TestCase
include JointTestHelpers
def setup
super
@@ -54,10 +14,49 @@
def teardown
all_files.each { |file| file.close }
end
+ context ".name" do
+ should "return original_filename" do
+ def @image.original_filename
+ 'frank.jpg'
+ end
+ Joint.name(@image).should == 'frank.jpg'
+ end
+
+ should "fall back to File.basename" do
+ Joint.name(@image).should == 'mr_t.jpg'
+ end
+ end
+
+ context ".size" do
+ should "return size" do
+ def @image.size
+ 25
+ end
+ Joint.size(@image).should == 25
+ end
+
+ should "fall back to File.size" do
+ Joint.size(@image).should == 13661
+ end
+ end
+
+ context ".type" do
+ should "return type" do
+ def @image.content_type
+ 'plain/text'
+ end
+ Joint.type(@image).should == 'plain/text'
+ end
+
+ should "fall back to Wand" do
+ Joint.type(@image).should == 'image/jpeg'
+ end
+ end
+
context "Using Joint plugin" do
should "add each attachment to attachment_names" do
Asset.attachment_names.should == Set.new([:image, :file])
end
@@ -339,8 +338,27 @@
model.file = nil
model.should_not be_valid
model.file = @image
model.should be_valid
+ end
+ end
+
+ context "Assigning joint io instance" do
+ setup do
+ io = Joint::IO.new({
+ :name => 'foo.txt',
+ :content_type => 'plain/text',
+ :content => 'This is my stuff',
+ :size => 19,
+ })
+ @asset = Asset.create(:file => io)
+ end
+
+ should "work" do
+ @asset.file_name.should == 'foo.txt'
+ @asset.file_size.should == 19
+ @asset.file_type.should == 'plain/text'
+ @asset.file.read.should == 'This is my stuff'
end
end
end
\ No newline at end of file