From 9d7b8d7f5db10bfb85201e1a9649d3d10e0f5b55 Mon Sep 17 00:00:00 2001 From: The Lambda Calculus Date: Thu, 18 Aug 2011 01:28:21 -0400 Subject: [PATCH] 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 /^"(\/.*)"/