Skip to content

Commit

Permalink
Merge pull request #46 from RileyManda/feature/iterations
Browse files Browse the repository at this point in the history
Fixed shopping inmdex path
  • Loading branch information
RileyManda authored Oct 20, 2023
2 parents 11b7f11 + fc2e1c2 commit a1b01e7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/views/recipe/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<p>Cooking Time: <%= @recipe.cooking_time %> minutes</p>

<div class="col-md-6">
<%= link_to "Generate Shopping List", shopping_list_path, class: 'btn btn-primary', id: 'generate-shopping-list-button' %>
<%= link_to "Generate Shopping List", shopping_index_path(recipe_id: @recipe.id), class: 'btn btn-primary', id: 'generate-shopping-list-button' %>

<%= link_to "Add Ingredient", new_recipe_food_path(recipe_id: @recipe.id), class: 'btn btn-primary btn-sm' %>
</div>
Expand Down
31 changes: 31 additions & 0 deletions spec/features/shopping_index_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'rails_helper'
RSpec.feature 'Shopping List Page', type: :feature do
scenario 'user can view shopping list information' do
user = create(:user)
login_as(user, scope: :user)
# Create valid Recipe and Food records
recipe = create(:recipe)
food = create(:food)
# Create recipe foods using the recipe_food factory with valid associations
recipe_foods = [
create(:recipe_food, recipe:, food:, quantity: 100, value: 10),
create(:recipe_food, recipe:, food:, quantity: 200, value: 20)
]
visit shopping_index_path
expect(page).to have_content('Shopping List')
expect(page).to have_content("Amount of food to buy: #{recipe_foods.size}")
expect(page).to have_content("Total value of food needed: $#{recipe_foods.sum { |rf| rf.quantity * rf.value }}")
recipe_foods.each do |recipe_food|
expect(page).to have_content(recipe_food.food.name)
expect(page).to have_content("#{recipe_food.quantity}g")
expect(page).to have_content("$#{recipe_food.quantity * recipe_food.value}")
end
end
scenario 'user sees a message when there are no shopping items' do
user = create(:user)
login_as(user, scope: :user)
visit shopping_index_path
expect(page).to have_content('Shopping List')
expect(page).to have_content('No shopping list available.')
end
end

0 comments on commit a1b01e7

Please sign in to comment.