-
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
Gawain Hewitt Takeaway challenge #2235
base: main
Are you sure you want to change the base?
Changes from 1 commit
0909b51
8883752
9c5f633
ca00cf9
00e89d8
124e7f0
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 |
---|---|---|
@@ -1,83 +1,34 @@ | ||
Takeaway Challenge | ||
================== | ||
``` | ||
_________ | ||
r== | | | ||
_ // | M.A. | )))) | ||
|_)//(''''': | | | ||
// \_____:_____.-------D ))))) | ||
// | === | / \ | ||
.:'//. \ \=| \ / .:'':./ ))))) | ||
:' // ': \ \ ''..'--:'-.. ': | ||
'. '' .' \:.....:--'.-'' .' | ||
':..:' ':..:' | ||
# FAKE-AWAY | ||
|
||
``` | ||
This is Gawain Hewitt's weekend challenge for Makers Academy week 2, the takeaway challenge. | ||
|
||
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 | ||
[Process Followed](#process-followed) | ||
|
||
Task | ||
----- | ||
[Instructions For Use](#instructions-for-use). | ||
|
||
* 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: | ||
|
||
``` | ||
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 | ||
``` | ||
|
||
* 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. | ||
|
||
* Advanced! (have a go if you're feeling adventurous): | ||
* Implement the ability to place orders via text message. | ||
|
||
* 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. | ||
|
||
> :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. | ||
### Process Followed | ||
|
||
* 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 | ||
|
||
|
||
In code review we'll be hoping to see: | ||
|
||
* 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. | ||
|
||
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. | ||
|
||
Notes on Test Coverage | ||
------------------ | ||
|
||
You can see your [test coverage](https://github.com/makersacademy/course/blob/main/pills/test_coverage.md) when you run your tests. | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
### Instructions For Use | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
Takeaway Challenge | ||
================== | ||
``` | ||
_________ | ||
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: | ||
|
||
``` | ||
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 | ||
``` | ||
|
||
* 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. | ||
|
||
* Advanced! (have a go if you're feeling adventurous): | ||
* Implement the ability to place orders via text message. | ||
|
||
* 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. | ||
|
||
> :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. | ||
|
||
* 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 | ||
|
||
|
||
In code review we'll be hoping to see: | ||
|
||
* 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. | ||
|
||
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. | ||
|
||
Notes on Test Coverage | ||
------------------ | ||
|
||
You can see your [test coverage](https://github.com/makersacademy/course/blob/main/pills/test_coverage.md) when you run your tests. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class Menu | ||
attr_reader :contents | ||
def initialize | ||
@contents = [{food: :Chips, price: 1}, | ||
{food: :Tofu, price: 2}, {food: :Broccoli, price: 1}, | ||
{food: :Ice_cream, price: 2}] | ||
end | ||
|
||
def show | ||
@contents.each_with_index do |item, index| | ||
puts "#{index+1}. #{item[:food]} - £#{item[:price]}" | ||
end | ||
end | ||
|
||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require './lib/menu.rb' | ||
|
||
class Takeaway | ||
attr_reader :menu | ||
def initialize | ||
@menu = Menu.new | ||
end | ||
|
||
def show_menu | ||
@menu.show | ||
end | ||
|
||
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. Really impressive thought about actual user interface, certainly going beyond what is required. You have my sympathy and respect for keeping your head around it though |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'menu' | ||
|
||
describe Menu do | ||
it 'can hold dishes and prices' do | ||
expect(subject.contents[0]).to eq({food: :Chips, price: 1}) | ||
end | ||
|
||
it 'should respond to contents' do | ||
expect(subject).to respond_to(:contents) | ||
end | ||
|
||
it 'should display menu' do | ||
expect do | ||
subject.show | ||
end.to output("1. Chips - £1\n2. Tofu - £2\n3. Broccoli - £1\n4. Ice_cream - £2\n").to_stdout | ||
end | ||
|
||
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. your general ruby syntax and string-morphing is fantastic! |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'takeaway' | ||
|
||
describe Takeaway do | ||
it 'should respond to show menu' do | ||
expect(subject).to respond_to(:menu) | ||
end | ||
|
||
it 'should call display method from Menu' do | ||
expect(subject.menu).to receive(:show) | ||
subject.show_menu | ||
end | ||
|
||
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. again, already thinking about testing injection (looking at commit 1) here is very switched on. nice. took a lot of research/cheating for me to come to tests like this |
||
|
||
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'm impressed you definitely know what you're doing, especially with the corresponding tests
I'm no expert in dependency injection, but this article near the beginning
https://medium.com/@Bakku1505/introduction-to-dependency-injection-in-ruby-dc238655a278
explains how linking the classes together so "strongly" ie 'def initialize... @menu = Menu.new' can cause issues down the line