generated from microverseinc/readme-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from demesameneshoa/feature/food-list-and-form
Issue #13 🎫: Food list and form
- Loading branch information
Showing
11 changed files
with
220 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,9 @@ | ||
<div id="<%= dom_id food %>"> | ||
<p> | ||
<strong>Name:</strong> | ||
<%= food.name %> | ||
</p> | ||
|
||
<p> | ||
<strong>Measurement unit:</strong> | ||
<%= food.measurement_unit %> | ||
</p> | ||
|
||
<p> | ||
<strong>Price:</strong> | ||
<%= food.price %> | ||
</p> | ||
|
||
<p> | ||
<strong>Quantity:</strong> | ||
<%= food.quantity %> | ||
</p> | ||
|
||
<p> | ||
<strong>User:</strong> | ||
<%= food.user_id %> | ||
</p> | ||
|
||
</div> | ||
<tr> | ||
<td><%= food.name %></td> | ||
<td><%= food.measurement_unit %></td> | ||
<td><%= "$#{food.price}" %></td> | ||
<td><%= "#{food.quantity}#{food.measurement_unit}" %></td> | ||
<td><%= button_to "Delete", food, | ||
method: :delete, | ||
class: "btn btn-outline-danger px-2 py-1" %></td> | ||
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,32 @@ | ||
<p style="color: green"><%= notice %></p> | ||
<main class='container mt-4' style="max-width: 900px;"> | ||
|
||
<h1>Foods</h1> | ||
<div id="foods"> | ||
<div class="p-2" style="text-align: end;"> | ||
<%= link_to "New food", new_food_path, class: "btn btn-outline-primary m-1" %> | ||
</div> | ||
<% if @foods.empty? %> | ||
<div class="alert alert-info text-center"> | ||
<p class="mb-0">There are no foods in your inventory.</p> | ||
</div> | ||
<% else %> | ||
<table class="table table-hover table-striped border"> | ||
<thead> | ||
<tr> | ||
<th>Food</th> | ||
<th>Measurement unit</th> | ||
<th>Unit Price</th> | ||
<th>Quantity</th> | ||
<th>Actions</th> | ||
</tr> | ||
</thead> | ||
|
||
<div id="foods"> | ||
<% @foods.each do |food| %> | ||
<%= render food %> | ||
<p> | ||
<%= link_to "Show this food", food %> | ||
</p> | ||
<% end %> | ||
</div> | ||
<tbody> | ||
<% @foods.each do |food| %> | ||
<%= render food %> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<% end %> | ||
</div> | ||
</main> | ||
|
||
<%= link_to "New food", new_food_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
<h1>New food</h1> | ||
<h2 class="text-muted text-center mb-4">Add a new item to inventory</h2> | ||
<div style="max-width: 400px; margin: 0 auto;" class="mb-3"> | ||
|
||
<%= render "form", food: @food %> | ||
<%= render "form", food: @food %> | ||
|
||
<br> | ||
<br> | ||
|
||
<div> | ||
<%= link_to "Back to foods", foods_path %> | ||
</div> | ||
<div> | ||
<%= link_to "Back to food list", foods_path, class: "btn btn-secondary px-2 py-1" %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
require 'faker' | ||
|
||
FactoryBot.define do | ||
factory :food do | ||
name { 'MyString' } | ||
measurement_unit { 'MyString' } | ||
price { '9.99' } | ||
name { Faker::Food.ingredient } | ||
measurement_unit { 'kg' } | ||
price { 1.5 } | ||
quantity { 1 } | ||
user { nil } | ||
user { create(:user) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
require 'faker' | ||
|
||
FactoryBot.define do | ||
factory :user do | ||
name { Faker::Name.name } | ||
email { Faker::Internet.email } | ||
password { '123456' } | ||
password_confirmation { '123456' } | ||
confirmed_at { Time.zone.now } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,70 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Food, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
let(:food) { build(:food) } # ! non persisting object. It's not saved in the database. | ||
|
||
describe 'validations' do | ||
context 'object itself' do | ||
it 'should be valid' do | ||
expect(food).to be_valid | ||
end | ||
end | ||
|
||
context 'name validations' do | ||
it 'should be valid' do | ||
expect(food.name).to be_present | ||
end | ||
|
||
it 'should be invalid' do | ||
food.name = nil | ||
expect(food).to_not be_valid | ||
end | ||
end | ||
|
||
context 'measurement_unit validations' do | ||
it 'should be valid' do | ||
expect(food.measurement_unit).to be_present | ||
expect(food.measurement_unit).to be_in(%w[mg g kg l ml]) | ||
end | ||
|
||
it 'should be invalid' do | ||
food.measurement_unit = nil | ||
expect(food).to_not be_valid | ||
end | ||
end | ||
|
||
context 'price validations' do | ||
it 'should be valid' do | ||
expect(food.price).to be_present | ||
expect(food.price).to be_a(BigDecimal) | ||
expect(food.price).to be > 0 | ||
end | ||
|
||
it 'should be invalid' do | ||
food.price = nil | ||
expect(food).to_not be_valid | ||
end | ||
end | ||
|
||
context 'quantity validations' do | ||
it 'should be valid' do | ||
expect(food.quantity).to be_present | ||
expect(food.quantity).to be_a(Integer) | ||
expect(food.quantity).to be > 0 | ||
end | ||
|
||
it 'should be invalid' do | ||
food.quantity = nil | ||
expect(food).to_not be_valid | ||
end | ||
end | ||
|
||
context 'total_price validations' do | ||
it 'should be valid' do | ||
expect(food.total_price).to be_present | ||
expect(food.total_price).to be_a(BigDecimal) | ||
expect(food.total_price).to be > 0 | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.