test/unit/test_roachclip.rb in roachclip-0.1.1 vs test/unit/test_roachclip.rb in roachclip-0.1.2
- old
+ new
@@ -41,10 +41,30 @@
setup do
@opts = {:styles => {:thumb => {:geometry => '50x50'}, :large => {:geometry => '500x500>'}}}
Doc.roachclip :image, @opts
end
+ context "with validations" do
+ setup do
+ Doc.validates_roachclip :image
+ end
+
+ context "on a new instance" do
+ setup do
+ @doc = Doc.new
+ end
+
+ should "validate presence of images" do
+ assert !@doc.valid?
+ assert @doc.errors.on(:image)
+
+ @doc.image = File.open(test_file_path)
+ assert @doc.valid?
+ end
+ end
+ end
+
should "add attachments for each option style" do
d = Doc.new
assert d.respond_to?(:image_thumb)
assert d.respond_to?(:image_thumb=)
@@ -52,29 +72,27 @@
assert d.respond_to?(:image_large=)
end
context "with a saved document w/ image" do
setup do
- @fname = 'fonz.jpg'
- @test_file_path = File.join(File.dirname(__FILE__), '..', 'data', @fname)
@doc = Doc.new
- @doc.image = File.open(@test_file_path)
+ @doc.image = File.open(test_file_path)
assert @doc.save
end
should "still save documents w/ images" do
d = Doc.find @doc.id
- assert_equal @fname, d.image_name
- assert_equal File.size(@test_file_path), d.image_size
+ assert_equal fname, d.image_name
+ assert_equal File.size(test_file_path), d.image_size
end
should "destroy thumbs when image set to nil" do
@doc.image = nil
@doc.save!
-
+
d = Doc.find(@doc.id)
# until joint supports clearing IDs
assert_raises(Mongo::GridFileNotFound) { d.image_thumb.read }
assert_raises(Mongo::GridFileNotFound) { d.image_large.read }
end
@@ -86,7 +104,15 @@
assert_equal 'fonz_thumb.jpg', @doc.image_thumb_name
assert_equal 'fonz_large.jpg', @doc.image_large_name
end
end
end
+ end
+
+ def fname
+ 'fonz.jpg'
+ end
+
+ def test_file_path
+ @test_file_path = File.join(File.dirname(__FILE__), '..', 'data', fname)
end
end