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

FarMar - Primary + Optionals #44

Open
wants to merge 29 commits into
base: KED/master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
36361d9
added #all method to Market class
kedevlin Oct 19, 2015
e35490f
Added #all method to Product class
kedevlin Oct 20, 2015
699b2e6
Added #all method to Sale Class
kedevlin Oct 20, 2015
817c020
added #all method to Vendor class
kedevlin Oct 20, 2015
2ae33ed
Added #find(id) method to Vendor class
kedevlin Oct 20, 2015
242b8ac
Added #find(id) method to Sales class
kedevlin Oct 20, 2015
f948040
added #find(id) to Product class
kedevlin Oct 20, 2015
98741b8
Added #find(id) to Market class
kedevlin Oct 20, 2015
38be600
Added .vendors method to Market class
kedevlin Oct 21, 2015
6776c61
added .market method to Vendor class
kedevlin Oct 21, 2015
f2f646a
Added .products method to Vendor class
kedevlin Oct 21, 2015
42524d9
added .sales method to Vendor class
kedevlin Oct 21, 2015
d52c4aa
Added .revenue method to Vendor class
kedevlin Oct 21, 2015
ed7a850
Added #by_market(market_id) method to Vendor class
kedevlin Oct 21, 2015
b83728a
added .vendor method to Product class
kedevlin Oct 21, 2015
3abaabe
Updated #all method for each class to use class variable
kedevlin Oct 21, 2015
422e5d9
Added .sales and .number_of_sales methods to Product class
kedevlin Oct 21, 2015
a9aa67e
added #by_vendor method to Product class
kedevlin Oct 21, 2015
311626e
Added .vendor method to Sale class
kedevlin Oct 21, 2015
b4368bf
Added #between method to Sale class
kedevlin Oct 21, 2015
660d15e
added optional .products method to Market class
kedevlin Oct 22, 2015
98b6a01
Added optional #search method to Market class
kedevlin Oct 22, 2015
8536039
Same as prior commit with uncommented tests in Market_Spec
kedevlin Oct 22, 2015
1e0e340
added optional .preferred_vendor method to Market class
kedevlin Oct 22, 2015
c4f3697
added optional .preferred_vendor method to Market class
kedevlin Oct 23, 2015
e45c49c
updated .revenue method in Vendor class to accept dates, updated .pre…
kedevlin Oct 23, 2015
85c708f
updated spec docs to use best practices
kedevlin Oct 23, 2015
d59b136
fixed indent errors
kedevlin Oct 23, 2015
ee340f2
revised all 4 classes
kedevlin Oct 23, 2015
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
Prev Previous commit
Next Next commit
Added #between method to Sale class
kedevlin committed Oct 21, 2015
commit b4368bf0b5c39479a941e344759a78c1623a2fba
12 changes: 12 additions & 0 deletions lib/far_mar/Sale.rb
Original file line number Diff line number Diff line change
@@ -28,5 +28,17 @@ def vendor
vendor.id == self.vendor_id
end
end
def product
FarMar::Product.all.find do |product|
product.id == self.product_id
end
end
def self.between(beginning_time, end_time)
beginning_time = DateTime.strptime(beginning_time, "%Y-%m-%d %H:%M:%S %z")
end_time = DateTime.strptime(end_time, "%Y-%m-%d %H:%M:%S %z")
self.all.find_all do |sale|
sale.purchase_time > beginning_time && sale.purchase_time < end_time
end
end
end
end
29 changes: 29 additions & 0 deletions spec/far_mar/Sale_spec.rb
Original file line number Diff line number Diff line change
@@ -27,4 +27,33 @@
expect(@sale.vendor.name).to eq "Beer, Heathcote and Leffler"
end
end
describe ".product" do
it "returns the product instance whose id matches the sales's product_id" do
expect(@sale.product.id).to eq 2213
expect(@sale.product.name).to eq "Rotten Fruit"
end
end
describe "#between(beginning_time, end_time)"do
it "returns a collection of sales where the purchase_time is between the two parameters" do
begin_time = "2013-11-06 08:47:12 -0800"
end_time = "2013-11-06 08:52:59 -0800"
expect(FarMar::Sale.between(begin_time, end_time).length).to eq 4
expect(FarMar::Sale.between(begin_time, end_time)[1].id).to eq 4119
expect(FarMar::Sale.between(begin_time, end_time)[1].class).to eq FarMar::Sale
end
context "when end_time is before beginning_time" do
it "returns an empty array" do
begin_time = "2013-11-06 08:52:59 -0800"
end_time = "2013-11-06 08:47:12 -0800"
expect(FarMar::Sale.between(begin_time, end_time)).to eq []
end
end
context "when beginning_time and end_time are the same" do
it "returns an empty array" do
begin_time = "2013-11-06 08:47:12 -0800"
end_time = "2013-11-06 08:47:12 -0800"
expect(FarMar::Sale.between(begin_time, end_time)).to eq []
end
end
end
end