Skip to content

Instantly share code, notes, and snippets.

@ozeias
Created June 18, 2010 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozeias/443127 to your computer and use it in GitHub Desktop.
Save ozeias/443127 to your computer and use it in GitHub Desktop.
require 'test_helper'
require 'capybara'
require 'capybara/dsl'
require 'selenium-webdriver'
class UserFlowsTest < ActionController::IntegrationTest
include Capybara
def setup
Capybara.app_host = 'http://www.soundfolder.dev:3000'
Capybara.default_driver = :selenium
Capybara.default_selector = :css # instead of xpath
end
test "make a test user" do
make_roland
end
test "sign up" do
visit '/signup'
fill_in_signup_form
find('button[type=submit]').click
assert page.has_content? 'Welcome to SoundFolder'
end
test "sign up from the home page" do
logout
visit '/'
fill_in_signup_form
find('button[type=submit]').click
assert page.has_content? 'Welcome to SoundFolder'
end
test "view a user's site at a subdomain" do
Capybara.app_host = 'http://roland.soundfolder.dev:3000'
visit '/'
assert page.has_css? '#artist-header'
assert page.has_content? 'roland'
end
test "upload a track" do
login
# remove previously uploaded fixture mp3
Track.find_all_by_title('Full House').each{|track| track.destroy}
visit '/mixer'
click 'Add a new track'
attach_file('track[track]', RAILS_ROOT + 'fixtures/mp3s/id3.mp3')
click 'Add this track'
#FIXME paperclip says "empty file"
#assert page.has_content? 'Full House'
end
def fill_in_signup_form
fill_in 'user[name]', :with => Faker::Name.name
fill_in 'user[email]', :with => Faker::Internet.email
fill_in 'user[password]', :with => 'shellacofnorthamerica'
end
def make_roland
# gives us a test user.
# don't care if this fails, roland might already exist.
visit '/signup'
fill_in 'user[name]', :with => 'roland'
fill_in 'user[email]', :with => 'roland@soundfolder.com'
fill_in 'user[password]', :with => 'roland'
find('button[type=submit]').click
end
def login
logout
visit '/login'
fill_in 'email', :with => 'roland@soundfolder.com'
fill_in 'password', :with => 'roland'
click 'Log in'
end
def logout
click 'Log Out' if page.has_css? '.logged_in'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment