Skip to content

Instantly share code, notes, and snippets.

@brandon-beacher
Created June 21, 2011 18:32
Show Gist options
  • Save brandon-beacher/1038532 to your computer and use it in GitHub Desktop.
Save brandon-beacher/1038532 to your computer and use it in GitHub Desktop.
require 'test_helper'
class VehiclesTest < ActionDispatch::IntegrationTest
test "a brand new visitor should be able to price a vehicle" do
visit('/vehicles/new')
assert has_selector?('h3', :text => 'Vehicle Description')
vehicle = Factory.attributes_for(:vehicle)
fill_in('Mileage', :with => vehicle[:mileage])
choose('vehicle_has_more_than_one_owner_true')
choose('vehicle_is_leased_or_financed_true')
choose('vehicle_has_complete_service_records_true')
choose('vehicle_has_recently_been_to_auction_true')
choose('vehicle_has_complete_sets_of_keys_true')
choose('vehicle_is_smoky_or_smelly_true')
choose('vehicle_was_rental_car_true')
click_button('vehicle_submit')
assert has_selector?('h3', :text => 'Condition Report')
click_button('vehicle_submit')
assert has_selector?('h3', :text => 'Email Address')
user = Factory.attributes_for(:user)
fill_in('email', :with => user[:email])
click_button('vehicle_submit')
assert has_selector?('h3', :text => 'Contact Information')
fill_in('Password', :with => user[:password])
fill_in('Password confirmation', :with => user[:password])
click_button('vehicle_submit')
assert has_selector?('h3', :text => 'Confirm Vehicle')
end
test "a signed in user should be able to price a vehicle" do
user = Factory(:user)
visit("/users/sign_in")
fill_in('Email', :with => user.email)
fill_in('Password', :with => user.password)
click_button('Sign in')
click_link('Price My Car')
assert has_selector?('h3', :text => 'Vehicle Description')
vehicle = Factory.attributes_for(:vehicle)
fill_in('Mileage', :with => vehicle[:mileage])
choose('vehicle_has_more_than_one_owner_true')
choose('vehicle_is_leased_or_financed_true')
choose('vehicle_has_complete_service_records_true')
choose('vehicle_has_recently_been_to_auction_true')
choose('vehicle_has_complete_sets_of_keys_true')
choose('vehicle_is_smoky_or_smelly_true')
choose('vehicle_was_rental_car_true')
click_button('vehicle_submit')
assert has_selector?('h3', :text => 'Condition Report')
click_button('vehicle_submit')
assert has_selector?('h3', :text => 'Confirm Vehicle')
end
test "a signed out user should be able to price a vehicle" do
user = Factory(:user)
click_link('Price My Car')
assert has_selector?('h3', :text => 'Vehicle Description')
vehicle = Factory.attributes_for(:vehicle)
fill_in('Mileage', :with => vehicle[:mileage])
choose('vehicle_has_more_than_one_owner_true')
choose('vehicle_is_leased_or_financed_true')
choose('vehicle_has_complete_service_records_true')
choose('vehicle_has_recently_been_to_auction_true')
choose('vehicle_has_complete_sets_of_keys_true')
choose('vehicle_is_smoky_or_smelly_true')
choose('vehicle_was_rental_car_true')
click_button('vehicle_submit')
assert has_selector?('h3', :text => 'Condition Report')
click_button('vehicle_submit')
assert has_selector?('h3', :text => 'Email Address')
fill_in('email', :with => user.email)
click_button('vehicle_submit')
assert has_selector?('h3', :text => 'Confirm Vehicle')
end
test "a visitor should be able to recover when reporting an invalid vehicle description" do
visit('/vehicles/new')
assert has_selector?('h3', :text => 'Vehicle Description')
fill_in('Mileage', :with => '')
click_button('vehicle_submit')
assert has_content?("Mileage can't be blank")
end
test "a visitor should be able to recover when reporting an invalid vehicle condition" do
visit('/vehicles/new')
assert has_selector?('h3', :text => 'Vehicle Description')
vehicle = Factory.attributes_for(:vehicle)
fill_in('Mileage', :with => vehicle[:mileage])
choose('vehicle_has_more_than_one_owner_true')
choose('vehicle_is_leased_or_financed_true')
choose('vehicle_has_complete_service_records_true')
choose('vehicle_has_recently_been_to_auction_true')
choose('vehicle_has_complete_sets_of_keys_true')
choose('vehicle_is_smoky_or_smelly_true')
choose('vehicle_was_rental_car_true')
click_button('vehicle_submit')
assert has_selector?('h3', :text => 'Condition Report')
find('#vehicle_mileage').set('')
click_button('vehicle_submit')
assert has_content?("Mileage can't be blank")
end
test "a visitor should be able to recover when reporting invalid contact info" do
visit('/vehicles/new')
assert has_selector?('h3', :text => 'Vehicle Description')
vehicle = Factory.attributes_for(:vehicle)
fill_in('Mileage', :with => vehicle[:mileage])
choose('vehicle_has_more_than_one_owner_true')
choose('vehicle_is_leased_or_financed_true')
choose('vehicle_has_complete_service_records_true')
choose('vehicle_has_recently_been_to_auction_true')
choose('vehicle_has_complete_sets_of_keys_true')
choose('vehicle_is_smoky_or_smelly_true')
choose('vehicle_was_rental_car_true')
click_button('vehicle_submit')
assert has_selector?('h3', :text => 'Condition Report')
click_button('vehicle_submit')
assert has_selector?('h3', :text => 'Email Address')
user = Factory.attributes_for(:user)
fill_in('email', :with => user[:email])
click_button('vehicle_submit')
assert has_selector?('h3', :text => 'Contact Information')
find('#vehicle_mileage').set('')
click_button('vehicle_submit')
assert has_content?("Mileage can't be blank")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment