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
|
end
|
||||||
|
|
||||||
def ensure_user_picture
|
def ensure_user_picture
|
||||||
users = Person.all('profile.image_url' => image.url(:thumb_medium) )
|
people = Person.all('profile.image_url' => absolute_url(:thumb_medium) )
|
||||||
users.each{ |user|
|
people.each{ |person|
|
||||||
user.profile.update_attributes!(:image_url => nil)
|
person.profile.update_attributes(:image_url => nil)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -64,6 +64,12 @@ class Photo < Post
|
||||||
true
|
true
|
||||||
end
|
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)
|
def self.gen_random_string(len)
|
||||||
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
|
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
|
||||||
string = ""
|
string = ""
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,8 @@ class Profile
|
||||||
end
|
end
|
||||||
|
|
||||||
def image_url= url
|
def image_url= url
|
||||||
return if url.nil? || url.empty?
|
return image_url if url == ''
|
||||||
if url.match(/^https?:\/\//)
|
if url.nil? || url.match(/^https?:\/\//)
|
||||||
super(url)
|
super(url)
|
||||||
else
|
else
|
||||||
super(absolutify_local_url(url))
|
super(absolutify_local_url(url))
|
||||||
|
|
|
||||||
|
|
@ -76,29 +76,28 @@ describe Photo do
|
||||||
binary.should == fixture_binary
|
binary.should == fixture_binary
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should have a caption' do
|
context 'with a saved photo' do
|
||||||
@photo.image.store! File.open(@fixture_name)
|
before do
|
||||||
@photo.caption = "cool story, bro"
|
@photo.image.store! File.open(@fixture_name)
|
||||||
@photo.save.should be_true
|
end
|
||||||
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
|
it 'should remove its reference in user profile if it is referred' do
|
||||||
@photo.image.store! File.open(@fixture_name)
|
@photo.save
|
||||||
@photo.save
|
|
||||||
|
|
||||||
@user.profile.image_url = @photo.image.url(:thumb_medium)
|
@user.profile.image_url = @photo.image.url(:thumb_medium)
|
||||||
@user.save
|
@user.person.save
|
||||||
@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)
|
it 'should not use the imported filename as the url' do
|
||||||
@photo.destroy
|
@photo.image.url.include?(@fixture_filename).should be false
|
||||||
@user.reload.profile.image_url.should be nil
|
@photo.image.url(:thumb_medium).include?("/" + @fixture_filename).should be false
|
||||||
end
|
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'non-image files' do
|
describe 'non-image files' do
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,6 @@ describe Profile do
|
||||||
it 'ignores an empty string' do
|
it 'ignores an empty string' do
|
||||||
lambda {@profile.image_url = ""}.should_not change(@profile, :image_url)
|
lambda {@profile.image_url = ""}.should_not change(@profile, :image_url)
|
||||||
end
|
end
|
||||||
it 'ignores nil' do
|
|
||||||
lambda {@profile.image_url = nil}.should_not change(@profile, :image_url)
|
|
||||||
end
|
|
||||||
it 'makes relative urls absolute' do
|
it 'makes relative urls absolute' do
|
||||||
@profile.image_url = @photo.url(:thumb_medium)
|
@profile.image_url = @photo.url(:thumb_medium)
|
||||||
@profile.image_url.should == "#{@pod_url}#{@photo.url(:thumb_medium)}"
|
@profile.image_url.should == "#{@pod_url}#{@photo.url(:thumb_medium)}"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue