From 636f05bd3273dcdff2a272b799d1f8959c0ada4c Mon Sep 17 00:00:00 2001 From: The Lambda Calculus Date: Fri, 12 Aug 2011 16:31:52 -0400 Subject: [PATCH 1/3] [Issue 1126] Starting to build cucumber test for issue --- features/photos.feature | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 features/photos.feature diff --git a/features/photos.feature b/features/photos.feature new file mode 100644 index 000000000..5d4dfde4a --- /dev/null +++ b/features/photos.feature @@ -0,0 +1,22 @@ +@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 + Then I should see an uploaded image within the photo drop zone + And I press "Share" + And I wait for the ajax to finish + And I follow "Your Aspects" + Then I should see a "img" within ".stream_element div.photo_attachments" + From 98b71f92ab78a6f722eb6c738919a475bb3a34b4 Mon Sep 17 00:00:00 2001 From: The Lambda Calculus Date: Wed, 17 Aug 2011 09:01:10 -0400 Subject: [PATCH 2/3] 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 From 9d7b8d7f5db10bfb85201e1a9649d3d10e0f5b55 Mon Sep 17 00:00:00 2001 From: The Lambda Calculus Date: Thu, 18 Aug 2011 01:28:21 -0400 Subject: [PATCH 3/3] Have passing Cucumber tests [Finishes issue #1126] --- app/controllers/photos_controller.rb | 2 +- app/models/status_message.rb | 11 ++--- features/photos.feature | 49 +++++++++++++++++-- features/step_definitions/custom_web_steps.rb | 8 +++ features/support/paths.rb | 2 + 5 files changed, 62 insertions(+), 10 deletions(-) diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index e95f1404a..e3a90658a 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -128,7 +128,7 @@ class PhotosController < ApplicationController format.html do flash[:notice] = I18n.t 'photos.destroy.notice' if photo.status_message_guid - if photo.status_message.empty? + if photo.status_message.message_or_photos_present? photo.status_message.destroy respond_with photo, :location => person_photos_path(current_user.person) else diff --git a/app/models/status_message.rb b/app/models/status_message.rb index 0db527a35..eb2b4c577 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -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 @@ -134,19 +134,18 @@ class StatusMessage < Post def comment_email_subject formatted_message(:plain_text => true) - end + end - def empty? + def message_or_photos_present? self.text.blank? && self.photos == [] end protected - def message_or_photos_present? - if self.blank? + def ensure_message_requirements + if message_or_photos_present? errors[:base] << 'Status message requires a message or at least one photo' end end - end diff --git a/features/photos.feature b/features/photos.feature index 5d4dfde4a..43ffd0a4d 100644 --- a/features/photos.feature +++ b/features/photos.feature @@ -14,9 +14,52 @@ Feature: photos 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 - Then I should see an uploaded image within the photo drop zone And I press "Share" And I wait for the ajax to finish - And I follow "Your Aspects" - Then I should see a "img" within ".stream_element div.photo_attachments" + + 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" + diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index ffc71c8f4..895696344 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -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}" diff --git a/features/support/paths.rb b/features/support/paths.rb index 78dbb649f..79ea386ee 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -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 /^"(\/.*)"/