Skip to content

Commit

Permalink
Issue #112 - added Pry for debugging, wrote a shit-ton more tests to …
Browse files Browse the repository at this point in the history
…try to find the source of the remaining failed test. No dice.
  • Loading branch information
johnhutch committed Jun 14, 2017
1 parent a6812e1 commit 1e5481f
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ group :development, :test do
gem 'rb-readline', '~> 0.5.3' #add inline readline support for guard
gem 'terminal-notifier-guard', '~> 1.7.0' # add mac os x notifications on guard runs. be sure to brew install terminal-notifier
gem 'email_spec', '~> 2.1.0' # adds matchers for various email tests
gem 'pry'
gem 'pry-nav'
gem 'pry-stack_explorer'
end

group :development do
Expand Down
10 changes: 9 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ GEM
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-nav (0.2.4)
pry (>= 0.9.10, < 0.11.0)
pry-stack_explorer (0.4.9.2)
binding_of_caller (>= 0.7)
pry (>= 0.9.11)
public_suffix (2.0.5)
puma (3.6.2)
rack (2.0.1)
Expand Down Expand Up @@ -298,6 +303,9 @@ DEPENDENCIES
letter_opener (~> 1.4.1)
listen (~> 3.0.5)
pg (~> 0.19.0)
pry
pry-nav
pry-stack_explorer
puma (~> 3.0)
rails (~> 5.0.0, >= 5.0.0.1)
rails-controller-testing
Expand All @@ -318,4 +326,4 @@ RUBY VERSION
ruby 2.3.1p112

BUNDLED WITH
1.14.3
1.15.1
7 changes: 7 additions & 0 deletions spec/features/meal_plans_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
let(:recipe) { FactoryGirl.create(:recipe, user: user1) }
let(:recipe2) { FactoryGirl.create(:recipe, user: user1) }
let(:recipe3) { FactoryGirl.create(:recipe, user: user1) }
let(:recipe4) { FactoryGirl.create(:recipe, user: user1, ingredients_block: %Q|5 tbsp soy sauce
4 tbsp mild or hot chili powder
3 tbsp five-spice powder
2 tbsp light muscovado sugar
2 cloves garlic, finely chopped
4 cm piece of fresh ginger, peeled and finely chopped
6 1/2 lbs boneless pork shoulder, rind removed|) }
let(:mealplan1) { FactoryGirl.create(:meal_plan, user: user1) }

describe "The meal plan show page" do
Expand Down
10 changes: 8 additions & 2 deletions spec/models/ingredient_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
let(:ingredient2) { FactoryGirl.create(:ingredient, parent: recipe2) }
let(:ingredient3) { FactoryGirl.create(:ingredient, parent: recipe2, amount: 4) }
let(:ing_liter) { FactoryGirl.create(:ingredient, parent: recipe2, unit: "liter", amount: 4) }
let(:ing_unitless) { FactoryGirl.create(:ingredient, parent: recipe2, unit: nil, amount: 4) }
let(:ing_unitless1) { FactoryGirl.create(:ingredient, parent: recipe2, unit: nil, amount: 4) }
let(:ing_unitless2) { FactoryGirl.create(:ingredient, parent: recipe2, unit: nil, amount: 3) }

it "is valid with valid attributes" do
expect(Ingredient.new(name: ingredient1.name, parent: recipe1)).to be_valid
Expand All @@ -28,14 +29,19 @@
end

it "returns false if trying to add to nil unit'd ingredient to a unit'd ingredient" do
expect(ing_unitless.sum(ingredient2)).to eq false
expect(ing_unitless1.sum(ingredient2)).to eq false
end

it "subtracts two compatibly unit'd ingredients" do
ingredient3.sub(ingredient2)
expect(ingredient3.unitized_amount.to_s.partition(" ").first).to eq "2.5"
end

it "subtracts two unitless ingredients" do
ing_unitless1.sub(ing_unitless2)
expect(ing_unitless1.unitized_amount.to_s.partition(" ").first).to eq "1"
end

it "returns false if trying to subtract equal to or more than the amount available" do
expect(ingredient1.sub(ingredient2)).to eq false
end
Expand Down
60 changes: 59 additions & 1 deletion spec/models/meal_plan_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

