Fix 328 profile images dying, thanks to theBernd
This commit is contained in:
parent
f6d899f1d9
commit
4eba0595f9
4 changed files with 30 additions and 28 deletions
|
|
@ -50,9 +50,9 @@ class Photo < Post
|
|||
end
|
||||
|
||||
def ensure_user_picture
|
||||
users = Person.all('profile.image_url' => image.url(:thumb_medium) )
|
||||
users.each{ |user|
|
||||
user.profile.update_attributes!(:image_url => nil)
|
||||
people = Person.all('profile.image_url' => absolute_url(:thumb_medium) )
|
||||
people.each{ |person|
|
||||
person.profile.update_attributes(:image_url => nil)
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -64,6 +64,12 @@ class Photo < Post
|
|||
true
|
||||
end
|
||||
|
||||
def absolute_url *args
|
||||
pod_url = APP_CONFIG[:pod_url].dup
|
||||
pod_url.chop! if APP_CONFIG[:pod_url][-1,1] == '/'
|
||||
"#{pod_url}#{url(*args)}"
|
||||
end
|
||||
|
||||
def self.gen_random_string(len)
|
||||
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
|
||||
string = ""
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ class Profile
|
|||
end
|
||||
|
||||
def image_url= url
|
||||
return if url.nil? || url.empty?
|
||||
if url.match(/^https?:\/\//)
|
||||
return image_url if url == ''
|
||||
if url.nil? || url.match(/^https?:\/\//)
|
||||
super(url)
|
||||
else
|
||||
super(absolutify_local_url(url))
|
||||
|
|
|
|||
|
|
@ -76,29 +76,28 @@ describe Photo do
|
|||
binary.should == fixture_binary
|
||||
end
|
||||
|
||||
it 'should have a caption' do
|
||||
@photo.image.store! File.open(@fixture_name)
|
||||
@photo.caption = "cool story, bro"
|
||||
@photo.save.should be_true
|
||||
end
|
||||
context 'with a saved photo' do
|
||||
before do
|
||||
@photo.image.store! File.open(@fixture_name)
|
||||
end
|
||||
it 'should have a caption' do
|
||||
@photo.caption = "cool story, bro"
|
||||
@photo.save.should be_true
|
||||
end
|
||||
|
||||
it 'should remove its reference in user profile if it is referred' do
|
||||
@photo.image.store! File.open(@fixture_name)
|
||||
@photo.save
|
||||
it 'should remove its reference in user profile if it is referred' do
|
||||
@photo.save
|
||||
|
||||
@user.profile.image_url = @photo.image.url(:thumb_medium)
|
||||
@user.save
|
||||
@user.person.save
|
||||
@user.profile.image_url = @photo.image.url(:thumb_medium)
|
||||
@user.person.save
|
||||
@photo.destroy
|
||||
Person.find(@user.person.id).profile.image_url.should be_nil
|
||||
end
|
||||
|
||||
@user.profile.image_url.should == @photo.image.url(:thumb_medium)
|
||||
@photo.destroy
|
||||
@user.reload.profile.image_url.should be nil
|
||||
end
|
||||
|
||||
it 'should not use the imported filename as the url' do
|
||||
@photo.image.store! File.open(@fixture_name)
|
||||
@photo.image.url.include?(@fixture_filename).should be false
|
||||
@photo.image.url(:thumb_medium).include?("/" + @fixture_filename).should be false
|
||||
it 'should not use the imported filename as the url' do
|
||||
@photo.image.url.include?(@fixture_filename).should be false
|
||||
@photo.image.url(:thumb_medium).include?("/" + @fixture_filename).should be false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'non-image files' do
|
||||
|
|
|
|||
|
|
@ -54,9 +54,6 @@ describe Profile do
|
|||
it 'ignores an empty string' do
|
||||
lambda {@profile.image_url = ""}.should_not change(@profile, :image_url)
|
||||
end
|
||||
it 'ignores nil' do
|
||||
lambda {@profile.image_url = nil}.should_not change(@profile, :image_url)
|
||||
end
|
||||
it 'makes relative urls absolute' do
|
||||
@profile.image_url = @photo.url(:thumb_medium)
|
||||
@profile.image_url.should == "#{@pod_url}#{@photo.url(:thumb_medium)}"
|
||||
|
|
|
|||
Loading…
Reference in a new issue