mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 19:03:48 +08:00
created optimized_image
model
This commit is contained in:
parent
2c3f757951
commit
5de03814fb
7
app/models/optimized_image.rb
Normal file
7
app/models/optimized_image.rb
Normal 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
|
|
@ -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
|
||||
|
||||
|
|
17
db/migrate/20130616082327_create_optimized_images.rb
Normal file
17
db/migrate/20130616082327_create_optimized_images.rb
Normal 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
|
7
spec/models/optimized_image_spec.rb
Normal file
7
spec/models/optimized_image_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe OptimizedImage do
|
||||
|
||||
it { should belong_to :upload }
|
||||
|
||||
end
|
|
@ -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 }
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user