summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2014-06-06 21:20:11 -0600
committermo khan <mo@mokhan.ca>2014-06-06 21:20:11 -0600
commitd481e4bac147388e5148d388310f32acdfd994c1 (patch)
treee074d09a3075eba4dfb4de371dd482cdbced817f
parent77b8d5c0d211939b28bc62d4c757b0bc9ed79527 (diff)
add specs for uploading a photo.
-rw-r--r--app/models/photo.rb1
-rw-r--r--app/services/application/handlers/process_photo.rb3
-rw-r--r--spec/fixtures/images/gps.jpgbin2250506 -> 38864 bytes
-rw-r--r--spec/models/photo_spec.rb22
4 files changed, 24 insertions, 2 deletions
diff --git a/app/models/photo.rb b/app/models/photo.rb
index f841f6dc..201513b4 100644
--- a/app/models/photo.rb
+++ b/app/models/photo.rb
@@ -16,6 +16,7 @@ class Photo < ActiveRecord::Base
end
def upload(file, blob_storage)
+ self.original_filename = File.basename(file)
image = Image.new(file)
versions.each do |version|
version.adjust(image)
diff --git a/app/services/application/handlers/process_photo.rb b/app/services/application/handlers/process_photo.rb
index 9f6915cf..52beb945 100644
--- a/app/services/application/handlers/process_photo.rb
+++ b/app/services/application/handlers/process_photo.rb
@@ -10,13 +10,12 @@ class ProcessPhoto
end
def handle(message)
- file = File.open(message[:file_path])
photo = @photos.find(message[:photo_id])
#photo.image = file
photo.image_processing = nil
photo.content_type = message[:content_type]
photo.original_filename = message[:original_filename]
- photo.latitude, photo.longitude = @exif_parser.parse_geolocation_from(file)
+ photo.latitude, photo.longitude = @exif_parser.parse_geolocation_from(message[:file_path])
photo.upload(message[:file_path], @blob_storage)
photo.save!
end
diff --git a/spec/fixtures/images/gps.jpg b/spec/fixtures/images/gps.jpg
index e4484de0..4cf254d5 100644
--- a/spec/fixtures/images/gps.jpg
+++ b/spec/fixtures/images/gps.jpg
Binary files differ
diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb
new file mode 100644
index 00000000..7e963a58
--- /dev/null
+++ b/spec/models/photo_spec.rb
@@ -0,0 +1,22 @@
+require "spec_helper"
+
+describe Photo do
+ subject { Photo.new }
+
+ describe "#upload" do
+ let(:file) { File.join(Rails.root, 'spec/fixtures/images/gps.jpg') }
+ let(:blob_storage) { double(upload: true) }
+
+ it "uploads each version to the blob storage" do
+ subject.id = rand(100)
+ subject.upload(file, blob_storage)
+ blob_storage.should have_received(:upload).with(upload_key, file)
+ blob_storage.should have_received(:upload).with(upload_key("large"), file)
+ blob_storage.should have_received(:upload).with(upload_key("thumb"), file)
+ end
+
+ def upload_key(prefix = '')
+ "uploads/photo/image/#{subject.id}/#{prefix}_gps.jpg"
+ end
+ end
+end