created optimized_image model

This commit is contained in:
Régis Hanol 2013-06-16 10:39:48 +02:00
parent 2c3f757951
commit 5de03814fb
5 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,7 @@
class OptimizedImage < ActiveRecord::Base
belongs_to :upload
def filename
"#{sha[0..2]}/#{sha[3..5]}/#{sha[6..16]}_#{width}x#{height}#{ext}"
end
end

View File

@ -9,6 +9,8 @@ class Upload < ActiveRecord::Base
has_many :post_uploads
has_many :posts, through: :post_uploads
has_many :optimized_images
validates_presence_of :filesize
validates_presence_of :original_filename

View File

@ -0,0 +1,17 @@
class CreateOptimizedImages < ActiveRecord::Migration
def up
create_table :optimized_images do |t|
t.string :sha, null: false
t.string :ext, null: false
t.integer :width, null: false
t.integer :height, null: false
t.integer :upload_id, null: false
end
add_index :optimized_images, :upload_id
end
def down
drop_table :optimized_images
end
end

View File

@ -0,0 +1,7 @@
require 'spec_helper'
describe OptimizedImage do
it { should belong_to :upload }
end

View File

@ -8,6 +8,8 @@ describe Upload do
it { should have_many :post_uploads }
it { should have_many :posts }
it { should have_many :optimized_images }
it { should validate_presence_of :original_filename }
it { should validate_presence_of :filesize }