Skip to content

Commit

Permalink
issue #112 - adjusted pluralize, added additional ingredient test
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhutch committed Jun 8, 2017
1 parent e7d03b6 commit 875c80c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ def pluralize_ingredient(i)
%Q|<div class="measurement">#{pluralize(i.numeric_amount, i.unit)}</div>
<div class="name">#{i.name}</div>|
else
%Q|<div class="measurement">#{i.numeric_amount}</div>
<div class="name">#{i.name.pluralize(i.numeric_amount)}</div>|
if i.name.split.count > 1
%Q|<div class="measurement">#{i.numeric_amount}</div>
<div class="name">#{i.name}</div>|
else
%Q|<div class="measurement">#{i.numeric_amount}</div>
<div class="name">#{i.name.pluralize(i.numeric_amount)}</div>|
end
end
end

Expand Down
7 changes: 7 additions & 0 deletions spec/models/meal_plan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
let(:recipe2) { FactoryGirl.create(:recipe, user: user1, ingredients_block: %Q|5 tbsp soy sauce
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(:mealplan1) { FactoryGirl.create(:meal_plan, user: user1) }

it "doesn't crash when subtracting a recipe with a weird unit" do
Expand All @@ -20,6 +21,12 @@
expect(mealplan1).to be_valid
end

it "doesn't invent weird units" do
mealplan1.recipes << recipe3
ingredient = mealplan1.recipes.first.ingredients.first
expect(ingredient.unit).to be_nil
end

it "doesn't crash when trying to add incompatible units" do
mealplan1.recipes << recipe1
mealplan1.recipes << recipe2
Expand Down

0 comments on commit 875c80c

Please sign in to comment.