diff --git a/lib/tasks/migrations.rake b/lib/tasks/migrations.rake index 9c46d830c..a0056498e 100644 --- a/lib/tasks/migrations.rake +++ b/lib/tasks/migrations.rake @@ -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] == '/' - 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 diff --git a/spec/lib/tasks/migrations_spec.rb b/spec/lib/tasks/migrations_spec.rb index eb7c9abcc..63e700207 100644 --- a/spec/lib/tasks/migrations_spec.rb +++ b/spec/lib/tasks/migrations_spec.rb @@ -21,11 +21,19 @@ describe 'migrations' do @photos = [] 5.times do |n| - photo = Photo.instantiate(:user_file => File.open(@fixture_name)) - photo.remote_photo_path = nil - photo.remote_photo_name = nil + 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