RS; Image filename is now the Photo model id

This commit is contained in:
Raphael 2010-08-02 10:05:34 -07:00
parent dc1a164b67
commit b8ae6b44a2
2 changed files with 17 additions and 7 deletions

View file

@ -11,6 +11,10 @@ class ImageUploader < CarrierWave::Uploader::Base
%w(jpg jpeg gif png) %w(jpg jpeg gif png)
end end
def filename
model.id.to_s + File.extname(@filename)
end
version :thumb_small do version :thumb_small do
process :resize_to_fill => [30,30] process :resize_to_fill => [30,30]
end end

View file

@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe Photo do describe Photo do
before do before do
@user = Factory.create(:user) @user = Factory.create(:user)
@fixture_filename = 'bp.jpeg'
@fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg' @fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg'
@fail_fixture_name = File.dirname(__FILE__) + '/../fixtures/msg.xml' @fail_fixture_name = File.dirname(__FILE__) + '/../fixtures/msg.xml'
@album = Album.create(:name => "foo", :person => @user) @album = Album.create(:name => "foo", :person => @user)
@ -47,6 +48,13 @@ describe Photo do
User.first.profile.image_url.should be nil User.first.profile.image_url.should be nil
end end
it 'should not use the imported filename as the url' do
@photo.image.store! File.open(@fixture_name)
puts @photo.image.url(:thumb_medium)
@photo.image.url.include?(@fixture_filename).should be false
@photo.image.url(:thumb_medium).include?(@fixture_filename).should be false
end
describe 'non-image files' do describe 'non-image files' do
it 'should not store' do it 'should not store' do
file = File.open(@fail_fixture_name) file = File.open(@fail_fixture_name)
@ -91,15 +99,13 @@ describe Photo do
xml = @photo.to_xml.to_s xml = @photo.to_xml.to_s
xml.include?("bp.jpeg").should be true xml.include?(@photo.image.url).should be true
end end
it 'should have an album id on serialization' do it 'should have an album id on serialization' do
@photo.image = File.open(@fixture_name) @photo.image.store! File.open(@fixture_name)
xml = @photo.to_xml.to_s xml = @photo.to_xml.to_s
puts xml xml.include?(@photo.album_id.to_s).should be true
xml.include?("scaled_full_bp.").should be true
end end
end end
end end