From 290fb1e7f5994a984c4b13dff5750d20f13f50eb Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Sat, 2 Jul 2011 13:40:30 -0700 Subject: [PATCH] Cut 45 seconds out of the comments feature by using factories --- .travis.yml | 1 - features/comments.feature | 12 +----------- features/step_definitions/user_steps.rb | 9 +++++++++ spec/factories.rb | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4745160ac..6fc098476 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ rvm: before_script: - "sass --update public/stylesheets/sass/:public/stylesheets/" - "cp config/database.yml.example config/database.yml" - - "rm .rspec" - "rake db:create" - "rake db:schema:load" - "rspec spec --tag fixture" diff --git a/features/comments.feature b/features/comments.feature index a414be3f4..1cd419832 100644 --- a/features/comments.feature +++ b/features/comments.feature @@ -8,17 +8,7 @@ Feature: commenting Given a user named "Bob Jones" with email "bob@bob.bob" And a user named "Alice Smith" with email "alice@alice.alice" And a user with email "bob@bob.bob" is connected with "alice@alice.alice" - When I sign in as "alice@alice.alice" - And I am on the home page - And I expand the publisher - And I attach the file "spec/fixtures/button.png" to hidden element "file" within "#file-upload" - And I fill in "status_message_fake_text" with "Look at this dog" - And I press "Share" - And I wait for the ajax to finish - And I follow "Your Aspects" - Then I should see "Look at this dog" within ".stream_element" - And I should see a "img" within ".stream_element div.photo_attachments" - Then I log out + When "alice@alice.alice" has posted a status message with a photo Scenario: comment on a post from within a user's stream When I sign in as "bob@bob.bob" diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index 1210a8bd2..2f993a650 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -152,3 +152,12 @@ And /^I follow the "([^\"]*)" link from the Devise.mailer$/ do |link_text| path = link.attributes["href"].value visit URI::parse(path).request_uri end + +When /^"([^\"]+)" has posted a status message with a photo$/ do |email| + user = User.find_for_database_authentication(:username => email) + post = Factory(:status_message_with_photo, :text => "Look at this dog", :author => user.person) + [post, post.photos.first].each do |p| + user.add_to_streams(p, user.aspects) + user.dispatch_post(p) + end +end diff --git a/spec/factories.rb b/spec/factories.rb index e07fc0708..da550151b 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -76,6 +76,22 @@ Factory.define(:status_message) do |m| end end +Factory.define(:status_message_with_photo, :parent => :status_message) do |m| + m.sequence(:text) { |n| "There are #{n} ninjas in this photo." } + m.after_build do |m| + p = Factory(:photo, :author => m.author, :status_message => m, :pending => false) + end +end + +Factory.define(:photo) do |p| + p.sequence(:random_string) {|n| ActiveSupport::SecureRandom.hex(10) } + p.after_build do |p| + p.unprocessed_image.store! File.open(File.join(File.dirname(__FILE__), 'fixtures', 'button.png')) + p.process + p.update_remote_path + end +end + Factory.define :service do |service| service.nickname "sirrobertking" service.type "Services::Twitter"