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|
|
Photo.all.each do |photo|
|
||||||
# extract root
|
# extract root
|
||||||
unless photo.image.url.match(/^https?:\/\//)
|
pod_url = photo.person.url
|
||||||
|
pod_url.chop! if pod_url[-1,1] == '/'
|
||||||
|
|
||||||
pod_url = photo.person.url
|
if photo.image.url
|
||||||
pod_url.chop! if pod_url[-1,1] == '/'
|
|
||||||
remote_path = "#{pod_url}#{photo.image.url}"
|
remote_path = "#{pod_url}#{photo.image.url}"
|
||||||
else
|
else
|
||||||
remote_path = photo.image.url
|
remote_path = "#{pod_url}#{photo.remote_photo_path}/#{photo.remote_photo_name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# get path/filename
|
# get path/filename
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,19 @@ describe 'migrations' do
|
||||||
@photos = []
|
@photos = []
|
||||||
|
|
||||||
5.times do |n|
|
5.times do |n|
|
||||||
photo = Photo.instantiate(:user_file => File.open(@fixture_name))
|
if n % 2 == 0
|
||||||
photo.remote_photo_path = nil
|
photo = Photo.instantiate(:user_file => File.open(@fixture_name))
|
||||||
photo.remote_photo_name = nil
|
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] = photo
|
||||||
@photos[n].save
|
@photos[n].save
|
||||||
end
|
end
|
||||||
|
|
@ -45,6 +53,10 @@ describe 'migrations' do
|
||||||
@photos[0].remote_photo_path.should include("http://google-")
|
@photos[0].remote_photo_path.should include("http://google-")
|
||||||
@photos[1].remote_photo_path.should include("https://remote.com/")
|
@photos[1].remote_photo_path.should include("https://remote.com/")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'is not destructive on a second pass' do
|
||||||
|
pending 'double check'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue