Cut 45 seconds out of the comments feature by using factories

This commit is contained in:
Raphael Sofaer 2011-07-02 13:40:30 -07:00
parent 7baeaebe57
commit 290fb1e7f5
4 changed files with 26 additions and 12 deletions

View file

@ -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"

View file

@ -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"

View file

@ -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

View file

@ -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"