Commit 9c9c442d
Changed files (6)
app
models
services
application
infrastructure
spec
controllers
models
services
infrastructure
app/models/photo.rb
@@ -42,7 +42,7 @@ class Photo < ActiveRecord::Base
@photo = photo
end
- def adjust(image)
+ def adjust(image)
fail "Please override with version specific behaviours"
end
@@ -51,7 +51,11 @@ class Photo < ActiveRecord::Base
end
def url_for(asset_host)
- "#{asset_host}/#{create_key}"
+ if photo.is_processed?
+ "#{asset_host}/#{create_key}"
+ else
+ ActionController::Base.helpers.asset_path("#{key}_default.png")
+ end
end
def create_key
app/services/application/photo_to_jq_json_mapper.rb
@@ -1,10 +1,9 @@
class PhotoToJQJsonMapper
def map_from(photo)
{
- name: photo.read_attribute(:image),
- #url: photo.image.url,
+ name: photo.image,
url: photo.url_for(:large),
- thumbnail_url: photo.is_processed? ? photo.image.thumb.url : photo.image.thumb.default_url,
+ thumbnail_url: photo.url_for(:thumb),
delete_url: photo.id,
delete_type: "DELETE"
}
app/services/infrastructure/blob_storage.rb
@@ -6,6 +6,7 @@ class BlobStorage
end
def upload(key, file)
+ raise "heck"
puts "uploading to #{bucket_name}/#{key}"
object = connection.buckets[bucket_name].objects[key]
object.write(Pathname.new(file), content_type: content_type_for(file), cache_control: 'public, max-age=315576000')
spec/controllers/my/photos_controller_spec.rb
@@ -48,9 +48,8 @@ module My
it "should respond with the proper json" do
response.body.should ==
- {
- :files => [
- {
+ {
+ :files => [{
:name => "example.png",
:url => "/uploads/photo/image/#{photo.id}/example.png",
:thumbnail_url => "/uploads/photo/image/#{photo.id}/thumb_example.png",
spec/models/photo_spec.rb
@@ -56,5 +56,29 @@ describe Photo do
it "returns the url for the original version" do
expect(subject.url_for(:original)).to eql("#{asset_host}/uploads/photo/image/#{subject.id}/blah.png")
end
+
+ context "when the image is still being processed" do
+ let(:large_processing_image_url) { path_to("large_default.png") }
+ let(:thumb_processing_image_url) { path_to("thumb_default.png") }
+ let(:original_processing_image_url) { path_to("original_default.png") }
+
+ before { subject.image_processing=true }
+
+ it "returns the path to the original processing image" do
+ expect(subject.url_for(:original)).to eql(original_processing_image_url)
+ end
+
+ it "returns the path to a large processing image" do
+ expect(subject.url_for(:large)).to eql(large_processing_image_url)
+ end
+
+ it "returns the path to a thumb processing image" do
+ expect(subject.url_for(:thumb)).to eql(thumb_processing_image_url)
+ end
+
+ def path_to(image_filename)
+ ActionController::Base.helpers.asset_path(image_filename)
+ end
+ end
end
end
spec/services/infrastructure/blob_storage_spec.rb
@@ -1,11 +1,18 @@
require "spec_helper"
describe BlobStorage do
+ let(:bucket) { ENV['FOG_DIRECTORY'] }
+ subject { BlobStorage.new }
+
context "when uploading" do
let(:file) { File.join(Rails.root, 'spec/fixtures/images/gps.jpg') }
it "uploads to s3" do
- BlobStorage.new.upload("test#{SecureRandom.uuid}", file)
+ key = "test#{SecureRandom.uuid}"
+ subject.upload(key, file)
+
+ object = AWS::S3.new.buckets[bucket].objects[key]
+ expect(object.size).to > 0
end
end
end