on photo delete, photo checks to see if it is set in user profile. if it is, profile is edited.

This commit is contained in:
danielvincent 2010-07-29 11:07:44 -07:00
parent fd4475370d
commit 11a099914c
2 changed files with 25 additions and 6 deletions

View file

@ -26,9 +26,13 @@ class Photo < Post
after_save :log_save_inspection
validates_true_for :album_id, :logic => lambda {self.validate_album_person}
before_destroy :ensure_user_picture
def validate_album_person
album.person_id == person_id
end
def remote_photo
@remote_photo ||= User.owner.url.chop + image.url(:scaled_full)
end
@ -40,4 +44,11 @@ class Photo < Post
image.store!
Rails.logger.info("Setting remote photo with id #{id}")
end
def ensure_user_picture
user = User.owner
if user.profile.image_url == image.url(:thumb_medium)
user.profile.update_attributes!(:image_url => nil)
end
end
end

View file

@ -26,7 +26,6 @@ describe Photo do
end
it 'must have an album' do
photo = Photo.new(:person => @user)
photo.image = File.open(@fixture_name)
photo.save
@ -36,6 +35,18 @@ describe Photo do
Photo.first.album.name.should == 'foo'
end
it 'should remove its reference in user profile if it is referred' do
@photo.image.store! File.open(@fixture_name)
@photo.save
@user.profile.image_url = @photo.image.url(:thumb_medium)
@user.save
User.first.profile.image_url.should == @photo.image.url(:thumb_medium)
@photo.destroy
User.first.profile.image_url.should be nil
end
describe 'non-image files' do
it 'should not store' do
file = File.open(@fail_fixture_name)
@ -52,9 +63,6 @@ describe Photo do
@photo.image = file
@photo.save.should == false
end
end
describe 'with encryption' do
@ -81,11 +89,11 @@ describe Photo do
@photo.image.store!
@photo.save
xml = @photo.to_xml.to_s
xml.include?("bp.jpeg").should be true
end
it 'should have an album id on serialization' do
@photo.image = File.open(@fixture_name)