Skip to content

Commit

Permalink
issue #112 moved ingredients delete call to an else block, build a cu…
Browse files Browse the repository at this point in the history
…stom matcher for collections, rewrote test that involved removing a recipe and not losing particular ingredients in the current grocery list
  • Loading branch information
jon-athan-hall committed Jun 20, 2017
1 parent ac61e98 commit cc409b5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/models/grocery_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ def subtract_ingredient(sub_i)
if list_i.matched?(sub_i)
if list_i.sub(sub_i)
return true
else
return self.ingredients.delete(list_i)
end
end
return self.ingredients.delete(list_i)
end
end

Expand Down
6 changes: 5 additions & 1 deletion spec/models/meal_plan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@
mealplan1.recipes << recipe7
mealplan1.recipes << recipe9
mealplan1.recipes.delete(recipe7)
expect(mealplan1.user.grocery_list.ingredients).to eq recipe7.ingredients.first
expect(mealplan1.user.grocery_list.ingredients).to contain_one_or_more_records_that(have_attributes(
:unit => recipe7.ingredients.first.unit,
:amount => recipe7.ingredients.first.amount,
:name => recipe7.ingredients.first.name)
)
end

end
8 changes: 8 additions & 0 deletions spec/support/custom_matchers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Helps to loop through a collection in search of one particular item that matches.
RSpec::Matchers.define :contain_one_or_more_records_that do |matcher|
match do |collection|
collection.any? do |item|
matcher.matches?(item)
end
end
end

0 comments on commit cc409b5

Please sign in to comment.