fixed nil error in migration when dealing with remote images

This commit is contained in:
danielvincent 2010-12-18 01:25:30 -08:00 committed by zhitomirskiyi
parent 1d52e06532
commit 7f87825186
2 changed files with 20 additions and 8 deletions

View file

@ -40,13 +40,13 @@ namespace :migrations do
Photo.all.each do |photo|
# extract root
unless photo.image.url.match(/^https?:\/\//)
pod_url = photo.person.url
pod_url.chop! if pod_url[-1,1] == '/'
if photo.image.url
remote_path = "#{pod_url}#{photo.image.url}"
else
remote_path = photo.image.url
remote_path = "#{pod_url}#{photo.remote_photo_path}/#{photo.remote_photo_name}"
end
# get path/filename

View file

@ -21,11 +21,19 @@ describe 'migrations' do
@photos = []
5.times do |n|
if n % 2 == 0
photo = Photo.instantiate(:user_file => File.open(@fixture_name))
photo.remote_photo_path = nil
photo.remote_photo_name = nil
photo.person = make_user.person
else
photo = Photo.new
photo.person = Factory(:person, :url => "https://remote.com/")
# legacy photo object
photo.remote_photo_path = "/uploads/images/"
photo.remote_photo_name = "129jcxz09j2103enas0zxc231cxz.png"
end
photo.person = (n % 2 == 0 ? make_user.person : Factory(:person, :url => "https://remote.com/"))
@photos[n] = photo
@photos[n].save
end
@ -45,6 +53,10 @@ describe 'migrations' do
@photos[0].remote_photo_path.should include("http://google-")
@photos[1].remote_photo_path.should include("https://remote.com/")
end
it 'is not destructive on a second pass' do
pending 'double check'
end
end
end