Commit 1d5aca06

mo khan <mo@mokhan.ca>
2014-05-31 15:29:23
marks the photo when processing is complete.
1 parent ca077fb
Changed files (3)
app
services
spec
services
application
app/services/application/handlers/process_photo.rb
@@ -10,6 +10,7 @@ class ProcessPhoto
   def handle(message)
     photo = @photos.find(message[:photo_id])
     photo.image = File.open(message[:file_path])
+    photo.image_processing = false
     #photo.content_type = message[:content_type]
     #photo.original_filename = message[:original_filename]
     photo.save!
app/services/application/upload_photo.rb
@@ -5,12 +5,11 @@ class UploadPhoto
   end
 
   def run(cake_id, params)
-    file_path = params[:image].tempfile.path
-    photo = Creation.find(cake_id).photos.create!(image_tmp: file_path, image_processing: true)
+    photo = Creation.find(cake_id).photos.create!(image_processing: true)
     message = {
       cake_id: cake_id,
       photo_id: photo.id,
-      file_path: file_path,
+      file_path: params[:image].tempfile.path,
       original_filename: params[:image].original_filename,
       content_type: params[:image].content_type,
       headers: params[:image].headers
spec/services/application/handlers/process_photo_spec.rb
@@ -12,13 +12,10 @@ describe ProcessPhoto do
 
   describe "#handle" do
     let(:image_path) { File.join(Rails.root, 'spec/fixtures/images/example.png') }
-    let(:photo) { Photo.new(id: rand(100)) }
+    let(:photo) { Photo.new(id: rand(100), image_processing: true) }
 
     before :each do
       photos.stub(:find).with(photo.id).and_return(photo)
-    end
-
-    it "saves the uploaded image" do
       message = {
         photo_id: photo.id,
         file_path: image_path,
@@ -26,8 +23,16 @@ describe ProcessPhoto do
         original_filename: 'blah.jpg'
       }
       subject.handle(message)
+    end
+
+
+    it "saves the uploaded image" do
       photo.image.should_not be_nil
     end
+
+    it "indicates that the photo has been processed." do
+      photo.image_processing.should be_false
+    end
   end
 end