Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Luke's takeaway challenge pull request #2224

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

# Local cache of Rubocop remote config
.rubocop-*
twilio.env
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ ruby '3.0.2'

group :test do
gem 'rspec'
gem 'simplecov', require: false, group: :test
gem 'simplecov-console', require: false, group: :test
gem 'simplecov', require: false
gem 'simplecov-console', require: false
gem 'simplecov-shields-badge', require: false
end

group :development, :test do
gem 'rubocop', '1.20'
gem 'twilio-ruby'
end
39 changes: 39 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,39 @@ GEM
ast (2.4.2)
diff-lcs (1.4.4)
docile (1.4.0)
faraday (1.10.0)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0)
faraday-multipart (~> 1.0)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.0)
faraday-patron (~> 1.0)
faraday-rack (~> 1.0)
faraday-retry (~> 1.0)
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-multipart (1.0.3)
multipart-post (>= 1.2, < 3)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
jwt (2.3.0)
mini_portile2 (2.8.0)
multipart-post (2.1.1)
nokogiri (1.13.4)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
parallel (1.20.1)
parser (3.0.2.0)
ast (~> 2.4.1)
racc (1.6.0)
rainbow (3.0.0)
regexp_parser (2.1.1)
rexml (3.2.5)
Expand Down Expand Up @@ -36,6 +66,7 @@ GEM
rubocop-ast (1.11.0)
parser (>= 3.0.1.1)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
Expand All @@ -45,9 +76,15 @@ GEM
simplecov
terminal-table
simplecov-html (0.12.3)
simplecov-shields-badge (0.1.0)
simplecov (~> 0.15)
simplecov_json_formatter (0.1.3)
terminal-table (3.0.1)
unicode-display_width (>= 1.1.1, < 3)
twilio-ruby (5.66.2)
faraday (>= 0.9, < 2.0)
jwt (>= 1.5, <= 2.5)
nokogiri (>= 1.6, < 2.0)
unicode-display_width (2.0.0)

PLATFORMS
Expand All @@ -58,6 +95,8 @@ DEPENDENCIES
rubocop (= 1.20)
simplecov
simplecov-console
simplecov-shields-badge
twilio-ruby

RUBY VERSION
ruby 3.0.2p107
Expand Down
130 changes: 65 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
Takeaway Challenge
==================
# Takeaway

[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
[![Coverage](./badge.svg)](https://github.com/lukestorey95/takeaway-challenge)

This program allows the user to order a takeaway, and receive a confirmation text informing them when to expect delivery. It uses a takeaway controller, order system, menu that loads dishes from a .csv file and TwilioAPI to send the text messages.

<br>

## Installation

```
_________
r== | |
_ // | M.A. | ))))
|_)//(''''': | |
// \_____:_____.-------D )))))
// | === | / \
.:'//. \ \=| \ / .:'':./ )))))
:' // ': \ \ ''..'--:'-.. ':
'. '' .' \:.....:--'.-'' .'
':..:' ':..:'

```

Instructions
-------

* Feel free to use google, your notes, books, etc. but work on your own
* If you refer to the solution of another coach or student, please put a link to that in your README
* If you have a partial solution, **still check in a partial solution**
* You must submit a pull request to this repo with your code by 9am Monday morning

Task
-----

* Fork this repo
* Run the command 'bundle' in the project directory to ensure you have all the gems
* Write a Takeaway program with the following user stories:
$ git clone https://github.com/lukestorey95/takeaway-challenge.git

$ cd takeaway-challenge

$ bundle

$ source ./twilio.env
```
As a customer
So that I can check if I want to order something
I would like to see a list of dishes with prices

As a customer
So that I can order the meal I want
I would like to be able to select some number of several available dishes
<br>

As a customer
So that I can verify that my order is correct
I would like to check that the total I have been given matches the sum of the various dishes in my order
## Quickstart

As a customer
So that I am reassured that my order will be delivered on time
I would like to receive a text such as "Thank you! Your order was placed and will be delivered before 18:52" after I have ordered
```
$ irb

* Hints on functionality to implement:
* Ensure you have a list of dishes with prices
* The text should state that the order was placed successfully and that it will be delivered 1 hour from now, e.g. "Thank you! Your order was placed and will be delivered before 18:52".
* The text sending functionality should be implemented using Twilio API. You'll need to register for it. It’s free.
* Use the twilio-ruby gem to access the API
* Use the Gemfile to manage your gems
* Make sure that your Takeaway is thoroughly tested and that you use mocks and/or stubs, as necessary to not to send texts when your tests are run
* However, if your Takeaway is loaded into IRB and the order is placed, the text should actually be sent
* Note that you can only send texts in the same country as you have your account. I.e. if you have a UK account you can only send to UK numbers.
> Dir['./lib/*.rb'].each {|file| require file }

* Advanced! (have a go if you're feeling adventurous):
* Implement the ability to place orders via text message.
> takeaway = Takeaway.new

* A free account on Twilio will only allow you to send texts to "verified" numbers. Use your mobile phone number, don't worry about the customer's mobile phone.
> takeaway.display_menu

> :warning: **WARNING:** think twice before you push your **mobile number** or **Twilio API Key** to a public space like GitHub :eyes:
>
> :key: Now is a great time to think about security and how you can keep your private information secret. You might want to explore environment variables.
> takeaway.add_to_order({ pizza: 9.50 })

* Finally submit a pull request before Monday at 9am with your solution or partial solution. However much or little amount of code you wrote please please please submit a pull request before Monday at 9am
> takeaway.check_order

> takeaway.place_order
```

In code review we'll be hoping to see:
<br>

* All tests passing
* High [Test coverage](https://github.com/makersacademy/course/blob/main/pills/test_coverage.md) (>95% is good)
* The code is elegant: every class has a clear responsibility, methods are short etc.
## Running Tests

Reviewers will potentially be using this [code review rubric](docs/review.md). Referring to this rubric in advance will make the challenge somewhat easier. You should be the judge of how much challenge you want this at this moment.
```
$ rspec

Notes on Test Coverage
------------------
# The integration test is pending as running it will public send a text (costs 6p per text)
```

You can see your [test coverage](https://github.com/makersacademy/course/blob/main/pills/test_coverage.md) when you run your tests.
<br>

## My Process

1. Break down user stories into objects, attributes and behaviour
2. Feature test and note down errors/expected errors
3. Write failing test that replicates errors
4. Write the minimum code to make test pass
5. Refactor and ensure tests still pass
6. Repeat step 2 and ensure behaviour works as intended

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like your readme. It sets a tone for the rest of the code.

<br>

## User Stories

```
As a customer
So that I can check if I want to order something
I would like to see a list of dishes with prices

As a customer
So that I can order the meal I want
I would like to be able to select some number of several available dishes

As a customer
So that I can verify that my order is correct
I would like to check that the total I have been given matches the sum of the various dishes in my order

As a customer
So that I am reassured that my order will be delivered on time
I would like to receive a text such as "Thank you! Your order was placed and will be delivered before 18:52" after I have ordered
```
6 changes: 6 additions & 0 deletions assets/dishes.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name, price, available
pizza, 9.50,true
pasta, 8.20,true
tiramisu, 4.50,false
calamari, 7.80,true
risotto, 6.90,true
1 change: 1 addition & 0 deletions badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 71 additions & 0 deletions diagram.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Diagram

```
Takeaway
@menu Menu
@current_order Order

display_menu
should instruct Menu to display available dishes

add_to_order(dishes)
when at least one item is chosen
when all the dishes match dishes on the Menu
should instruct

when not all the dishes match dishes on the Menu
should raise error

when no dishes are not provided
should raise error

place_order
when current_order and basket are not empty
should change current_order order_complete from false to true
should instruct Text to send_text

when current_order basket are empty
should raise error

Order
@basket []
@order_total_price 0.00
@order_complete false
@order_placed_time Time

add_to_basket
should change basket by number of dishes

check_order_total_matches_item_total
when basket are not empty
should return list of basket, prices and order_total_price

when basket are empty
should raise error

Menu
@dishes_menu [{ name: “”, price: 0.00, available: true}]

display_available_dishes
when dishes_menu contains available dishes
should return list of available dishes names and prices

when dishes_menu is empty
should raise error

import_dishes
when dishes are not empty
should change dishes_menu by at least 1

when dishes are empty
should raise error

Text
ORDER_CONFIRMATION_MESSAGE

@client Twilio::REST::Client
@message_body “”

send_text
should instruct client with message_body and order_placed_time
```
50 changes: 50 additions & 0 deletions lib/menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'csv'

class Menu
attr_reader :dishes, :available_dishes

def initialize(dishes_file = "./assets/dishes.csv")
@dishes = []
load_dishes(dishes_file)

@available_dishes = filter_dishes_by_available
end

def display_available_dishes
available_dishes
end

private

attr_writer :dishes, :available_dishes

def load_dishes(dishes_file)
CSV.foreach(dishes_file, headers: true, header_converters: :symbol) do |row|
name, price, available = row[:name], row[:price], row[:available]

@dishes << { name: name.to_sym, price: price.to_f, available: true?(available) }
end
end

def true?(available)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend adding more context to this method name, eg. is_available? rather than just true?

available == "true"
end

def filter_dishes_by_available
self.available_dishes = dishes.select do |dish|
dish[:available] == true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The functionality around whether a dish is available or not is adding a slight degree of complexity that isn't asked for in the spec - do try to keep your implementation as simple as possible by following the spec closely. I think the 'available'ness mentioned in the user story simply refers to dishes that are on sale at the restaurant.

end

format_available_dishes
end

def format_available_dishes
formatted_available_dishes = {}

self.available_dishes = available_dishes.each do |dish|
formatted_available_dishes.merge!(dish[:name] => dish[:price])
end

formatted_available_dishes
end
end
Loading