From 98b71f92ab78a6f722eb6c738919a475bb3a34b4 Mon Sep 17 00:00:00 2001 From: The Lambda Calculus Date: Wed, 17 Aug 2011 09:01:10 -0400 Subject: [PATCH] We now do a check on photo deletion to ensure that any associated status messages are also deleted if now empty [Issue #1126] --- app/controllers/photos_controller.rb | 7 ++++++- app/models/status_message.rb | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 7a1406ea9..e95f1404a 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -128,7 +128,12 @@ class PhotosController < ApplicationController format.html do flash[:notice] = I18n.t 'photos.destroy.notice' if photo.status_message_guid - respond_with photo, :location => post_path(photo.status_message) + if photo.status_message.empty? + photo.status_message.destroy + respond_with photo, :location => person_photos_path(current_user.person) + else + respond_with photo, :location => post_path(photo.status_message) + end else respond_with photo, :location => person_photos_path(current_user.person) end diff --git a/app/models/status_message.rb b/app/models/status_message.rb index c08386234..0db527a35 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -134,14 +134,19 @@ class StatusMessage < Post def comment_email_subject formatted_message(:plain_text => true) + end + + def empty? + self.text.blank? && self.photos == [] end protected def message_or_photos_present? - if self.text.blank? && self.photos == [] + if self.blank? errors[:base] << 'Status message requires a message or at least one photo' end end + end