Commit b39f1114

mo khan <mo@mokhan.ca>
2014-06-01 20:35:39
create parser to parse out exif information.
1 parent affc992
Changed files (2)
app
services
application
spec
services
application
app/services/application/handlers/process_photo.rb
@@ -1,6 +1,7 @@
 class ProcessPhoto
-  def initialize(photos = Photo)
+  def initialize(photos = Photo, exif_parser)
     @photos = photos
+    @exif_parser = exif_parser
   end
 
   def handles?(event)
@@ -14,7 +15,7 @@ class ProcessPhoto
     photo.image_processing = false
     photo.content_type = message[:content_type]
     photo.original_filename = message[:original_filename]
-    photo.latitude, photo.longitude = parse_exif_from(file)
+    photo.latitude, photo.longitude = @exif_parser.parse_geolocation_from(file)
     photo.save!
   end
 
spec/services/application/handlers/process_photo_spec.rb
@@ -2,7 +2,8 @@ require "spec_helper"
 
 describe ProcessPhoto do
   let(:photos) { double }
-  subject { ProcessPhoto.new(photos) }
+  let(:exif_parser) { double }
+  subject { ProcessPhoto.new(photos, exif_parser) }
 
   describe "#handles?" do
     it "handles photo uploads" do
@@ -13,9 +14,12 @@ describe ProcessPhoto do
   describe "#handle" do
     let(:image_path) { File.join(Rails.root, 'spec/fixtures/images/gps.jpg') }
     let(:photo) { Photo.new(id: rand(100), image_processing: true) }
+    let(:latitude)  { rand(100) }
+    let(:longitude)  { rand(100) }
 
     before :each do
       photos.stub(:find).with(photo.id).and_return(photo)
+      exif_parser.stub(:parse_geolocation_from).and_return([latitude, longitude])
       message = {
         photo_id: photo.id,
         file_path: image_path,
@@ -42,12 +46,8 @@ describe ProcessPhoto do
     end
 
     it "applies the geolocation information" do
-      photo.latitude.should == 51.07296369444445
-      photo.longitude.should == -114.101799
-    end
-
-    xit "ignore geolocation for files that dont have geolocation info" do
-      
+      photo.latitude.should == latitude
+      photo.longitude.should == longitude
     end
   end
 end