Skip to content

Commit

Permalink
issue #112 - managed to replicate ingredient subtraction issue in mod…
Browse files Browse the repository at this point in the history
…el test. The short circuit in the sub() function in ingredient doesn't appear to actually avoid hitting the false state where the whole ingredient is removed. Not sure why. Research required on short circuiting functions via returns in ruby.
  • Loading branch information
johnhutch committed Jun 14, 2017
1 parent 1e5481f commit ac61e98
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spec/models/meal_plan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
let(:recipe_unitless_2) { FactoryGirl.create(:recipe, user: user1, ingredients_block: "3 apples") }
let(:recipe5) { FactoryGirl.create(:recipe, user: user1, ingredients_block: "4 pounds of apples") }
let(:recipe6) { FactoryGirl.create(:recipe, user: user1, ingredients_block: "4 grams of apples") }

let(:recipe7) { FactoryGirl.create(:recipe, user: user1) }
let(:recipe8) { FactoryGirl.create(:recipe, user: user1) }
let(:recipe9) { FactoryGirl.create(:recipe, user: user1) }

let(:mealplan1) { FactoryGirl.create(:meal_plan, user: user1) }

it "doesn't crash when subtracting a recipe with a weird unit" do
Expand Down Expand Up @@ -92,4 +97,11 @@
expect(mealplan1.user.grocery_list.ingredients.first.unitized_amount).to_not eq recipe5.ingredients.first.unitized_amount
end

it "doesn't completely wipe out the grocery list in our meal plan feature spec scenario" do
mealplan1.recipes << recipe7
mealplan1.recipes << recipe9
mealplan1.recipes.delete(recipe7)
expect(mealplan1.user.grocery_list.ingredients).to eq recipe7.ingredients.first
end

end

0 comments on commit ac61e98

Please sign in to comment.