Commit d4124da6
Changed files (3)
app/jobs/process_photo_job.rb
@@ -0,0 +1,12 @@
+class ProcessPhotoJob < ActiveJob::Base
+ queue_as :default
+
+ def perform(photo, file_path)
+ photo.upload(file_path, storage)
+ photo.save!
+ end
+
+ def storage
+ Spank::IOC.resolve(:blob_storage)
+ end
+end
db/schema.rb
@@ -18,11 +18,11 @@ ActiveRecord::Schema.define(version: 20150111153140) do
enable_extension "uuid-ossp"
create_table "activities", force: :cascade do |t|
- t.integer "subject_id", null: false
- t.string "subject_type", limit: 255, null: false
- t.integer "user_id", null: false
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
+ t.integer "subject_id", null: false
+ t.string "subject_type", null: false
+ t.integer "user_id", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
end
add_index "activities", ["subject_id"], name: "index_activities_on_subject_id", using: :btree
@@ -33,18 +33,18 @@ ActiveRecord::Schema.define(version: 20150111153140) do
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
- t.string "avatar", limit: 255
+ t.string "avatar"
t.boolean "avatar_processing"
- t.string "avatar_tmp", limit: 255
+ t.string "avatar_tmp"
end
add_index "avatars", ["user_id"], name: "index_avatars_on_user_id", using: :btree
create_table "categories", force: :cascade do |t|
- t.string "name", limit: 255
+ t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
- t.string "slug", limit: 255
+ t.string "slug"
end
add_index "categories", ["slug"], name: "index_categories_on_slug", using: :btree
@@ -52,7 +52,7 @@ ActiveRecord::Schema.define(version: 20150111153140) do
create_table "comments", force: :cascade do |t|
t.integer "user_id"
t.integer "creation_id"
- t.string "text", limit: 255
+ t.string "text"
t.integer "disqus_id"
t.datetime "created_at"
t.datetime "updated_at"
@@ -62,15 +62,15 @@ ActiveRecord::Schema.define(version: 20150111153140) do
add_index "comments", ["user_id"], name: "index_comments_on_user_id", using: :btree
create_table "creations", force: :cascade do |t|
- t.string "name", limit: 255
+ t.string "name"
t.text "story"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
- t.string "image", limit: 255
- t.string "watermark", limit: 255
- t.integer "photos_count", default: 0
- t.integer "favorites_count", default: 0
+ t.string "image"
+ t.string "watermark"
+ t.integer "photos_count", default: 0
+ t.integer "favorites_count", default: 0
t.integer "category_id"
end
@@ -79,15 +79,15 @@ ActiveRecord::Schema.define(version: 20150111153140) do
add_index "creations", ["user_id"], name: "index_creations_on_user_id", using: :btree
create_table "delayed_jobs", force: :cascade do |t|
- t.integer "priority", default: 0
- t.integer "attempts", default: 0
+ t.integer "priority", default: 0
+ t.integer "attempts", default: 0
t.text "handler"
t.text "last_error"
t.datetime "run_at"
t.datetime "locked_at"
t.datetime "failed_at"
- t.string "locked_by", limit: 255
- t.string "queue", limit: 255
+ t.string "locked_by"
+ t.string "queue"
t.datetime "created_at"
t.datetime "updated_at"
end
@@ -105,18 +105,18 @@ ActiveRecord::Schema.define(version: 20150111153140) do
add_index "favorites", ["user_id"], name: "index_favorites_on_user_id", using: :btree
create_table "interests", force: :cascade do |t|
- t.string "name", limit: 255
+ t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "locations", id: :uuid, default: "uuid_generate_v4()", force: :cascade do |t|
t.uuid "locatable_id"
- t.string "locatable_type", limit: 255
- t.string "latitude", limit: 255
- t.string "longitude", limit: 255
- t.string "city", limit: 255
- t.string "country", limit: 255
+ t.string "locatable_type"
+ t.string "latitude"
+ t.string "longitude"
+ t.string "city"
+ t.string "country"
t.datetime "created_at"
t.datetime "updated_at"
end
@@ -125,18 +125,18 @@ ActiveRecord::Schema.define(version: 20150111153140) do
create_table "photos", force: :cascade do |t|
t.integer "imageable_id"
- t.string "image", limit: 255
+ t.string "image"
t.datetime "created_at"
t.datetime "updated_at"
- t.string "image_tmp", limit: 255
+ t.string "image_tmp"
t.boolean "image_processing"
- t.string "content_type", limit: 255
- t.string "original_filename", limit: 255
+ t.string "content_type"
+ t.string "original_filename"
t.float "latitude"
t.float "longitude"
- t.string "sha256", limit: 255
- t.string "watermark", limit: 255
- t.string "imageable_type", limit: 255
+ t.string "sha256"
+ t.string "watermark"
+ t.string "imageable_type"
end
add_index "photos", ["imageable_id", "imageable_type"], name: "index_photos_on_imageable_id_and_imageable_type", using: :btree
@@ -145,9 +145,9 @@ ActiveRecord::Schema.define(version: 20150111153140) do
create_table "taggings", force: :cascade do |t|
t.integer "tag_id"
t.integer "taggable_id"
- t.string "taggable_type", limit: 255
+ t.string "taggable_type"
t.integer "tagger_id"
- t.string "tagger_type", limit: 255
+ t.string "tagger_type"
t.string "context", limit: 128
t.datetime "created_at"
end
@@ -159,8 +159,8 @@ ActiveRecord::Schema.define(version: 20150111153140) do
add_index "taggings", ["tagger_type"], name: "index_taggings_on_tagger_type", using: :btree
create_table "tags", force: :cascade do |t|
- t.string "name", limit: 255
- t.integer "taggings_count", default: 0
+ t.string "name"
+ t.integer "taggings_count", default: 0
end
add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree
@@ -177,15 +177,15 @@ ActiveRecord::Schema.define(version: 20150111153140) do
add_index "tools", ["name"], name: "index_tools_on_name", unique: true, using: :btree
create_table "tutorials", force: :cascade do |t|
- t.string "heading", limit: 255
+ t.string "heading"
t.text "description"
- t.string "url", limit: 255
+ t.string "url"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
- t.string "image_url", limit: 255
- t.string "author", limit: 255
- t.string "author_url", limit: 255
+ t.string "image_url"
+ t.string "author"
+ t.string "author_url"
end
add_index "tutorials", ["user_id"], name: "index_tutorials_on_user_id", using: :btree
@@ -194,8 +194,8 @@ ActiveRecord::Schema.define(version: 20150111153140) do
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
- t.string "key", limit: 255
- t.string "ip", limit: 255
+ t.string "key"
+ t.string "ip"
t.text "user_agent"
t.datetime "accessed_at"
t.datetime "revoked_at"
@@ -207,20 +207,20 @@ ActiveRecord::Schema.define(version: 20150111153140) do
add_index "user_sessions", ["user_id"], name: "index_user_sessions_on_user_id", using: :btree
create_table "users", force: :cascade do |t|
- t.string "email", limit: 255, default: "", null: false
- t.string "password_digest", limit: 255, default: "", null: false
- t.string "reset_password_token", limit: 255
+ t.string "email", default: "", null: false
+ t.string "password_digest", default: "", null: false
+ t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "created_at"
t.datetime "updated_at"
- t.string "name", limit: 255
- t.string "website", limit: 255
- t.string "twitter", limit: 255
- t.string "facebook", limit: 255
- t.string "city", limit: 255
- t.string "authentication_token", limit: 255
- t.string "full_address", limit: 255
- t.integer "creations_count", default: 0
+ t.string "name"
+ t.string "website"
+ t.string "twitter"
+ t.string "facebook"
+ t.string "city"
+ t.string "authentication_token"
+ t.string "full_address"
+ t.integer "creations_count", default: 0
t.boolean "admin"
end
spec/jobs/process_photo_job_spec.rb
@@ -0,0 +1,21 @@
+require 'rails_helper'
+
+RSpec.describe ProcessPhotoJob, :type => :job do
+ subject { ProcessPhotoJob.new }
+
+ describe "#perform" do
+ let(:blob_storage) { double(upload: true) }
+ let(:image_path) { File.join(Rails.root, 'spec/fixtures/images/gps.jpg') }
+ let(:photo) { double(upload: true, save!: true) }
+
+ before :each do
+ allow(subject).to receive(:storage).and_return(blob_storage)
+ end
+
+ it "saves the uploaded image" do
+ subject.perform(photo, image_path)
+ expect(photo).to have_received(:upload).with(image_path, blob_storage)
+ expect(photo).to have_received(:save!)
+ end
+ end
+end