Commit dca10817

mo khan <mo@mokhan.ca>
2014-05-31 15:33:42
save the content type and filename of each new photo.
1 parent 1d5aca0
app/services/application/handlers/process_photo.rb
@@ -11,8 +11,8 @@ class ProcessPhoto
     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.content_type = message[:content_type]
+    photo.original_filename = message[:original_filename]
     photo.save!
   end
 end
db/migrate/20140531153018_add_content_type_to_photos.rb
@@ -0,0 +1,5 @@
+class AddContentTypeToPhotos < ActiveRecord::Migration
+  def change
+    add_column :photos, :content_type, :string
+  end
+end
db/migrate/20140531153240_add_original_filename_to_photos.rb
@@ -0,0 +1,5 @@
+class AddOriginalFilenameToPhotos < ActiveRecord::Migration
+  def change
+    add_column :photos, :original_filename, :string
+  end
+end
db/schema.rb
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 20140521032101) do
+ActiveRecord::Schema.define(version: 20140531153240) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -30,8 +30,8 @@ ActiveRecord::Schema.define(version: 20140521032101) do
 
   create_table "avatars", force: true do |t|
     t.integer  "user_id"
-    t.datetime "created_at"
-    t.datetime "updated_at"
+    t.datetime "created_at",        null: false
+    t.datetime "updated_at",        null: false
     t.string   "avatar"
     t.boolean  "avatar_processing"
     t.string   "avatar_tmp"
@@ -93,8 +93,8 @@ ActiveRecord::Schema.define(version: 20140521032101) do
     t.datetime "failed_at"
     t.string   "locked_by"
     t.string   "queue"
-    t.datetime "created_at"
-    t.datetime "updated_at"
+    t.datetime "created_at",             null: false
+    t.datetime "updated_at",             null: false
   end
 
   add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree
@@ -111,13 +111,8 @@ ActiveRecord::Schema.define(version: 20140521032101) do
 
   create_table "interests", force: true do |t|
     t.string   "name"
-    t.datetime "created_at"
-    t.datetime "updated_at"
-  end
-
-  create_table "page_views", force: true do |t|
-    t.integer "user_id"
-    t.string  "url"
+    t.datetime "created_at", null: false
+    t.datetime "updated_at", null: false
   end
 
   create_table "photos", force: true do |t|
@@ -127,6 +122,8 @@ ActiveRecord::Schema.define(version: 20140521032101) do
     t.datetime "updated_at"
     t.string   "image_tmp"
     t.boolean  "image_processing"
+    t.string   "content_type"
+    t.string   "original_filename"
   end
 
   add_index "photos", ["creation_id"], name: "index_photos_on_creation_id", using: :btree
@@ -156,8 +153,8 @@ ActiveRecord::Schema.define(version: 20140521032101) do
     t.text     "description"
     t.string   "url"
     t.integer  "user_id"
-    t.datetime "created_at"
-    t.datetime "updated_at"
+    t.datetime "created_at",  null: false
+    t.datetime "updated_at",  null: false
     t.string   "image_url"
     t.string   "author"
     t.string   "author_url"
@@ -166,12 +163,12 @@ ActiveRecord::Schema.define(version: 20140521032101) do
   add_index "tutorials", ["user_id"], name: "index_tutorials_on_user_id", using: :btree
 
   create_table "users", force: true do |t|
-    t.string   "email",                  default: "", null: false
-    t.string   "encrypted_password",     default: "", null: false
+    t.string   "email",                              default: "", null: false
+    t.string   "encrypted_password",     limit: 128, default: "", null: false
     t.string   "reset_password_token"
     t.datetime "reset_password_sent_at"
     t.datetime "remember_created_at"
-    t.integer  "sign_in_count",          default: 0
+    t.integer  "sign_in_count",                      default: 0
     t.datetime "current_sign_in_at"
     t.datetime "last_sign_in_at"
     t.string   "current_sign_in_ip"
@@ -190,13 +187,13 @@ ActiveRecord::Schema.define(version: 20140521032101) do
     t.datetime "confirmed_at"
     t.datetime "confirmation_sent_at"
     t.string   "unconfirmed_email"
-    t.integer  "failed_attempts",        default: 0
+    t.integer  "failed_attempts",                    default: 0
     t.string   "unlock_token"
     t.datetime "locked_at"
     t.string   "authentication_token"
     t.string   "invitation_token"
     t.string   "full_address"
-    t.integer  "creations_count",        default: 0
+    t.integer  "creations_count",                    default: 0
     t.boolean  "is_admin"
   end
 
spec/services/application/handlers/process_photo_spec.rb
@@ -33,6 +33,14 @@ describe ProcessPhoto do
     it "indicates that the photo has been processed." do
       photo.image_processing.should be_false
     end
+
+    it "specifies the content type" do
+      photo.content_type.should == 'image/jpeg'
+    end
+
+    it "specifies the original filename" do
+      photo.original_filename = 'blah.jpg'
+    end
   end
 end