Skip to content

Instantly share code, notes, and snippets.

@bryanaknight
Created December 11, 2013 21:30
Show Gist options
  • Save bryanaknight/7918800 to your computer and use it in GitHub Desktop.
Save bryanaknight/7918800 to your computer and use it in GitHub Desktop.
Cart test
describe "adding items and viewing cart" do
it "has unique cart for each restaurant" do
new_restaurant = FactoryGirl.create(:restaurant)
new_item = FactoryGirl.create(:item, restaurant_id: new_restaurant.id)
visit "/#{new_restaurant.slug}"
click_on('Add to Cart')
expect(page).to have_content("Bacon")
new_restaurant2 = FactoryGirl.create(:restaurant, title: "Parsley", description: "blah balh")
new_item2 = FactoryGirl.create(:item, restaurant_id: new_restaurant2.id, title: "brown fried food", description: "fried brown food")
visit "/#{new_restaurant2.slug}"
click_on('Add to Cart')
expect(page).to have_no_content("Bacon")
expect(page).to have_content("fried brown food")
end
it "cart holds unsubmitted order for current restaurant after visiting different restaurant" do
new_restaurant = FactoryGirl.create(:restaurant)
new_item = FactoryGirl.create(:item, restaurant_id: new_restaurant.id)
visit "/#{new_restaurant.slug}"
click_on('Add to Cart')
expect(page).to have_content("Bacon")
new_restaurant2 = FactoryGirl.create(:restaurant, title: "Parsley", description: "blah balh")
new_item2 = FactoryGirl.create(:item, restaurant_id: new_restaurant2.id, title: "brown fried food", description: "fried brown food")
visit "/#{new_restaurant2.slug}"
click_on('Add to Cart')
expect(page).to have_no_content("Bacon")
expect(page).to have_content("fried brown food")
visit '/'
visit "/#{new_restaurant.slug}"
click_on('View Items in Cart: 1')
expect(page).to have_content("Bacon")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment