fixed nil error in migration when dealing with remote images
This commit is contained in:
parent
1d52e06532
commit
7f87825186
2 changed files with 20 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue