From 864bf6eed461dfbc24bfc4c76bad6115dce29e15 Mon Sep 17 00:00:00 2001 From: LGretzk Date: Sat, 30 Apr 2022 17:28:33 +0100 Subject: [PATCH 01/14] Create menu.rb and menu_spec.rb files --- lib/menu.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ spec/menu_spec.rb | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 lib/menu.rb create mode 100644 spec/menu_spec.rb diff --git a/lib/menu.rb b/lib/menu.rb new file mode 100644 index 0000000000..e7d421d6e4 --- /dev/null +++ b/lib/menu.rb @@ -0,0 +1,42 @@ + +class Menu + + attr_reader :dishes + + def initialize + @dishes = [ + {id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true}, + {id: 2, name: 'Veggie Breakfast', price: 8, available?: true}, + {id: 3, name: 'Halloumi Sandwhich', price: 7, available?: true}, + {id: 4, name: 'Soup of the Day', price: 8, available?: true}, + {id: 5, name: 'Ceaser Salad', price: 8, available?: true}, + {id: 6, name: 'Pizza', price: 9, available?: true}, + {id: 7, name: 'Vegan Pizza', price: 10, available?: true}, + {id: 8, name: 'Yum Yum Salad', price: 11, available?: true}, + {id: 9, name: 'Singapore Laksa', price: 11, available?: true}, + {id: 10, name: 'Spiced Noodles', price: 11, available?: true}, + {id: 11, name: 'Phad Thai', price: 11, available?: true} + ] + end + + def display_dishes + @dishes.map { |dish| + p "#{dish[:id]}. #{dish[:name]} - £#{dish[:price]} - #{dish[:available?] ? 'available' : 'unavailable'}" + } + end + + def select_dish(id) + @dishes.select { |dish| dish[:id] == id }.first + end + + def dish_price(id) + dish = select_dish(id) + dish[:price] + end + + def dish_available?(id) + dish = select_dish(id) + dish[:available?] + end + +end \ No newline at end of file diff --git a/spec/menu_spec.rb b/spec/menu_spec.rb new file mode 100644 index 0000000000..09d798613a --- /dev/null +++ b/spec/menu_spec.rb @@ -0,0 +1,39 @@ +require 'menu' + +describe Menu do + + subject(:menu) { described_class.new } + + it 'creates an instance of the class' do + expect(menu).to be_instance_of(Menu) + end + + it 'initializes with a dishes array' do + expect(menu.dishes).not_to be_empty + end + + it 'initializes wiht a dishes array that contains dishes' do + expect(menu.dishes).to include({id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true}) + end + + it 'contains multiple dishes' do + expect(menu.dishes).to include({id: 11, name: 'Phad Thai', price: 11, available?: true}) + end + + it 'displays all of the dishes' do + expect(menu.display_dishes[1]).to eq("2. Veggie Breakfast - £8 - available") + end + + it 'selects a dish' do + expect(menu.select_dish(1)).to eq({id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true}) + end + + it 'returns a price of a dish' do + expect(menu.dish_price(1)).to eq 7 + end + + it 'informs whether the dish is available' do + expect(menu.dish_available?(1)).to eq true + end + +end \ No newline at end of file From d7ecfc7fe3880de99efb8a95a8146cd5a6b6cec9 Mon Sep 17 00:00:00 2001 From: LGretzk Date: Sat, 30 Apr 2022 17:34:02 +0100 Subject: [PATCH 02/14] Add order.rb and order_spec.rb --- lib/order.rb | 3 +++ spec/menu_spec.rb | 2 +- spec/order_spec.rb | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 lib/order.rb create mode 100644 spec/order_spec.rb diff --git a/lib/order.rb b/lib/order.rb new file mode 100644 index 0000000000..0f7b8d6621 --- /dev/null +++ b/lib/order.rb @@ -0,0 +1,3 @@ +class Order + +end \ No newline at end of file diff --git a/spec/menu_spec.rb b/spec/menu_spec.rb index 09d798613a..784e666f45 100644 --- a/spec/menu_spec.rb +++ b/spec/menu_spec.rb @@ -2,7 +2,7 @@ describe Menu do - subject(:menu) { described_class.new } + subject(:menu) { Menu.new } it 'creates an instance of the class' do expect(menu).to be_instance_of(Menu) diff --git a/spec/order_spec.rb b/spec/order_spec.rb new file mode 100644 index 0000000000..5cd8b149e5 --- /dev/null +++ b/spec/order_spec.rb @@ -0,0 +1,11 @@ +require 'order' + +describe Order do + + subject(:order) {Order.new} + + it 'creates an instance of the order class' do + expect(order).to be_instance_of(Order) + end + +end \ No newline at end of file From 1eed378a41d76c417287b51bc87fb9ce67ba4658 Mon Sep 17 00:00:00 2001 From: LGretzk Date: Sat, 30 Apr 2022 21:17:25 +0100 Subject: [PATCH 03/14] Add remove dish and total --- lib/order.rb | 37 +++++++++++++++++++++++++++++++++++++ spec/order_spec.rb | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/lib/order.rb b/lib/order.rb index 0f7b8d6621..0dff9d212e 100644 --- a/lib/order.rb +++ b/lib/order.rb @@ -1,3 +1,40 @@ +require_relative 'menu' + class Order + attr_reader :current_order + + def initialize + @current_order = [] + end + + def add_dish(id, quantity) + dish = {:dish => @@menu.select_dish(id), :quantity => quantity} + dish_already_added?(id) ? update_dish_quantity(id, quantity) : @current_order << dish + end + + def remove_dish(id) + fail 'Dish has not been added' unless dish_already_added?(id) + index = @current_order.index { |current_dish| current_dish[:dish][:id] == id } + @current_order.delete_at(index) + end + + def update_dish_quantity(id, quantity) + remove_dish(id) if quantity < 1 + @current_order.each { |current_dish| current_dish[:quantity] += quantity if current_dish[:dish][:id] == id } + end + + def total + @current_order.map { |current_dish| current_dish[:dish][:price] * current_dish[:quantity]}.reduce(:+) + end + + + private + + @@menu = Menu.new + + def dish_already_added?(id) + (@current_order.select { |current_dish| current_dish[:dish][:id] == id }) != [] ? true : false + end + end \ No newline at end of file diff --git a/spec/order_spec.rb b/spec/order_spec.rb index 5cd8b149e5..4f68ae376c 100644 --- a/spec/order_spec.rb +++ b/spec/order_spec.rb @@ -3,9 +3,53 @@ describe Order do subject(:order) {Order.new} - + let(:dish) { {id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true} } + let(:menu) {instance_double('Menu')} + it 'creates an instance of the order class' do expect(order).to be_instance_of(Order) end + it 'initializes with the order variable' do + expect(order.current_order).to eq([]) + end + + it 'adds a dish to the current_order' do + allow(menu).to receive(:select_dish).and_return(dish) + order.add_dish(1, 1) + expect(order.current_order).to eq([{:dish => dish, :quantity => 1}]) + end + + it 'updates the quantity if the same dish is added twice' do + allow(menu).to receive(:select_dish).and_return(dish) + order.add_dish(1, 1) + order.add_dish(1, 1) + expect(order.current_order).to eq([{:dish => dish, :quantity =>2}]) + end + + it 'removes the dish from the current order' do + allow(menu).to receive(:select_dish).and_return(dish) + order.add_dish(1, 1) + order.remove_dish(1) + expect(order.current_order).to eq([]) + end + + it 'raises an erro when removing dish that has not been added' do + expect {order.remove_dish(1)}.to raise_error 'Dish has not been added' + end + + it 'removes the dish from the current order if the quantity is zero' do + allow(menu).to receive(:select_dish).and_return(dish) + order.add_dish(1, 1) + order.update_dish_quantity(1, 0) + expect(order.current_order).to eq([]) + end + + it 'calculates total for the current order' do + allow(menu).to receive(:select_dish).and_return(dish) + order.add_dish(1, 1) + order.add_dish(1, 1) + expect(order.total).to eq 14 + end + end \ No newline at end of file From bcf30300a610d74bc296e3ca97def0c5aa5594b8 Mon Sep 17 00:00:00 2001 From: LGretzk Date: Sat, 30 Apr 2022 23:22:27 +0100 Subject: [PATCH 04/14] Refactor --- lib/menu.rb | 29 +++++++--------- lib/order.rb | 35 +++++++++++++++---- spec/menu_spec.rb | 12 +++---- spec/order_spec.rb | 83 +++++++++++++++++++++++++++++++--------------- 4 files changed, 102 insertions(+), 57 deletions(-) diff --git a/lib/menu.rb b/lib/menu.rb index e7d421d6e4..882fad46b3 100644 --- a/lib/menu.rb +++ b/lib/menu.rb @@ -5,21 +5,21 @@ class Menu def initialize @dishes = [ - {id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true}, - {id: 2, name: 'Veggie Breakfast', price: 8, available?: true}, - {id: 3, name: 'Halloumi Sandwhich', price: 7, available?: true}, - {id: 4, name: 'Soup of the Day', price: 8, available?: true}, - {id: 5, name: 'Ceaser Salad', price: 8, available?: true}, - {id: 6, name: 'Pizza', price: 9, available?: true}, - {id: 7, name: 'Vegan Pizza', price: 10, available?: true}, - {id: 8, name: 'Yum Yum Salad', price: 11, available?: true}, - {id: 9, name: 'Singapore Laksa', price: 11, available?: true}, - {id: 10, name: 'Spiced Noodles', price: 11, available?: true}, - {id: 11, name: 'Phad Thai', price: 11, available?: true} + {id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true, quantity: 0}, + {id: 2, name: 'Veggie Breakfast', price: 8, available?: true, quantity: 0}, + {id: 3, name: 'Halloumi Sandwhich', price: 7, available?: true, quantity: 0}, + {id: 4, name: 'Soup of the Day', price: 8, available?: true, quantity: 0}, + {id: 5, name: 'Ceaser Salad', price: 8, available?: true, quantity: 0}, + {id: 6, name: 'Pizza', price: 9, available?: true, quantity: 0}, + {id: 7, name: 'Vegan Pizza', price: 10, available?: true, quantity: 0}, + {id: 8, name: 'Yum Yum Salad', price: 11, available?: true, quantity: 0}, + {id: 9, name: 'Singapore Laksa', price: 11, available?: true, quantity: 0}, + {id: 10, name: 'Spiced Noodles', price: 11, available?: true, quantity: 0}, + {id: 11, name: 'Phad Thai', price: 11, available?: true, quantity: 0} ] end - def display_dishes + def display @dishes.map { |dish| p "#{dish[:id]}. #{dish[:name]} - £#{dish[:price]} - #{dish[:available?] ? 'available' : 'unavailable'}" } @@ -29,11 +29,6 @@ def select_dish(id) @dishes.select { |dish| dish[:id] == id }.first end - def dish_price(id) - dish = select_dish(id) - dish[:price] - end - def dish_available?(id) dish = select_dish(id) dish[:available?] diff --git a/lib/order.rb b/lib/order.rb index 0dff9d212e..6e9ce0b8dd 100644 --- a/lib/order.rb +++ b/lib/order.rb @@ -9,32 +9,55 @@ def initialize end def add_dish(id, quantity) - dish = {:dish => @@menu.select_dish(id), :quantity => quantity} - dish_already_added?(id) ? update_dish_quantity(id, quantity) : @current_order << dish + fetch_dish(id) #catch error + @dish[:quantity] = quantity + dish_already_added?(id) ? update_dish_quantity(id, quantity) : @current_order << @dish end def remove_dish(id) fail 'Dish has not been added' unless dish_already_added?(id) - index = @current_order.index { |current_dish| current_dish[:dish][:id] == id } + index = @current_order.index { |dish| dish[:id] == id } @current_order.delete_at(index) end def update_dish_quantity(id, quantity) + fail 'Dish has not been added' unless dish_already_added?(id) remove_dish(id) if quantity < 1 - @current_order.each { |current_dish| current_dish[:quantity] += quantity if current_dish[:dish][:id] == id } + @current_order.each { |dish| dish[:quantity] += quantity if dish[:id] == id } end def total - @current_order.map { |current_dish| current_dish[:dish][:price] * current_dish[:quantity]}.reduce(:+) + @current_order.map { |dish| dish[:price] * dish[:quantity]}.reduce(:+) + end + + # show dishes >>>test + def show_dishes + @@menu.display end + # display order + + # place order + # def place_order + # p "Your order has been placed. Order summary:" + # display_order + # SendText.new(@current_order) + # end + + private @@menu = Menu.new + def fetch_dish(id) + fail 'Invalid id' if @@menu.invalid_id?(id) #test + fail 'Dish unavailable' unless @@menu.dish_available?(id) # test + @dish = @@menu.select_dish(id) + end + def dish_already_added?(id) - (@current_order.select { |current_dish| current_dish[:dish][:id] == id }) != [] ? true : false + (@current_order.select { |dish| dish[:id] == id }) != [] ? true : false end end \ No newline at end of file diff --git a/spec/menu_spec.rb b/spec/menu_spec.rb index 784e666f45..491dcdfe4c 100644 --- a/spec/menu_spec.rb +++ b/spec/menu_spec.rb @@ -13,23 +13,19 @@ end it 'initializes wiht a dishes array that contains dishes' do - expect(menu.dishes).to include({id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true}) + expect(menu.dishes).to include({id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true, quantity: 0}) end it 'contains multiple dishes' do - expect(menu.dishes).to include({id: 11, name: 'Phad Thai', price: 11, available?: true}) + expect(menu.dishes).to include({id: 11, name: 'Phad Thai', price: 11, available?: true, quantity: 0}) end it 'displays all of the dishes' do - expect(menu.display_dishes[1]).to eq("2. Veggie Breakfast - £8 - available") + expect(menu.display[1]).to eq("2. Veggie Breakfast - £8 - available") end it 'selects a dish' do - expect(menu.select_dish(1)).to eq({id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true}) - end - - it 'returns a price of a dish' do - expect(menu.dish_price(1)).to eq 7 + expect(menu.select_dish(1)).to eq({id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true, quantity: 0}) end it 'informs whether the dish is available' do diff --git a/spec/order_spec.rb b/spec/order_spec.rb index 4f68ae376c..e757a42d34 100644 --- a/spec/order_spec.rb +++ b/spec/order_spec.rb @@ -3,50 +3,81 @@ describe Order do subject(:order) {Order.new} - let(:dish) { {id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true} } + let(:dish_0) { {id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true, quantity: 0} } + let(:dish_1) { {id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true, quantity: 1} } + let(:dish_2) { {id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true, quantity: 2} } let(:menu) {instance_double('Menu')} + it 'creates an instance of the order class' do expect(order).to be_instance_of(Order) end - it 'initializes with the order variable' do + it 'initializes with the current_order variable' do expect(order.current_order).to eq([]) end - it 'adds a dish to the current_order' do - allow(menu).to receive(:select_dish).and_return(dish) - order.add_dish(1, 1) - expect(order.current_order).to eq([{:dish => dish, :quantity => 1}]) + describe '#fetch_dish' do + + xit 'creates an instance of a dish from the menu' do + allow(menu).to receive(:select_dish).and_return(dish_0) + expect(order.fetch_dish(1)).to eq dish_0 + end + end - it 'updates the quantity if the same dish is added twice' do - allow(menu).to receive(:select_dish).and_return(dish) - order.add_dish(1, 1) - order.add_dish(1, 1) - expect(order.current_order).to eq([{:dish => dish, :quantity =>2}]) + describe '#add_dish' do + + it 'adds a dish to the current_order' do + #allow(menu).to receive(:select_dish).and_return(dish_0) + order.add_dish(1, 1) + expect(order.current_order).to eq([dish_1]) + end + end - it 'removes the dish from the current order' do - allow(menu).to receive(:select_dish).and_return(dish) - order.add_dish(1, 1) - order.remove_dish(1) - expect(order.current_order).to eq([]) + + describe '#remove_dish' do + + it 'removes the dish from the current order' do + #allow(menu).to receive(:select_dish).and_return(dish_0) + order.add_dish(1, 1) + order.remove_dish(1) + expect(order.current_order).to eq([]) + end + + it 'raises an erro when removing dish that has not been added' do + expect {order.remove_dish(1)}.to raise_error 'Dish has not been added' + end + end + + + describe '#update_dish_quantity' do + + it 'updates the quantity if the same dish is added twice' do + #allow(menu).to receive(:select_dish).and_return(dish_0) + order.add_dish(1, 1) + order.add_dish(1, 1) + expect(order.current_order).to eq([dish_2]) + end + + it 'removes the dish from the current order if the quantity is zero' do + #allow(menu).to receive(:select_dish).and_return(dish_0) + order.add_dish(1, 1) + order.update_dish_quantity(1, 0) + expect(order.current_order).to eq([]) + end + + it 'raises an error when dish has not been added' do + expect{order.update_dish_quantity(1, 1)}.to raise_error 'Dish has not been added' + end - it 'raises an erro when removing dish that has not been added' do - expect {order.remove_dish(1)}.to raise_error 'Dish has not been added' - end + end - it 'removes the dish from the current order if the quantity is zero' do - allow(menu).to receive(:select_dish).and_return(dish) - order.add_dish(1, 1) - order.update_dish_quantity(1, 0) - expect(order.current_order).to eq([]) - end it 'calculates total for the current order' do - allow(menu).to receive(:select_dish).and_return(dish) + #allow(menu).to receive(:select_dish).and_return(dish_0) order.add_dish(1, 1) order.add_dish(1, 1) expect(order.total).to eq 14 From bd5408a90486578e4f08efaed39862ced62f7c3f Mon Sep 17 00:00:00 2001 From: LGretzk Date: Mon, 2 May 2022 12:49:06 +0100 Subject: [PATCH 05/14] Refactored, fixed bugs --- lib/menu.rb | 39 ++++++++++++-------- lib/order.rb | 67 +++++++++++++++++++++------------ spec/menu_spec.rb | 32 +++++++++++++--- spec/order_spec.rb | 92 ++++++++++++++++++++++++++++++++++------------ 4 files changed, 162 insertions(+), 68 deletions(-) diff --git a/lib/menu.rb b/lib/menu.rb index 882fad46b3..009e91d8a7 100644 --- a/lib/menu.rb +++ b/lib/menu.rb @@ -1,28 +1,31 @@ class Menu + DISHES = [ + { id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true, quantity: 0 }, + { id: 2, name: 'Veggie Breakfast', price: 8, available?: true, quantity: 0 }, + { id: 3, name: 'Halloumi Sandwhich', price: 7, available?: true, quantity: 0 }, + { id: 4, name: 'Soup of the Day', price: 8, available?: true, quantity: 0 }, + { id: 5, name: 'Ceaser Salad', price: 8, available?: true, quantity: 0 }, + { id: 6, name: 'Pizza', price: 9, available?: true, quantity: 0 }, + { id: 7, name: 'Vegan Pizza', price: 10, available?: true, quantity: 0 }, + { id: 8, name: 'Yum Yum Salad', price: 11, available?: true, quantity: 0 }, + { id: 9, name: 'Singapore Laksa', price: 11, available?: true, quantity: 0 }, + { id: 10, name: 'Spiced Noodles', price: 11, available?: true, quantity: 0 }, + { id: 11, name: 'Phad Thai', price: 11, available?: true, quantity: 0 }, + { id: 12, name: 'Caponata', price: 11, available?: false, quantity: 0 } + ].freeze + attr_reader :dishes def initialize - @dishes = [ - {id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true, quantity: 0}, - {id: 2, name: 'Veggie Breakfast', price: 8, available?: true, quantity: 0}, - {id: 3, name: 'Halloumi Sandwhich', price: 7, available?: true, quantity: 0}, - {id: 4, name: 'Soup of the Day', price: 8, available?: true, quantity: 0}, - {id: 5, name: 'Ceaser Salad', price: 8, available?: true, quantity: 0}, - {id: 6, name: 'Pizza', price: 9, available?: true, quantity: 0}, - {id: 7, name: 'Vegan Pizza', price: 10, available?: true, quantity: 0}, - {id: 8, name: 'Yum Yum Salad', price: 11, available?: true, quantity: 0}, - {id: 9, name: 'Singapore Laksa', price: 11, available?: true, quantity: 0}, - {id: 10, name: 'Spiced Noodles', price: 11, available?: true, quantity: 0}, - {id: 11, name: 'Phad Thai', price: 11, available?: true, quantity: 0} - ] + @dishes = DISHES end def display - @dishes.map { |dish| + @dishes.map do |dish| p "#{dish[:id]}. #{dish[:name]} - £#{dish[:price]} - #{dish[:available?] ? 'available' : 'unavailable'}" - } + end end def select_dish(id) @@ -34,4 +37,8 @@ def dish_available?(id) dish[:available?] end -end \ No newline at end of file + def id_valid?(id) + @dishes.select { |dish| dish[:id] == id } != [] + end + +end diff --git a/lib/order.rb b/lib/order.rb index 6e9ce0b8dd..00f7f176a9 100644 --- a/lib/order.rb +++ b/lib/order.rb @@ -2,62 +2,83 @@ class Order - attr_reader :current_order + attr_reader :current_order, :order_placed def initialize @current_order = [] + @order_placed = false + end + + def show_dishes + @@menu.display end def add_dish(id, quantity) - fetch_dish(id) #catch error + select_dish(id) @dish[:quantity] = quantity dish_already_added?(id) ? update_dish_quantity(id, quantity) : @current_order << @dish end def remove_dish(id) - fail 'Dish has not been added' unless dish_already_added?(id) + fail_if_dish_not_added(id) index = @current_order.index { |dish| dish[:id] == id } @current_order.delete_at(index) end def update_dish_quantity(id, quantity) - fail 'Dish has not been added' unless dish_already_added?(id) + fail_if_dish_not_added(id) remove_dish(id) if quantity < 1 @current_order.each { |dish| dish[:quantity] += quantity if dish[:id] == id } end + def show_current_order + fail_if_order_empty + @current_order.map do |dish| + p "#{dish[:quantity]} x ##{dish[:id]} #{dish[:name]} - £#{dish[:price] * dish[:quantity]}" + end + puts "Order total: £#{total}" + end + def total - @current_order.map { |dish| dish[:price] * dish[:quantity]}.reduce(:+) + fail_if_order_empty + @current_order.map { |dish| dish[:price] * dish[:quantity] }.reduce(:+) end - # show dishes >>>test - def show_dishes - @@menu.display + def place_order + fail_if_order_empty || (fail 'Order already placed' if @order_placed == true) + @order_placed = true + puts "Your order has been placed. Order summary:" + show_current_order + # SendText.new(@current_order) end - # display order + private - # place order - # def place_order - # p "Your order has been placed. Order summary:" - # display_order - # SendText.new(@current_order) - # end + @@menu = Menu.new + def select_dish(id) + fail_if_invalid_id(id) || fail_if_dish_unavailable(id) + @dish = @@menu.select_dish(id) + end + def fail_if_invalid_id(id) + fail 'Invalid id' unless @@menu.id_valid?(id) + end - private + def fail_if_dish_unavailable(id) + fail 'Dish unavailable' unless @@menu.dish_available?(id) + end - @@menu = Menu.new + def fail_if_dish_not_added(id) + fail 'Dish has not been added' unless dish_already_added?(id) + end - def fetch_dish(id) - fail 'Invalid id' if @@menu.invalid_id?(id) #test - fail 'Dish unavailable' unless @@menu.dish_available?(id) # test - @dish = @@menu.select_dish(id) + def fail_if_order_empty + fail 'Current order empty' if @current_order.empty? end def dish_already_added?(id) - (@current_order.select { |dish| dish[:id] == id }) != [] ? true : false + (@current_order.select { |dish| dish[:id] == id }) != [] end -end \ No newline at end of file +end diff --git a/spec/menu_spec.rb b/spec/menu_spec.rb index 491dcdfe4c..ff33103377 100644 --- a/spec/menu_spec.rb +++ b/spec/menu_spec.rb @@ -13,11 +13,11 @@ end it 'initializes wiht a dishes array that contains dishes' do - expect(menu.dishes).to include({id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true, quantity: 0}) + expect(menu.dishes).to include({ id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true, quantity: 0 }) end it 'contains multiple dishes' do - expect(menu.dishes).to include({id: 11, name: 'Phad Thai', price: 11, available?: true, quantity: 0}) + expect(menu.dishes).to include({ id: 11, name: 'Phad Thai', price: 11, available?: true, quantity: 0 }) end it 'displays all of the dishes' do @@ -25,11 +25,31 @@ end it 'selects a dish' do - expect(menu.select_dish(1)).to eq({id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true, quantity: 0}) + expect(menu.select_dish(1)).to eq({ id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true, quantity: 0 }) end - it 'informs whether the dish is available' do - expect(menu.dish_available?(1)).to eq true + context 'dish available' do + it 'informs whether the dish is available' do + expect(menu.dish_available?(1)).to eq true + end end -end \ No newline at end of file + context 'dish unavailable' do + it 'informs whether the dish is available' do + expect(menu.dish_available?(12)).to eq false + end + end + + context 'id valid' do + it 'checks if id is valid' do + expect(menu.id_valid?(1)).to eq true + end + end + + context 'id invalid' do + it 'checks if if is valid' do + expect(menu.id_valid?(30)).to eq false + end + end + +end diff --git a/spec/order_spec.rb b/spec/order_spec.rb index e757a42d34..a6184d43a2 100644 --- a/spec/order_spec.rb +++ b/spec/order_spec.rb @@ -2,11 +2,11 @@ describe Order do - subject(:order) {Order.new} - let(:dish_0) { {id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true, quantity: 0} } - let(:dish_1) { {id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true, quantity: 1} } - let(:dish_2) { {id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true, quantity: 2} } - let(:menu) {instance_double('Menu')} + subject(:order) { Order.new } + let(:dish0) { { id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true, quantity: 0 } } + let(:dish1) { { id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true, quantity: 1 } } + let(:dish2) { { id: 1, name: 'Spinach & Cheddar Pancakes', price: 7, available?: true, quantity: 2 } } + let(:menu) { instance_double('Menu') } it 'creates an instance of the order class' do @@ -17,70 +17,116 @@ expect(order.current_order).to eq([]) end - describe '#fetch_dish' do + it 'initializes with the order_placed variable' do + expect(order.order_placed).to eq false + end + + it 'shows all of the dishes' do + allow(menu).to receive(:display).and_return("2. Veggie Breakfast - £8 - available") + expect(order.show_dishes[1]).to eq("2. Veggie Breakfast - £8 - available") + end + + describe '#select_dish' do ### tested the method when wasn't private - xit 'creates an instance of a dish from the menu' do - allow(menu).to receive(:select_dish).and_return(dish_0) - expect(order.fetch_dish(1)).to eq dish_0 + it 'selects a dish from the menu' do + allow(menu).to receive_messages(:select_dish => dish0) + dish = menu.select_dish(1) + expect(dish).to eq dish0 + end + + xit 'fails if id is invalid' do ### this works in irb but not in rspec, what could be the reason? + # tested when the method wasn't private + allow(menu).to receive(:select_dish).and_raise('Invalid id') + dish = menu.select_dish(1) + expect { dish }.to raise_error 'Invalid id' + end + + xit 'fails if dish is unavailable' do ### same as above + allow(menu).to receive_messages(:select_dish => dish0, :id_valid? => true, :dish_available? => false) + dish = menu.select_dish(1) + expect { dish }.to raise_error 'Dish unavailable' end end - describe '#add_dish' do + describe '#add_dish' do ### this still uses the Menu class; how coud it stub it? - it 'adds a dish to the current_order' do - #allow(menu).to receive(:select_dish).and_return(dish_0) + it 'adds a dish to the current_order' do order.add_dish(1, 1) - expect(order.current_order).to eq([dish_1]) + expect(order.current_order).to eq([dish1]) end - end + it 'fails if id is invalid' do + expect { order.add_dish(33, 1) }.to raise_error 'Invalid id' + end + it 'fails if dish is unavailable' do + expect { order.add_dish(12, 1) }.to raise_error 'Dish unavailable' + end + + end describe '#remove_dish' do it 'removes the dish from the current order' do - #allow(menu).to receive(:select_dish).and_return(dish_0) order.add_dish(1, 1) order.remove_dish(1) expect(order.current_order).to eq([]) end it 'raises an erro when removing dish that has not been added' do - expect {order.remove_dish(1)}.to raise_error 'Dish has not been added' + expect { order.remove_dish(1) }.to raise_error 'Dish has not been added' end end - describe '#update_dish_quantity' do it 'updates the quantity if the same dish is added twice' do - #allow(menu).to receive(:select_dish).and_return(dish_0) order.add_dish(1, 1) order.add_dish(1, 1) - expect(order.current_order).to eq([dish_2]) + expect(order.current_order).to eq([dish2]) end it 'removes the dish from the current order if the quantity is zero' do - #allow(menu).to receive(:select_dish).and_return(dish_0) order.add_dish(1, 1) order.update_dish_quantity(1, 0) expect(order.current_order).to eq([]) end it 'raises an error when dish has not been added' do - expect{order.update_dish_quantity(1, 1)}.to raise_error 'Dish has not been added' + expect { order.update_dish_quantity(1, 1) }.to raise_error 'Dish has not been added' end end + xit 'shows the current order' do ### test pending, method prints & doesn't return statements + order.add_dish(2, 1) + expect(order.show_current_order).to eq("1 x #2 Veggie Breakfast - £8" + "Order total: £14") + end + + it 'fails to show current order if empty' do + expect { order.show_current_order }.to raise_error 'Current order empty' + end it 'calculates total for the current order' do - #allow(menu).to receive(:select_dish).and_return(dish_0) order.add_dish(1, 1) order.add_dish(1, 1) expect(order.total).to eq 14 end -end \ No newline at end of file + it 'fails to calculate total if current order is empty' do + expect { order.total }.to raise_error 'Current order empty' + end + + it 'places order' do + order.add_dish(1, 1) + order.add_dish(1, 1) + expect { order.place_order }.to output.to_stdout + end + + it 'fails to place order if current order is empty' do + expect { order.place_order }.to raise_error 'Current order empty' + end + +end From 75dd706468ad9e1355ad4caa9db85cd52d32a77a Mon Sep 17 00:00:00 2001 From: LGretzk Date: Mon, 2 May 2022 13:36:10 +0100 Subject: [PATCH 06/14] Fix quantity bug --- lib/order.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/order.rb b/lib/order.rb index 00f7f176a9..9d4a9b6de6 100644 --- a/lib/order.rb +++ b/lib/order.rb @@ -15,8 +15,12 @@ def show_dishes def add_dish(id, quantity) select_dish(id) - @dish[:quantity] = quantity - dish_already_added?(id) ? update_dish_quantity(id, quantity) : @current_order << @dish + if dish_already_added?(id) + add_by_updating_quantity(id, quantity) + else + @dish[:quantity] = quantity + @current_order << @dish + end end def remove_dish(id) @@ -28,7 +32,7 @@ def remove_dish(id) def update_dish_quantity(id, quantity) fail_if_dish_not_added(id) remove_dish(id) if quantity < 1 - @current_order.each { |dish| dish[:quantity] += quantity if dish[:id] == id } + @current_order.each { |dish| dish[:quantity] = quantity if dish[:id] == id } end def show_current_order @@ -61,6 +65,10 @@ def select_dish(id) @dish = @@menu.select_dish(id) end + def add_by_updating_quantity(id, quantity) + @current_order.each { |dish| dish[:quantity] = (dish[:quantity] + quantity) if dish[:id] == id } + end + def fail_if_invalid_id(id) fail 'Invalid id' unless @@menu.id_valid?(id) end From 496b167076b2fec1789346ef2cb9e4444b134f0e Mon Sep 17 00:00:00 2001 From: LGretzk Date: Mon, 2 May 2022 14:53:34 +0100 Subject: [PATCH 07/14] Add twilio and dotenv to the gemfile, set up text messages --- .gitignore | 2 ++ Gemfile | 2 ++ Gemfile.lock | 59 +++++++++++++++++++++++++++++++++++++++ lib/confirmation.rb | 34 ++++++++++++++++++++++ spec/confirmation_spec.rb | 0 5 files changed, 97 insertions(+) create mode 100644 lib/confirmation.rb create mode 100644 spec/confirmation_spec.rb diff --git a/.gitignore b/.gitignore index d1a1edf06f..eba59a0a64 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ /**/.DS_Store /coverage +.env + # Local cache of Rubocop remote config .rubocop-* diff --git a/Gemfile b/Gemfile index 35de4a7f0e..1aec18fcad 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +gem 'dotenv-rails', groups: [:development, :test] + source 'https://rubygems.org' ruby '3.0.2' diff --git a/Gemfile.lock b/Gemfile.lock index 66064703c7..bfc9e1c755 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,14 +1,68 @@ GEM remote: https://rubygems.org/ specs: + actionpack (7.0.2.4) + actionview (= 7.0.2.4) + activesupport (= 7.0.2.4) + rack (~> 2.0, >= 2.2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actionview (7.0.2.4) + activesupport (= 7.0.2.4) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activesupport (7.0.2.4) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) ansi (1.5.0) ast (2.4.2) + builder (3.2.4) + concurrent-ruby (1.1.10) + crass (1.0.6) diff-lcs (1.4.4) docile (1.4.0) + dotenv (2.7.6) + dotenv-rails (2.7.6) + dotenv (= 2.7.6) + railties (>= 3.2) + erubi (1.10.0) + i18n (1.10.0) + concurrent-ruby (~> 1.0) + loofah (2.17.0) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + method_source (1.0.0) + mini_portile2 (2.8.0) + minitest (5.15.0) + 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) + rack (2.2.3) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.4.2) + loofah (~> 2.3) + railties (7.0.2.4) + actionpack (= 7.0.2.4) + activesupport (= 7.0.2.4) + method_source + rake (>= 12.2) + thor (~> 1.0) + zeitwerk (~> 2.5) rainbow (3.0.0) + rake (13.0.6) regexp_parser (2.1.1) rexml (3.2.5) rspec (3.10.0) @@ -48,12 +102,17 @@ GEM simplecov_json_formatter (0.1.3) terminal-table (3.0.1) unicode-display_width (>= 1.1.1, < 3) + thor (1.2.1) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) unicode-display_width (2.0.0) + zeitwerk (2.5.4) PLATFORMS ruby DEPENDENCIES + dotenv-rails rspec rubocop (= 1.20) simplecov diff --git a/lib/confirmation.rb b/lib/confirmation.rb new file mode 100644 index 0000000000..d064d63e15 --- /dev/null +++ b/lib/confirmation.rb @@ -0,0 +1,34 @@ +require 'twilio-ruby' +require 'dotenv' +Dotenv.load + +class Confirmation + + def initialize(order, number) + @order = order + @number = number + end + + def send_text + account_sid = ENV['ACCOUNT_SID'] + auth_token = ENV['AUTH_TOKEN'] + client = Twilio::REST::Client.new(account_sid, auth_token) + + from = ENV['FROM_PHONE_NUMBER'] + to = ENV['TO_PHONE_NUMBER'] + + client.messages.create( + from: from, + to: to, + body: "Thank you! Your order was placed and will be delivered before #{delivery_time}" + ) + + end + + def delivery_time + time = Time.now + 1h_later = time + (60 * 60) + 1h_later.to_s.split(" ")[1][0,5] + end + +end diff --git a/spec/confirmation_spec.rb b/spec/confirmation_spec.rb new file mode 100644 index 0000000000..e69de29bb2 From c8f079b461f35e0adf412acf8236c3f146cf01b6 Mon Sep 17 00:00:00 2001 From: LGretzk Date: Mon, 2 May 2022 15:19:30 +0100 Subject: [PATCH 08/14] Send messages when placing order functionality --- lib/confirmation.rb | 14 ++++++-------- lib/order.rb | 3 ++- spec/order_spec.rb | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/confirmation.rb b/lib/confirmation.rb index d064d63e15..04d8e64f3e 100644 --- a/lib/confirmation.rb +++ b/lib/confirmation.rb @@ -4,9 +4,8 @@ class Confirmation - def initialize(order, number) - @order = order - @number = number + def initialize + @number = ENV['TO_PHONE_NUMBER'] end def send_text @@ -15,20 +14,19 @@ def send_text client = Twilio::REST::Client.new(account_sid, auth_token) from = ENV['FROM_PHONE_NUMBER'] - to = ENV['TO_PHONE_NUMBER'] + #to = ENV['TO_PHONE_NUMBER'] client.messages.create( from: from, - to: to, + to: @number, body: "Thank you! Your order was placed and will be delivered before #{delivery_time}" ) - end def delivery_time time = Time.now - 1h_later = time + (60 * 60) - 1h_later.to_s.split(" ")[1][0,5] + delivered_by = (time + (60 * 60)) + delivered_by.to_s.split(" ")[1][0,5] end end diff --git a/lib/order.rb b/lib/order.rb index 9d4a9b6de6..49497141fe 100644 --- a/lib/order.rb +++ b/lib/order.rb @@ -1,4 +1,5 @@ require_relative 'menu' +require_relative 'confirmation' class Order @@ -53,7 +54,7 @@ def place_order @order_placed = true puts "Your order has been placed. Order summary:" show_current_order - # SendText.new(@current_order) + Confirmation.new.send_text ### this would have had the tel number passed on as argument end private diff --git a/spec/order_spec.rb b/spec/order_spec.rb index a6184d43a2..3ad0cabb1c 100644 --- a/spec/order_spec.rb +++ b/spec/order_spec.rb @@ -26,7 +26,7 @@ expect(order.show_dishes[1]).to eq("2. Veggie Breakfast - £8 - available") end - describe '#select_dish' do ### tested the method when wasn't private + describe '#select_dish' do ### tested when the method wasn't private it 'selects a dish from the menu' do allow(menu).to receive_messages(:select_dish => dish0) From 105ce3f8f8d65f130f5f83526374e288493a0101 Mon Sep 17 00:00:00 2001 From: LGretzk Date: Mon, 2 May 2022 16:01:21 +0100 Subject: [PATCH 09/14] Add mocking of send_text --- lib/order.rb | 5 +++-- spec/order_spec.rb | 12 ++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/order.rb b/lib/order.rb index 49497141fe..36eb6e93b4 100644 --- a/lib/order.rb +++ b/lib/order.rb @@ -49,12 +49,13 @@ def total @current_order.map { |dish| dish[:price] * dish[:quantity] }.reduce(:+) end - def place_order + def place_order(confirmation) fail_if_order_empty || (fail 'Order already placed' if @order_placed == true) @order_placed = true puts "Your order has been placed. Order summary:" show_current_order - Confirmation.new.send_text ### this would have had the tel number passed on as argument + confirmation.send_text + #Confirmation.new.send_text ### this would have had the tel number passed on as argument end private diff --git a/spec/order_spec.rb b/spec/order_spec.rb index 3ad0cabb1c..c4afacf157 100644 --- a/spec/order_spec.rb +++ b/spec/order_spec.rb @@ -122,11 +122,19 @@ it 'places order' do order.add_dish(1, 1) order.add_dish(1, 1) - expect { order.place_order }.to output.to_stdout + confirmation = double('Confirmation', :send_text => 'Message sent') + order.place_order(confirmation) + expect(order.order_placed).to be true end it 'fails to place order if current order is empty' do - expect { order.place_order }.to raise_error 'Current order empty' + expect { order.place_order('confirmation') }.to raise_error 'Current order empty' + end + + it 'sends a confirmation text message' do + order.add_dish(1, 1) + confirmation = double('Confirmation', :send_text => 'Message sent') + expect(order.place_order(confirmation)).to eq 'Message sent' end end From e4a6ff5956d42008607d7a80bedf07cbbd46bf11 Mon Sep 17 00:00:00 2001 From: LGretzk Date: Mon, 2 May 2022 16:06:29 +0100 Subject: [PATCH 10/14] Correct rubocop offences --- lib/confirmation.rb | 3 +-- lib/order.rb | 3 +-- spec/order_spec.rb | 36 ++++++++++++++++++------------------ 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/lib/confirmation.rb b/lib/confirmation.rb index 04d8e64f3e..92d099aa0f 100644 --- a/lib/confirmation.rb +++ b/lib/confirmation.rb @@ -14,7 +14,6 @@ def send_text client = Twilio::REST::Client.new(account_sid, auth_token) from = ENV['FROM_PHONE_NUMBER'] - #to = ENV['TO_PHONE_NUMBER'] client.messages.create( from: from, @@ -26,7 +25,7 @@ def send_text def delivery_time time = Time.now delivered_by = (time + (60 * 60)) - delivered_by.to_s.split(" ")[1][0,5] + delivered_by.to_s.split()[1][0,5] end end diff --git a/lib/order.rb b/lib/order.rb index 36eb6e93b4..6311c6b1da 100644 --- a/lib/order.rb +++ b/lib/order.rb @@ -54,8 +54,7 @@ def place_order(confirmation) @order_placed = true puts "Your order has been placed. Order summary:" show_current_order - confirmation.send_text - #Confirmation.new.send_text ### this would have had the tel number passed on as argument + confirmation.send_text ### this would have had the tel number passed on as argument end private diff --git a/spec/order_spec.rb b/spec/order_spec.rb index c4afacf157..cf8aed942d 100644 --- a/spec/order_spec.rb +++ b/spec/order_spec.rb @@ -80,26 +80,26 @@ end - describe '#update_dish_quantity' do - - it 'updates the quantity if the same dish is added twice' do - order.add_dish(1, 1) - order.add_dish(1, 1) - expect(order.current_order).to eq([dish2]) - end - - it 'removes the dish from the current order if the quantity is zero' do - order.add_dish(1, 1) - order.update_dish_quantity(1, 0) - expect(order.current_order).to eq([]) - end - - it 'raises an error when dish has not been added' do - expect { order.update_dish_quantity(1, 1) }.to raise_error 'Dish has not been added' - end - + describe '#update_dish_quantity' do + + it 'updates the quantity if the same dish is added twice' do + order.add_dish(1, 1) + order.add_dish(1, 1) + expect(order.current_order).to eq([dish2]) + end + + it 'removes the dish from the current order if the quantity is zero' do + order.add_dish(1, 1) + order.update_dish_quantity(1, 0) + expect(order.current_order).to eq([]) + end + + it 'raises an error when dish has not been added' do + expect { order.update_dish_quantity(1, 1) }.to raise_error 'Dish has not been added' end + end + xit 'shows the current order' do ### test pending, method prints & doesn't return statements order.add_dish(2, 1) expect(order.show_current_order).to eq("1 x #2 Veggie Breakfast - £8" + "Order total: £14") From 790aaccf8d26a0275c0a58de01231a787fd53aad Mon Sep 17 00:00:00 2001 From: Luiza Gretzk <79107383+LGretzk@users.noreply.github.com> Date: Mon, 2 May 2022 16:22:51 +0100 Subject: [PATCH 11/14] Update README.md --- README.md | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index dbcb154e43..3b40af81d2 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,16 @@ Takeaway Challenge ================== -``` - _________ - r== | | - _ // | M.A. | )))) - |_)//(''''': | | - // \_____:_____.-------D ))))) - // | === | / \ - .:'//. \ \=| \ / .:'':./ ))))) - :' // ': \ \ ''..'--:'-.. ': - '. '' .' \:.....:--'.-'' .' - ':..:' ':..:' - - ``` - -Instructions + + +Instalation ------- +``` +$ git clone https://github.com/lgretzk/takeaway-challenge.git + +$ cd takeaway-challenge -* 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 +$ bundle +``` Task ----- From c2e7504736dae1df795050b4c4634da3e67c53d6 Mon Sep 17 00:00:00 2001 From: Luiza Gretzk <79107383+LGretzk@users.noreply.github.com> Date: Mon, 2 May 2022 16:32:16 +0100 Subject: [PATCH 12/14] Update README.md --- README.md | 63 ++++++++++++++++++++----------------------------------- 1 file changed, 23 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 3b40af81d2..672aaafeb5 100644 --- a/README.md +++ b/README.md @@ -5,19 +5,37 @@ Takeaway Challenge Instalation ------- ``` -$ git clone https://github.com/lgretzk/takeaway-challenge.git +$ git clone https://github.com/LGretzk/takeaway-challenge.git $ cd takeaway-challenge $ bundle ``` -Task +Instructions ----- -* 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: +* Use IRB to require the order.rb file + +* Create a new instance of Order to order food. + +* Use show_dishes method to see the menu. + +* Use add_dish(id, quantity) to order dish. + +* Use remove_dish(id) to remove dish from your order. + +* Use update_dish_quantity(id, quantity) to update the quantity of your chosen dish. + +* Use show_current_order to preview your order. + +* Use total to get the total amount you would need to pay for your order. + +* Use place_order(Confirmation.new) to place your order. + + +User stories +----- ``` As a customer @@ -36,38 +54,3 @@ 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. From 04d48e349b5af5ab7e0062cd64649d4e8805670d Mon Sep 17 00:00:00 2001 From: LGretzk Date: Mon, 2 May 2022 16:34:23 +0100 Subject: [PATCH 13/14] Update gemfile --- Gemfile | 4 ++-- Gemfile.lock | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 1aec18fcad..95c8a88f1b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,3 @@ -gem 'dotenv-rails', groups: [:development, :test] - source 'https://rubygems.org' ruby '3.0.2' @@ -12,4 +10,6 @@ end group :development, :test do gem 'rubocop', '1.20' + gem 'twilio-ruby' + gem 'dotenv-rails' end diff --git a/Gemfile.lock b/Gemfile.lock index bfc9e1c755..c4dcf8d32f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -117,6 +117,7 @@ DEPENDENCIES rubocop (= 1.20) simplecov simplecov-console + twilio-ruby RUBY VERSION ruby 3.0.2p107 From f41197c6324a2d67b097818c1cce560ec12405c2 Mon Sep 17 00:00:00 2001 From: Luiza Gretzk <79107383+LGretzk@users.noreply.github.com> Date: Sun, 8 May 2022 18:55:13 +0100 Subject: [PATCH 14/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 672aaafeb5..e24d7369e0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Takeaway Challenge ================== -Instalation +Installation ------- ``` $ git clone https://github.com/LGretzk/takeaway-challenge.git