Merge pull request #1866 from TheLambdaCalculus/b1126-deletion-of-all-photos-from-a-post-with-no-words-should-result-in-the-post-being-deleted

B1126 deletion of all photos from a post with no words should result in the post being deleted
This commit is contained in:
Daniel Grippi 2011-09-01 10:04:10 -07:00
commit 00ffc996e4
5 changed files with 88 additions and 4 deletions

View file

@ -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.message_or_photos_present?
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

View file

@ -19,7 +19,7 @@ class StatusMessage < Post
xml_attr :raw_message
has_many :photos, :dependent => :destroy, :foreign_key => :status_message_guid, :primary_key => :guid
validate :message_or_photos_present?
validate :ensure_message_requirements
attr_accessible :text
serialize :youtube_titles, Hash
@ -136,10 +136,14 @@ class StatusMessage < Post
formatted_message(:plain_text => true)
end
def message_or_photos_present?
self.text.blank? && self.photos == []
end
protected
def message_or_photos_present?
if self.text.blank? && self.photos == []
def ensure_message_requirements
if message_or_photos_present?
errors[:base] << 'Status message requires a message or at least one photo'
end
end

65
features/photos.feature Normal file
View file

@ -0,0 +1,65 @@
@javascript
Feature: photos
In order to enlighten humanity for the good of society
As a rock star
I want to post pictures of a button
Background:
Given a user with username "bob"
When I sign in as "bob@bob.bob"
And I am on the home page
Scenario: deleting a photo will delete a photo-only post if the photo was the last image
Given I expand the publisher
And I attach the file "spec/fixtures/button.png" to hidden element "file" within "#file-upload"
And I wait for the ajax to finish
And I press "Share"
And I wait for the ajax to finish
When I go to the photo page for "bob@bob.bob"'s latest post
And I follow "edit_photo_toggle"
And I preemptively confirm the alert
And I press "Delete Photo"
And I wait for the ajax to finish
And I go to the home page
Then I should see 0 posts
Scenario: deleting a photo will not delete a photo-only post if another photo remains attached
Given I expand the publisher
And I attach the file "spec/fixtures/button.png" to hidden element "file" within "#file-upload"
And I wait for the ajax to finish
And I attach the file "spec/fixtures/button.png" to hidden element "file" within "#file-upload"
And I wait for the ajax to finish
And I press "Share"
And I wait for the ajax to finish
When I go to the photo page for "bob@bob.bob"'s latest post
And I follow "edit_photo_toggle"
And I preemptively confirm the alert
And I press "Delete Photo"
And I wait for the ajax to finish
And I go to the home page
Then I should see 1 posts
Scenario: deleting a photo will not delete its parent post if the parent also contained text
Given I expand the publisher
And I fill in "status_message_fake_text" with "I am eating a yogurt"
And I attach the file "spec/fixtures/button.png" to hidden element "file" within "#file-upload"
And I wait for the ajax to finish
And I press "Share"
And I wait for the ajax to finish
When I go to the photo page for "bob@bob.bob"'s latest post
And I follow "edit_photo_toggle"
And I preemptively confirm the alert
And I press "Delete Photo"
And I wait for the ajax to finish
And I go to the home page
Then I should see 1 posts
And I should see "I am eating a yogurt" within ".stream_element"

View file

@ -108,11 +108,19 @@ When /^I press the ([\d])(nd|rd|st|th) "([^\"]*)"(?: within "([^\"]*)")?$/ do |n
find(:css, link_selector+":nth-child(#{number})").click
end
end
Then /^(?:|I )should see a "([^\"]*)"(?: within "([^\"]*)")?$/ do |selector, scope_selector|
with_scope(scope_selector) do
page.has_css?(selector).should be_true
end
end
Then /^(?:|I )should not see a "([^\"]*)"(?: within "([^\"]*)")?$/ do |selector, scope_selector|
with_scope(scope_selector) do
page.has_css?(selector).should be_false
end
end
Then /^I should see "([^\"]*)" in the main content area$/ do |stuff|
within("#main_stream") do
Then "I should see #{stuff}"

View file

@ -27,6 +27,8 @@ module NavigationHelpers
person_path(User.find_by_email($1).person)
when /^my account settings page$/
edit_user_path
when /^the photo page for "([^\"]*)"'s latest post$/
photo_path(User.find_by_email($1).posts.where(:type => "Photo").last)
when /^the photo page for "([^\"]*)"'s post "([^\"]*)"$/
photo_path(User.find_by_email($1).posts.find_by_text($2))
when /^"(\/.*)"/