test/task_test.rb in paperdragon-0.0.6 vs test/task_test.rb in paperdragon-0.0.7
- old
+ new
@@ -35,16 +35,41 @@
describe "#process!" do
it do
subject.process!(:original)
subject.process!(:thumb) { |j| j.thumb!("16x16") }
- subject.metadata_hash.must_equal({:original=>{:width=>216, :height=>63, :uid=>"original-apotomo.png"}, :thumb=>{:width=>16, :height=>5, :uid=>"thumb-apotomo.png"}})
+ original_metadata = subject.metadata_hash
+ original_metadata.must_equal({:original=>{:width=>216, :height=>63, :uid=>"original-apotomo.png"}, :thumb=>{:width=>16, :height=>5, :uid=>"thumb-apotomo.png"}})
+ # processed files must exist.
+ exists?(original_metadata[:original][:uid]).must_equal true
+ exists?(original_metadata[:thumb][:uid]).must_equal true
+
+ # calling #process! again, with existing metadata, means OVERWRITING the existing image.
+ task = Attachment.new(subject.metadata_hash).task(Pathname("test/fixtures/trb.png"))
+ task.process!(:thumb) { |j| j.thumb!("48x48") }
+
+ overwritten_metadata = task.metadata_hash
+ overwritten_metadata.must_equal({:original=>{:width=>216, :height=>63, :uid=>"original-apotomo.png"}, :thumb=>{:width=>48, :height=>48, :uid=>"thumb-trb.png"}})
+ # original must still exist.
+ exists?(overwritten_metadata[:original][:uid]).must_equal true
+ # old thumb must be deleted.
+ exists?(original_metadata[:thumb][:uid]).must_equal false
+ # new thumb must be existing
+ exists?(overwritten_metadata[:thumb][:uid]).must_equal true
end
it do
assert_raises Paperdragon::MissingUploadError do
Attachment.new(nil).task.process!(:original)
end
+ end
+
+ it do
+ # after uploading "new", only delete when uid was in metadata.
+ existing_metadata = {processing: true}
+ metadata = Attachment.new(existing_metadata).task(logo).process!(:thumb)
+ metadata.must_equal({:processing=>true, :thumb=>{:width=>216, :height=>63, :uid=>"thumb-apotomo.png"}})
+ exists?("thumb-apotomo.png").must_equal true
end
end
describe "#reprocess!" do