|
1 | 1 | require "rails_helper"
|
2 | 2 | RSpec.feature "Foods", type: :feature do
|
3 |
| - scenario "the food index page shows all the food" do |
4 |
| - Food.create( |
| 3 | + before(:each) do |
| 4 | + @user = User.create(first_name: "Toyosi", |
| 5 | + last_name: "Famakinde", |
| 6 | + |
| 7 | + password: "jeffrules", |
| 8 | + password_confirmation: "jeffrules", |
| 9 | + role: "admin") |
| 10 | + Category.create(title: "Entree", description: "first meal") |
| 11 | + @F1 = Food.create( |
5 | 12 | name: "Spaghetti",
|
6 | 13 | description: "Best spaghetti ever",
|
7 |
| - price: 1500.00 |
8 |
| - ) |
9 |
| - Food.create( |
10 |
| - name: "Jollof rice", |
11 |
| - description: "Hot spicy jollof ever", |
12 |
| - price: 1600.00 |
13 |
| - ) |
| 14 | + price: 1500.00 ) |
| 15 | + visit root_path |
| 16 | + |
| 17 | + click_link('Log in') |
| 18 | + expect(current_path).to eq(login_path) |
| 19 | + expect(page).to have_selector("h3", text: "Log in") |
| 20 | + fill_in "session_email", with: '[email protected]' |
| 21 | + fill_in "session_password", with: 'jeffrules' |
| 22 | + click_button('Log in') |
| 23 | + end |
| 24 | + |
| 25 | + scenario "the food index page shows all the food" do |
14 | 26 | visit foods_path
|
15 |
| - expect(page).to have_content("Jollof rice") |
16 | 27 | expect(page).to have_content("Spaghetti")
|
17 | 28 | end
|
| 29 | + |
| 30 | + scenario "admin should be able to add new food" do |
| 31 | + expect(current_path).to eq("/admin") |
| 32 | + |
| 33 | + visit("foods/new") |
| 34 | + expect(page).to have_content("Create new food") |
| 35 | + page.fill_in "food_name", :with => "Pancake n Syrup" |
| 36 | + page.fill_in "food_description", :with => "Juicy syrup on fresh home-baked pancakes" |
| 37 | + page.fill_in "food_price", :with => 100 |
| 38 | + page.fill_in "food_prep_time", :with => 12 |
| 39 | + select('Entree', from: 'food_category_id') |
| 40 | + page.attach_file('food[food_image]', Rails.root + 'app/assets/images/chicken.jpg') |
| 41 | + click_button "Add food" |
| 42 | + expect(current_path).to eq admin_foods_path |
| 43 | + |
| 44 | + expect(page).to have_content("Pancake n Syrup") |
| 45 | + |
| 46 | + end |
| 47 | + |
| 48 | + scenario "admin should edit food" do |
| 49 | + visit(admin_foods_path) |
| 50 | + click_link("Spaghetti") |
| 51 | + expect(current_path).to eq edit_food_path(@F1.id) |
| 52 | + |
| 53 | + page.fill_in "food_name", :with => "Pancake and meatballs" |
| 54 | + page.attach_file('food[food_image]', Rails.root + 'app/assets/images/chicken.jpg') |
| 55 | + |
| 56 | + click_button "Add food" |
| 57 | + expect(current_path).to eq admin_foods_path |
| 58 | + |
| 59 | + expect(page).to have_content("Pancake and meatballs") |
| 60 | + end |
| 61 | + |
| 62 | + # scenario "admin should edit food status" do |
| 63 | + # visit(admin_foods_path) |
| 64 | + # uncheck('A Checkbox') |
| 65 | + # end |
| 66 | + |
| 67 | + |
18 | 68 | end
|
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
0 commit comments