Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ruby '2.1.1'

gem 'rack', '~> 1.5.2'
gem "puma", "~> 2.8.1"
gem "timecop", "~> 0.7.1"

gem 'rspec', group: [:development, :test]

Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ GEM
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6)
timecop (0.7.1)
xpath (2.0.0)
nokogiri (~> 1.3)

Expand All @@ -40,3 +41,4 @@ DEPENDENCIES
puma (~> 2.8.1)
rack (~> 1.5.2)
rspec
timecop (~> 0.7.1)
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ You can find them in the `spec/features` directory.

## Development

NOTE: Whenever you change a ruby file, you need to stop the server, and restart it.
NOTE: Whenever you change a ruby file, you need to stop the server, and restart it.

#Staging

URL: git@heroku.com:lit-reaches-1754.git
5 changes: 0 additions & 5 deletions Rakefile

This file was deleted.

10 changes: 5 additions & 5 deletions config/menu.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name,price,description,image
Channa Masala,5.95,Yummy goodness,food1.jpg
Chicken Tikka Masala,5.95,Yummy goodness,food2.jpg
Saag Paneer,5.95,Yummy goodness,food3.jpg
Alu Gobi,5.95,Yummy goodness,food4.jpg
name,price,description,image, day
Channa Masala,5.95,Yummy goodness,food1.jpg, monday
Chicken Tikka Masala,5.95,Yummy goodness,food2.jpg, tuesday
Saag Paneer,5.95,Yummy goodness,food3.jpg, wednesday
Alu Gobi,5.95,Yummy goodness,food4.jpg, thursday
4 changes: 3 additions & 1 deletion lib/app.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'erb'
require 'menu'

class App
def call(env)
Expand All @@ -20,7 +21,8 @@ def body
if File.exist?(index_html)
File.open(index_html, File::RDONLY)
else
[ERB.new(File.open(index_erb, File::RDONLY).read).result]
file_contents = File.open(index_erb, File::RDONLY).read
[ERB.new(file_contents).result]
end
end
end
41 changes: 41 additions & 0 deletions lib/item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Item
def initialize(name, price, description, image, day)
@name = name
@price = price
@description = description
@image = image
@day = day

end

def name
@name
end

def price(day = Date.today)
if day.wednesday?
(Float(@price)*0.9).round(2).to_s
end
else
@price
end

def description
@description
end

def image
@image
end

def day
@day
end

def == (other)
self.name == other.name
self.price == other.price
self.description == other.description
self.image == other.image
end
end
16 changes: 16 additions & 0 deletions lib/menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'item'
require 'csv'

class Menu
def items
csv_data = CSV.read("config/menu.csv", headers: true)

array = []
csv_data.each do |row|
array.push(Item.new(row["name"], row["price"], row["description"], row["image"], row["day"]))

end
array
end
end

11 changes: 5 additions & 6 deletions public/index.html → public/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@
<img src="/images/food1.jpg">

<dl>
<dt>Channa Masala - 5.95</dt>
<dd>Yummy goodness</dd>

<dt>Chicken Tikka Masala - 5.95</dt>
<dd>Yummy goodness</dd>
<% Menu.new.items.each do |item| %>
<dt><%= item.name %> - <%= item.price%></dt>
<dd><%= item.description %> </dd>
<% end %>
</dl>
</main>

Expand All @@ -45,7 +44,7 @@
Boulder, CO 80301
<a href="mailto:bob@example.com">Contact Us</a>
</address>
&copy; 2013
&copy; <%= Date.today.year %>
</footer>

</body>
Expand Down
12 changes: 9 additions & 3 deletions spec/features/homepage_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
require 'spec_helper'

describe 'Visiting the home page' do

it "displays all of the menu items" do
visit "/"
expect(page).to have_content("Channa Masala")
expect(page).to have_content("Chicken Tikka Masala")
end

end

it "displays the current year for the copyright" do
visit "/"
within("footer") do
expect(page).to have_content("2014")
end
end
end
36 changes: 36 additions & 0 deletions spec/models/item_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'spec_helper'
require 'item'

attr_reader = :name, :description, :image, :day

describe Item do
it 'has a name' do
item = Item.new("Channa Masala", "5.95", "Yummy goodness", "food1.jpg", "monday")

expect(item.name).to eq "Channa Masala"
end
it 'has a price' do
item = Item.new("Channa Masala", "5.95", "Yummy goodness", "food1.jpg", "monday")

expect(item.price).to eq "5.95"
end
it 'has a description' do
item = Item.new("Channa Masala", "5.95", "Yummy goodness", "food1.jpg", "monday" )

expect(item.description).to eq "Yummy goodness"
end
it 'has an image' do
item = Item.new("Channa Masala", "5.95", "Yummy goodness", "food1.jpg", "monday")

expect(item.image).to eq "food1.jpg"
end
it 'knows that two items are the same if they have the same attributes' do
item1 = Item.new("Channa Masala", "5.95", "Yummy goodness", "food1.jpg", "monday")
item2 = Item.new("Channa Masala", "5.95", "Yummy goodness", "food1.jpg", "monday")

expect(item1).to eq item2
end

end


18 changes: 18 additions & 0 deletions spec/models/menu_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'spec_helper'
require 'item'
require 'menu'

describe Menu do
it 'knows about the items adds two more rows of items' do
menu = Menu.new

expect(menu.items).to match_array [
Item.new("Channa Masala", "5.95", "Yummy goodness", "food1.jpg", "monday"),
Item.new("Chicken Tikka Masala", "5.95", "Yummy goodness", "food2.jpg", "tuesday"),
Item.new("Saag Paneer", "5.95", "Yummy goodness", "food3.jpg", "wednesday"),
Item.new("Alu Gobi", "5.95", "Yummy goodness", "food4.jpg", "thursday"),
]
end

end