This repository has been archived by the owner on Jun 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 147
/
app.rb
66 lines (44 loc) · 2.16 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require_relative "lib/errors"
require_relative "lib/customer"
require_relative "lib/product"
require_relative "lib/transaction"
# PRODUCTS
# Product.new(title: "LEGO Iron Man vs. Ultron", price: 22.99, stock: 55)
# Product.new(title: "Nano Block Empire State Building", price: 49.99, stock: 12)
# Product.new(title: "LEGO Firehouse Headquarter", price: 199.99, stock: 0)
# puts Product.all.count # Should return 3
# Product.new(title: "LEGO Iron Man vs. Ultron", price: 22.99, stock: 55)
# Should return DuplicateProductError: 'LEGO Iron Man vs. Ultron' already exists.
# nanoblock = Product.find_by_title("Nano Block Empire State Building")
# firehouse = Product.find_by_title("LEGO Firehouse Headquarter")
# puts nanoblock.title # Should return 'Nano Block Empire State Building'
# puts nanoblock.price # Should return 49.99
# puts nanoblock.stock # Should return 12
# puts nanoblock.in_stock? # Should return true
# puts firehouse.in_stock? # Should return false
# products_in_stock = Product.in_stock
# Should return an array of all products with a stock greater than zero
# puts products_in_stock.include?(nanoblock) # Should return true
# puts products_in_stock.include?(firehouse) # Should return false
# CUSTOMERS
# Customer.new(name: "Walter Latimer")
# Customer.new(name: "Julia Van Cleve")
# puts Customer.all.count # Should return 2
# Customer.new(name: "Walter Latimer")
# Should return DuplicateCustomerError: 'Walter Latimer' already exists.
# walter = Customer.find_by_name("Walter Latimer")
# puts walter.name # Should return "Walter Latimer"
# TRANSACTIONS
# transaction = Transaction.new(walter, nanoblock)
# puts transaction.id # Should return 1
# puts transaction.product == nanoblock # Should return true
# puts transaction.product == firehouse # Should return false
# puts transaction.customer == walter # Should return true
# puts nanoblock.stock # Should return 11
# PURCHASES
# puts walter.purchase(nanoblock)
# puts Transaction.all.count # Should return 2
# transaction2 = Transaction.find(2)
# puts transaction2.product == nanoblock # Should return true
# walter.purchase(firehouse)
# Should return OutOfStockError: 'LEGO Firehouse Headquarter' is out of stock.