RSpec.describe GroceryList, type: :model do
RSpec.describe MealPlan, type: :model do
let(:user1) {FactoryGirl.create(:user)}
let(:recipe1) { FactoryGirl.create(:recipe, user: user1, ingredients_block: %Q|5 tbsp soy sauce
4 tbsp mild or hot chili powder
Expand All @@ -13,6 +13,10 @@
4 grams mild or hot chili powder
6 1/2 lbs boneless pork shoulder, rind removed|) }
let(:recipe3) { FactoryGirl.create(:recipe, user: user1, ingredients_block: %Q|2 cloves garlic, finely chopped| ) }
let(:recipe_unitless_1) { FactoryGirl.create(:recipe, user: user1, ingredients_block: "1 apple") }
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(:mealplan1) { FactoryGirl.create(:meal_plan, user: user1) }

it "doesn't crash when subtracting a recipe with a weird unit" do
Expand All @@ -34,4 +38,58 @@
expect(mealplan1).to be_valid
end

it "creates a user's grocery list when adding to the mealplan" do
mealplan1.recipes << recipe1
expect(mealplan1.user.grocery_list).to be_valid
end

it "adds a recipe's ingredients to a user's grocery list when adding a recipe to a user's mealplan" do
mealplan1.recipes << recipe1
list_ing = mealplan1.user.grocery_list.ingredients.first
expect(list_ing.unitized_amount).to eq recipe1.ingredients.first.unitized_amount
end

it "sums a recipe's ingredients to a user's grocery list when adding a recipe to a user's mealplan" do
mealplan1.recipes << recipe1
mealplan1.recipes << recipe2
list_ing = mealplan1.user.grocery_list.ingredients.first
expect(list_ing.amount).to eq (recipe1.ingredients.first.amount.to_i + recipe2.ingredients.first.amount.to_i).to_s
end

it "sums a recipe's unitless ingredients to a user's grocery list when adding a recipe to a user's mealplan" do
mealplan1.recipes << recipe_unitless_1
mealplan1.recipes << recipe_unitless_2
list_ing = mealplan1.user.grocery_list.ingredients.first
expect(list_ing.amount).to eq (recipe_unitless_1.ingredients.first.amount.to_i + recipe_unitless_2.ingredients.first.amount.to_i).to_s
end

it "tries to sum a unitless with a unit'd ingredient, but can't, so it just adds the unitless one" do
mealplan1.recipes << recipe_unitless_2
mealplan1.recipes << recipe5
list_ing = mealplan1.user.grocery_list.ingredients.last
expect(list_ing.unitized_amount).to eq recipe5.ingredients.first.unitized_amount
end

it "subtracts compatibly unit'd ingredients from a user's grocery list when a recipe is removed from their meal plan." do
mealplan1.recipes << recipe5
mealplan1.recipes << recipe6
mealplan1.recipes.delete(recipe5)
expect(mealplan1.user.grocery_list.ingredients.first.unitized_amount).to eq recipe6.ingredients.first.unitized_amount
end

it "subtracts compatibly unitless ingredients from a user's grocery list when a recipe is removed from their meal plan." do
mealplan1.recipes << recipe_unitless_1
mealplan1.recipes << recipe_unitless_2
mealplan1.recipes.delete(recipe_unitless_1)
expect(mealplan1.user.grocery_list.ingredients.first.unitized_amount).to eq recipe_unitless_2.ingredients.first.unitized_amount
end

it "skips incompatibly unit'd ingredients on from a user's grocery list when a recipe is removed from their meal plan, and just removes the correct ingredient." do
mealplan1.recipes << recipe5
mealplan1.recipes << recipe_unitless_1
mealplan1.recipes.delete(recipe5)
expect(mealplan1.user.grocery_list.ingredients.first.unitized_amount).to eq recipe_unitless_1.ingredients.first.unitized_amount
expect(mealplan1.user.grocery_list.ingredients.first.unitized_amount).to_not eq recipe5.ingredients.first.unitized_amount
end

end

0 comments on commit 1e5481f

Please sign in to comment.