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:
parent
fd4475370d
commit
11a099914c
2 changed files with 25 additions and 6 deletions
|
|
@ -26,9 +26,13 @@ class Photo < Post
|
||||||
after_save :log_save_inspection
|
after_save :log_save_inspection
|
||||||
validates_true_for :album_id, :logic => lambda {self.validate_album_person}
|
validates_true_for :album_id, :logic => lambda {self.validate_album_person}
|
||||||
|
|
||||||
|
before_destroy :ensure_user_picture
|
||||||
|
|
||||||
|
|
||||||
def validate_album_person
|
def validate_album_person
|
||||||
album.person_id == person_id
|
album.person_id == person_id
|
||||||
end
|
end
|
||||||
|
|
||||||
def remote_photo
|
def remote_photo
|
||||||
@remote_photo ||= User.owner.url.chop + image.url(:scaled_full)
|
@remote_photo ||= User.owner.url.chop + image.url(:scaled_full)
|
||||||
end
|
end
|
||||||
|
|
@ -40,4 +44,11 @@ class Photo < Post
|
||||||
image.store!
|
image.store!
|
||||||
Rails.logger.info("Setting remote photo with id #{id}")
|
Rails.logger.info("Setting remote photo with id #{id}")
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,7 @@ describe Photo do
|
||||||
binary.should == fixture_binary
|
binary.should == fixture_binary
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'must have an album' do
|
it 'must have an album' do
|
||||||
|
|
||||||
photo = Photo.new(:person => @user)
|
photo = Photo.new(:person => @user)
|
||||||
photo.image = File.open(@fixture_name)
|
photo.image = File.open(@fixture_name)
|
||||||
photo.save
|
photo.save
|
||||||
|
|
@ -36,6 +35,18 @@ describe Photo do
|
||||||
Photo.first.album.name.should == 'foo'
|
Photo.first.album.name.should == 'foo'
|
||||||
end
|
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
|
describe 'non-image files' do
|
||||||
it 'should not store' do
|
it 'should not store' do
|
||||||
file = File.open(@fail_fixture_name)
|
file = File.open(@fail_fixture_name)
|
||||||
|
|
@ -52,9 +63,6 @@ describe Photo do
|
||||||
@photo.image = file
|
@photo.image = file
|
||||||
@photo.save.should == false
|
@photo.save.should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'with encryption' do
|
describe 'with encryption' do
|
||||||
|
|
@ -80,12 +88,12 @@ describe Photo do
|
||||||
@photo.image = File.open(@fixture_name)
|
@photo.image = File.open(@fixture_name)
|
||||||
@photo.image.store!
|
@photo.image.store!
|
||||||
@photo.save
|
@photo.save
|
||||||
|
|
||||||
|
|
||||||
xml = @photo.to_xml.to_s
|
xml = @photo.to_xml.to_s
|
||||||
|
|
||||||
xml.include?("bp.jpeg").should be true
|
xml.include?("bp.jpeg").should be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should have an album id on serialization' do
|
it 'should have an album id on serialization' do
|
||||||
@photo.image = File.open(@fixture_name)
|
@photo.image = File.open(@fixture_name)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue