-
Notifications
You must be signed in to change notification settings - Fork 2k
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
base: main
Are you sure you want to change the base?
Changes from all commits
c53eb59
10529a7
010b192
c4e17a6
7d9a819
0ba4cd9
5fea51e
aee76f3
6597650
ef186ba
5197e8b
d33825e
d4fb845
235b77a
b75551f
385e649
6d4b97d
c31498a
9dab091
fe28775
5814093
9b58f62
a667806
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
|
||
# Local cache of Rubocop remote config | ||
.rubocop-* | ||
twilio.env |
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 | ||
|
||
<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 | ||
``` |
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 |
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 | ||
``` |
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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.