From 38ea371ee356985e257b226dd5c4a6f7aec3f68c Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Tue, 20 Oct 2015 16:16:05 -0700 Subject: [PATCH 01/42] Made working initialize methods for the Market and Product classes --- lib/far_mar/market.rb | 18 ++++++++++++++++++ lib/far_mar/product.rb | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index 5be343e9..e4c385a9 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -1,4 +1,22 @@ +require 'csv' + module FarMar class Market + attr_accessor :id, :name, :address, :city, :county, :state, :zip + def initialize() + @id = id + @name = name + @address = address + @city = city + @county = county + @state = state + @zip = zip + end + + # def self.all + # #returns a collection of Market instances, representing all of the markets described in the CSV + # + # return market_list + # end end end diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index 67d6716d..6da023b0 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -1,4 +1,10 @@ module FarMar class Product + attr_accessor :id, :name, :vendor_id + def initialize() + @id = id + @name = name + @vendor_id = vendor_id + end end end From 1f43d3938828df9634613f57750c758b4670be27 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Tue, 20 Oct 2015 16:26:31 -0700 Subject: [PATCH 02/42] Working initialize methods for Sale and Vendor classes. --- lib/far_mar/sale.rb | 8 ++++++++ lib/far_mar/vendor.rb | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index 10e3780e..7693c63d 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -1,4 +1,12 @@ module FarMar class Sale + attr_accessor :id, :amount, :purchase_time, :vendor_id, :product_id + def initialize + @id = id + @amount = amount + @purchase_time = purchase_time + @vendor_id = vendor_id + @product_id = product_id + end end end diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 43c213b6..f4fd6c54 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -1,4 +1,11 @@ module FarMar class Vendor + attr_accessor :id, :name, :no_of_employees, :market_id + def initialize + @id = id + @name = name + @no_of_employees = no_of_employees + @market_id = market_id + end end end From 378b73eed816cab1cd000591185cb164b6b6ec92 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Tue, 20 Oct 2015 16:37:17 -0700 Subject: [PATCH 03/42] Got the self.all method for the Market class to work. --- lib/far_mar/market.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index e4c385a9..9e7b90c4 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -3,7 +3,7 @@ module FarMar class Market attr_accessor :id, :name, :address, :city, :county, :state, :zip - def initialize() + def initialize(id, name, address, city, county, state, zip) @id = id @name = name @address = address @@ -13,10 +13,14 @@ def initialize() @zip = zip end - # def self.all - # #returns a collection of Market instances, representing all of the markets described in the CSV - # - # return market_list - # end + def self.all + #returns a collection of Market instances, representing all of the markets described in the CSV + market_array = [] + CSV.read("./support/markets.csv").each do |market| + print market + list_of_markets = Market.new(market[0], market[1], market[2], market[3], market[4], market[5], market[6]) + market_array.push(list_of_markets) + end + end end end From e3790e8f390471bec1cf9f0eb9577dcb37333f29 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Tue, 20 Oct 2015 16:41:09 -0700 Subject: [PATCH 04/42] Working self.all method for the Product class. --- lib/far_mar/product.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index 6da023b0..6bdb813c 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -1,10 +1,20 @@ module FarMar class Product attr_accessor :id, :name, :vendor_id - def initialize() + def initialize(id, name, vendor_id) @id = id @name = name @vendor_id = vendor_id end + + def self.all + #returns a collection of product instances, representing all of the products described in the CSV + product_array = [] + CSV.read("./support/products.csv").each do |product| + print product + list_of_products = Product.new(product[0], product[1], product[2]) + product_array.push(list_of_products) + end + end end end From e166fe2562cfc585034c35bc5cd546efb60abb0c Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Tue, 20 Oct 2015 16:45:20 -0700 Subject: [PATCH 05/42] Working self.all method for the Sale class. --- lib/far_mar/sale.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index 7693c63d..316c28b1 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -1,12 +1,22 @@ module FarMar class Sale attr_accessor :id, :amount, :purchase_time, :vendor_id, :product_id - def initialize + def initialize(id, amount, purchase_time, vendor_id, product_id) @id = id @amount = amount @purchase_time = purchase_time @vendor_id = vendor_id @product_id = product_id end + + def self.all + #returns a collection of sale instances, representing all of the sales described in the CSV + sale_array = [] + CSV.read("./support/sales.csv").each do |sale| + print sale + list_of_sales = Sale.new(sale[0], sale[1], sale[2], sale[3], sale[4]) + sale_array.push(list_of_sales) + end + end end end From f6fc4b39c92ec15df49fe8187f4b283f93e18215 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Tue, 20 Oct 2015 16:48:22 -0700 Subject: [PATCH 06/42] Working self.all method for Vendor class. --- lib/far_mar/vendor.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index f4fd6c54..d65d1ec5 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -1,11 +1,21 @@ module FarMar class Vendor attr_accessor :id, :name, :no_of_employees, :market_id - def initialize + def initialize(id, name, no_of_employees, market_id) @id = id @name = name @no_of_employees = no_of_employees @market_id = market_id end + + def self.all + #returns a collection of vendor instances, representing all of the vendors described in the CSV + vendor_array = [] + CSV.read("./support/vendors.csv").each do |vendor| + print vendor + list_of_vendors = Vendor.new(vendor[0], vendor[1], vendor[2], vendor[3]) + vendor_array.push(list_of_vendors) + end + end end end From 61dafb5326645324ab84c2f6044e728c6c5641a0 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Tue, 20 Oct 2015 18:32:57 -0700 Subject: [PATCH 07/42] Added working self.find method in Market class and corrected self.all method in Market class to return array of instances instead of an array of arrays. --- lib/far_mar/market.rb | 15 +++++++++++---- lib/far_mar/vendor.rb | 4 ++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index 9e7b90c4..f3a25cbf 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -4,7 +4,7 @@ module FarMar class Market attr_accessor :id, :name, :address, :city, :county, :state, :zip def initialize(id, name, address, city, county, state, zip) - @id = id + @id = id.to_i @name = name @address = address @city = city @@ -16,11 +16,18 @@ def initialize(id, name, address, city, county, state, zip) def self.all #returns a collection of Market instances, representing all of the markets described in the CSV market_array = [] - CSV.read("./support/markets.csv").each do |market| - print market - list_of_markets = Market.new(market[0], market[1], market[2], market[3], market[4], market[5], market[6]) + read_file = CSV.read("./support/markets.csv") + read_file.each do |market| + list_of_markets = FarMar::Market.new(market[0], market[1], market[2], market[3], market[4], market[5], market[6]) market_array.push(list_of_markets) end + return market_array + end + + def self.find(id) + #returns an instance of Market where the value in the id field of the CSV file matches the passed parameter + market_array = self.all + market_array.find {|i| i.id == id} end end end diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index d65d1ec5..d9db7826 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -17,5 +17,9 @@ def self.all vendor_array.push(list_of_vendors) end end + + # def self.find(id) + # end + end end From 8cdf1c67866de1a0312476a65689be4841f2e297 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Tue, 20 Oct 2015 18:46:20 -0700 Subject: [PATCH 08/42] Added working self.find(id) method and corrected self.all method to return an array of instances instead of an array of arrays. --- lib/far_mar/product.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index 6bdb813c..65efe40a 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -2,7 +2,7 @@ module FarMar class Product attr_accessor :id, :name, :vendor_id def initialize(id, name, vendor_id) - @id = id + @id = id.to_i @name = name @vendor_id = vendor_id end @@ -10,11 +10,18 @@ def initialize(id, name, vendor_id) def self.all #returns a collection of product instances, representing all of the products described in the CSV product_array = [] - CSV.read("./support/products.csv").each do |product| - print product - list_of_products = Product.new(product[0], product[1], product[2]) + product_file = CSV.read("./support/products.csv") + product_file.each do |product| + list_of_products = FarMar::Product.new(product[0], product[1], product[2]) product_array.push(list_of_products) end + return product_array + end + + def self.find(id) + #returns an instance of Product where the value in the id field of the CSV file matches the passed parameter + product_array = self.all + product_array.find {|i| i.id == id} end end end From 93b063664e428fbd4e8111aa2ff08846f2471fd7 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Tue, 20 Oct 2015 18:53:26 -0700 Subject: [PATCH 09/42] Added working self.find(id) method to the Sale class. Fixed self.all method in Sale class to return an array of instances instead of an array of arrays. --- lib/far_mar/sale.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index 316c28b1..5e83ce23 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -2,7 +2,7 @@ module FarMar class Sale attr_accessor :id, :amount, :purchase_time, :vendor_id, :product_id def initialize(id, amount, purchase_time, vendor_id, product_id) - @id = id + @id = id.to_i @amount = amount @purchase_time = purchase_time @vendor_id = vendor_id @@ -13,10 +13,15 @@ def self.all #returns a collection of sale instances, representing all of the sales described in the CSV sale_array = [] CSV.read("./support/sales.csv").each do |sale| - print sale list_of_sales = Sale.new(sale[0], sale[1], sale[2], sale[3], sale[4]) sale_array.push(list_of_sales) end + return sale_array + end + + def self.find(id) + sale_array = self.all + sale_array.find {|i| i.id == id} end end end From bfd8ef5af71b040e322816d7bb58818976b23fdd Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Tue, 20 Oct 2015 18:57:47 -0700 Subject: [PATCH 10/42] Added working self.find(id) method to Vendor class. Fixed self.all method in the Vendor class to return an array of instances instead of an array of arrays. --- lib/far_mar/vendor.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index d9db7826..eccd7558 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -2,7 +2,7 @@ module FarMar class Vendor attr_accessor :id, :name, :no_of_employees, :market_id def initialize(id, name, no_of_employees, market_id) - @id = id + @id = id.to_i @name = name @no_of_employees = no_of_employees @market_id = market_id @@ -12,14 +12,16 @@ def self.all #returns a collection of vendor instances, representing all of the vendors described in the CSV vendor_array = [] CSV.read("./support/vendors.csv").each do |vendor| - print vendor list_of_vendors = Vendor.new(vendor[0], vendor[1], vendor[2], vendor[3]) vendor_array.push(list_of_vendors) end + return vendor_array end - # def self.find(id) - # end + def self.find(id) + vendor_array = self.all + vendor_array.find {|i| i.id == id} + end end end From bae35810ab1516f819982e7b6a39453f86f8f5ba Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Wed, 21 Oct 2015 10:50:28 -0700 Subject: [PATCH 11/42] Got a working initialize method test for the Market class using instance id 14 of the markets.csv file --- spec/far_mar/market_spec.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index 160df0eb..c1cac25d 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -2,7 +2,7 @@ describe FarMar::Market do before :each do - @market = FarMar::Market.new + @market = FarMar::Market.new(14, "Hartford Farmers Market", "1 Block North of Highway 60 on Rural Street","Hartford","Washington", "Wisconsin", 53027) end context "initializing" do @@ -10,4 +10,22 @@ expect(@market).to be_an_instance_of FarMar::Market end end + + # context "#self.all" do + # it "only returns instances in the markets.csv file" do + # expect(FarMar::Market.all(99999)).to be_falsey + # end + # end + + # context "" do + # it "" do + # expect().to + # end + # end + # + # context "" do + # it "" do + # expect().to + # end + # end end From 64f6520478b386e9c274d28f9cbefe9f6a2c0756 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Wed, 21 Oct 2015 10:52:46 -0700 Subject: [PATCH 12/42] Added working initalize spec for the Product class. --- spec/far_mar/product_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 4e20d380..0c2e3723 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -2,7 +2,7 @@ describe FarMar::Product do before :each do - @product = FarMar::Product.new + @product = FarMar::Product.new(12, "Gorgeous Fish", 6) end context "initializing" do From e4cb6cd865e6a5ca383946933122221ad9af01c6 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Wed, 21 Oct 2015 11:01:24 -0700 Subject: [PATCH 13/42] Added working initialize spec for Sale class and modified @purchase time instance variable to equal purchase_time.to_s. --- lib/far_mar/sale.rb | 2 +- spec/far_mar/sale_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index 5e83ce23..c9a974e3 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -4,7 +4,7 @@ class Sale def initialize(id, amount, purchase_time, vendor_id, product_id) @id = id.to_i @amount = amount - @purchase_time = purchase_time + @purchase_time = purchase_time.to_s @vendor_id = vendor_id @product_id = product_id end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index 90c45a92..3717e557 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -2,7 +2,7 @@ describe FarMar::Sale do before :each do - @sale = FarMar::Sale.new + @sale = FarMar::Sale.new(14, 4978, "2013-11-10 01:51:24 -0800", 3, 4) end context "initializing" do From 9f88e4fc60cef9616f3c58736b177ca192893067 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Wed, 21 Oct 2015 11:04:08 -0700 Subject: [PATCH 14/42] Added working initialize rspec for the Vendor class. --- spec/far_mar/vendor_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 804d90ab..e4885605 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -2,7 +2,7 @@ describe FarMar::Vendor do before :each do - @vendor = FarMar::Vendor.new + @vendor = FarMar::Vendor.new(45,"Hyatt, Conroy and Ortiz",5,10) end context "initializing" do From 5b5e6ff072e1217adf6679c8cd04533ad37a35b6 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Wed, 21 Oct 2015 11:15:06 -0700 Subject: [PATCH 15/42] added a #self.all method to the Market class that returns all instances of the Market class from the CSV file. Test is currently passing. --- spec/far_mar/market_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index c1cac25d..04d97925 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -11,11 +11,11 @@ end end - # context "#self.all" do - # it "only returns instances in the markets.csv file" do - # expect(FarMar::Market.all(99999)).to be_falsey - # end - # end + context "#self.all" do + it "only returns instances in the markets.csv file" do + expect(FarMar::Market.all()).to be_truthy + end + end # context "" do # it "" do From b2f42d0a7f025f413747138043ba105380ecdd53 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Wed, 21 Oct 2015 11:19:29 -0700 Subject: [PATCH 16/42] Got working self.all spec tests for the Product, Sale, and Vendor classes --- spec/far_mar/product_spec.rb | 6 ++++++ spec/far_mar/sale_spec.rb | 6 ++++++ spec/far_mar/vendor_spec.rb | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 0c2e3723..7596f11b 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -10,4 +10,10 @@ expect(@product).to be_an_instance_of FarMar::Product end end + + context "#self.all" do + it "only returns instances in the products.csv file" do + expect(FarMar::Product.all()).to be_truthy + end + end end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index 3717e557..8b81e3c4 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -10,4 +10,10 @@ expect(@sale).to be_an_instance_of FarMar::Sale end end + + context "#self.all" do + it "only returns instances in the sales.csv file" do + expect(FarMar::Sale.all()).to be_truthy + end + end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index e4885605..0e13a268 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -10,4 +10,10 @@ expect(@vendor).to be_an_instance_of FarMar::Vendor end end + + context "#self.all" do + it "only returns instances in the vendors.csv file" do + expect(FarMar::Vendor.all()).to be_truthy + end + end end From 0f5e6d2a8e8d4fc70d83f1e317c7ef0405421e92 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Wed, 21 Oct 2015 14:14:59 -0700 Subject: [PATCH 17/42] Added working self.all rspec with two tests that check if it returns an Array and if the array is the same length as the vendors.csv file. --- spec/far_mar/market_spec.rb | 16 ++++++++-------- spec/far_mar/product_spec.rb | 2 +- spec/far_mar/sale_spec.rb | 2 +- spec/far_mar/vendor_spec.rb | 13 ++++++++----- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index 04d97925..c7ce2a4b 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -2,7 +2,7 @@ describe FarMar::Market do before :each do - @market = FarMar::Market.new(14, "Hartford Farmers Market", "1 Block North of Highway 60 on Rural Street","Hartford","Washington", "Wisconsin", 53027) + @market = FarMar::Market.new("14", "Hartford Farmers Market", "1 Block North of Highway 60 on Rural Street","Hartford","Washington", "Wisconsin", "53027") end context "initializing" do @@ -11,18 +11,18 @@ end end - context "#self.all" do + context ".self.all" do it "only returns instances in the markets.csv file" do expect(FarMar::Market.all()).to be_truthy end end - # context "" do - # it "" do - # expect().to - # end - # end - # + context ".self.find(id)" do + it "returns an instance with a specific id" do + expect(FarMar::Market.find(14)).to be_truthy + end + end + # context "" do # it "" do # expect().to diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 7596f11b..26294a85 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -11,7 +11,7 @@ end end - context "#self.all" do + context ".self.all" do it "only returns instances in the products.csv file" do expect(FarMar::Product.all()).to be_truthy end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index 8b81e3c4..b5ed7be8 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -11,7 +11,7 @@ end end - context "#self.all" do + context ".self.all" do it "only returns instances in the sales.csv file" do expect(FarMar::Sale.all()).to be_truthy end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 0e13a268..5d385bc8 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -5,15 +5,18 @@ @vendor = FarMar::Vendor.new(45,"Hyatt, Conroy and Ortiz",5,10) end - context "initializing" do - it "returns a vendor object" do + context "#initializing" do + it "creates an instance of @vendor" do expect(@vendor).to be_an_instance_of FarMar::Vendor end end - context "#self.all" do - it "only returns instances in the vendors.csv file" do - expect(FarMar::Vendor.all()).to be_truthy + context ".self.all" do + it "returns an array" do + expect(FarMar::Vendor.all().class).to be Array + end + it "returns instances of all lines in vendors.csv" do + expect(FarMar::Vendor.all().length).to eq 2690 end end end From a87ff3c2f5f470c4c0e735c29f1b9f108e317c30 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Wed, 21 Oct 2015 14:21:08 -0700 Subject: [PATCH 18/42] Added working self.all rspec for Vendor class with two tests. --- spec/far_mar/product_spec.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 26294a85..4d33c3e2 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -12,8 +12,14 @@ end context ".self.all" do - it "only returns instances in the products.csv file" do - expect(FarMar::Product.all()).to be_truthy + it "returns an array" do + expect(FarMar::Product.all().class).to be Array + end + it "returns instances of all lines in vendors.csv" do + expect(FarMar::Product.all().length).to eq 8193 end end + + + end From 6a6372098e656af9bdab583949afe7927ead1ed0 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Wed, 21 Oct 2015 14:23:48 -0700 Subject: [PATCH 19/42] Added working rspec with two tests for the self.all method in the Sale class. --- spec/far_mar/sale_spec.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index b5ed7be8..bcf57732 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -12,8 +12,11 @@ end context ".self.all" do - it "only returns instances in the sales.csv file" do - expect(FarMar::Sale.all()).to be_truthy + it "returns an array" do + expect(FarMar::Sale.all().class).to be Array + end + it "returns instances of all lines in vendors.csv" do + expect(FarMar::Sale.all().length).to eq 12798 end end end From ea5c475e00cc3f057a57ec97b72d56ffe8357f3c Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Wed, 21 Oct 2015 14:27:42 -0700 Subject: [PATCH 20/42] Corrected descriptions in it line to be non file specific. All tests are currently passing. --- spec/far_mar/market_spec.rb | 7 +++++-- spec/far_mar/product_spec.rb | 2 +- spec/far_mar/sale_spec.rb | 2 +- spec/far_mar/vendor_spec.rb | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index c7ce2a4b..e49eeaab 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -12,8 +12,11 @@ end context ".self.all" do - it "only returns instances in the markets.csv file" do - expect(FarMar::Market.all()).to be_truthy + it "returns an array" do + expect(FarMar::Market.all().class).to be Array + end + it "returns instances of all lines in the csv" do + expect(FarMar::Market.all().length).to eq 500 end end diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 4d33c3e2..9e71a5b6 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -15,7 +15,7 @@ it "returns an array" do expect(FarMar::Product.all().class).to be Array end - it "returns instances of all lines in vendors.csv" do + it "returns instances of all lines in the csv" do expect(FarMar::Product.all().length).to eq 8193 end end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index bcf57732..d161496d 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -15,7 +15,7 @@ it "returns an array" do expect(FarMar::Sale.all().class).to be Array end - it "returns instances of all lines in vendors.csv" do + it "returns instances of all lines in the csv" do expect(FarMar::Sale.all().length).to eq 12798 end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 5d385bc8..86a3daf8 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -15,7 +15,7 @@ it "returns an array" do expect(FarMar::Vendor.all().class).to be Array end - it "returns instances of all lines in vendors.csv" do + it "returns instances of all lines in the csv" do expect(FarMar::Vendor.all().length).to eq 2690 end end From 99d7d0b271414d1a60c251a0f907c90d8a590df5 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Wed, 21 Oct 2015 14:47:54 -0700 Subject: [PATCH 21/42] Added working self.find(id) rspec with two tests. --- spec/far_mar/vendor_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 86a3daf8..45ea1459 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -3,11 +3,13 @@ describe FarMar::Vendor do before :each do @vendor = FarMar::Vendor.new(45,"Hyatt, Conroy and Ortiz",5,10) + @vendor_2 = FarMar::Vendor.new(2690, "Mann-Lueilwitz", 4, 500) end context "#initializing" do it "creates an instance of @vendor" do expect(@vendor).to be_an_instance_of FarMar::Vendor + expect(@vendor_2).to be_an_instance_of FarMar::Vendor end end @@ -19,4 +21,17 @@ expect(FarMar::Vendor.all().length).to eq 2690 end end + + context ".self.find(id)" do + it "returns an instance of Vendor" do + expect(@vendor.class).to be FarMar::Vendor + end + + it "returns an instance with the same id as the value in the CSV file" do + expect(@vendor.id).to eq 45 + expect(@vendor_2.id).to eq 2690 + end + end + + end From fca722f89656e543e722eddfe4102ee8c92edfbb Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Wed, 21 Oct 2015 14:52:00 -0700 Subject: [PATCH 22/42] Added working self.find(id) tests to market_spec.rb --- spec/far_mar/market_spec.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index e49eeaab..32777fda 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -3,6 +3,7 @@ describe FarMar::Market do before :each do @market = FarMar::Market.new("14", "Hartford Farmers Market", "1 Block North of Highway 60 on Rural Street","Hartford","Washington", "Wisconsin", "53027") + @market_2 = FarMar::Market.new("500", "Montefiore Medical Center Farmers Market_Thursday", "111 E. 210th Street", "Bronx", "Bronx", "New York","10467") end context "initializing" do @@ -21,8 +22,13 @@ end context ".self.find(id)" do - it "returns an instance with a specific id" do - expect(FarMar::Market.find(14)).to be_truthy + it "returns an instance of Market" do + expect(@market.class).to be FarMar::Market + end + + it "returns an instance with the same id as the value in the CSV file" do + expect(@market.id).to eq 14 + expect(@market_2.id).to eq 500 end end From e226113979afc5c9a2192f5c7c68796cecdfc5ef Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Wed, 21 Oct 2015 14:55:51 -0700 Subject: [PATCH 23/42] Added working self.find(id) method to the Product class. All tests passing. --- spec/far_mar/product_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 9e71a5b6..3c0ed6c9 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -3,6 +3,7 @@ describe FarMar::Product do before :each do @product = FarMar::Product.new(12, "Gorgeous Fish", 6) + @product_2 = FarMar::Product.new(8193, "Cruel Beef", 2690) end context "initializing" do @@ -20,6 +21,17 @@ end end + context ".self.find(id)" do + it "returns an instance of Product" do + expect(@product.class).to be FarMar::Product + end + + it "returns an instance with the same id as the value in the CSV file" do + expect(@product.id).to eq 12 + expect(@product_2.id).to eq 8193 + end + end + end From f4b08a530f054a3d0d1964b73dc71abfe6d3186d Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Wed, 21 Oct 2015 15:00:07 -0700 Subject: [PATCH 24/42] Added working self.find(id) method to sale_spec.rb. All tests working. --- spec/far_mar/sale_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index d161496d..89eae87d 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -3,6 +3,7 @@ describe FarMar::Sale do before :each do @sale = FarMar::Sale.new(14, 4978, "2013-11-10 01:51:24 -0800", 3, 4) + @sale_2 = FarMar::Sale.new(12001, 8923.0, "2013-11-12 02:03:31 -0800", 2690, 8192) end context "initializing" do @@ -19,4 +20,15 @@ expect(FarMar::Sale.all().length).to eq 12798 end end + + context ".self.find(id)" do + it "returns an instance of Sale" do + expect(@sale.class).to be FarMar::Sale + end + + it "returns an instance with the same id as the value in the CSV file" do + expect(@sale.id).to eq 14 + expect(@sale_2.id).to eq 12001 + end + end end From 5bf75129807ca192d6c37e9f6a7161dc90720399 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Wed, 21 Oct 2015 16:58:28 -0700 Subject: [PATCH 25/42] Wrote working vendors method for Market class and fixed spec file tests for market and vendor. --- lib/far_mar/market.rb | 13 +++++++++++++ lib/far_mar/vendor.rb | 2 +- spec/far_mar/market_spec.rb | 13 ++++++++----- spec/far_mar/vendor_spec.rb | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index f3a25cbf..6c8db4cd 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -29,5 +29,18 @@ def self.find(id) market_array = self.all market_array.find {|i| i.id == id} end + + def vendors + #returns a collection of FarMar::Vendor instances that are associated with the market by the market_id field + vendor_array = [] + vendor_list = FarMar::Vendor.all + vendor_list.find_all do |i| + if i.market_id == id + vendor_array.push(i) + end + end + return vendor_array + end + end end diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index eccd7558..6549f4c0 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -5,7 +5,7 @@ def initialize(id, name, no_of_employees, market_id) @id = id.to_i @name = name @no_of_employees = no_of_employees - @market_id = market_id + @market_id = market_id.to_i end def self.all diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index 32777fda..f8817e1d 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -32,9 +32,12 @@ end end - # context "" do - # it "" do - # expect().to - # end - # end + context "#vendors" do + it "returns a collection" do + expect(@market.vendors.class).to eq Array + end + it "is a collection of Vendor instances in Far::Mar" do + expect(@market.vendors.length).to eq 8 + end + end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 45ea1459..f5b890d5 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -2,7 +2,7 @@ describe FarMar::Vendor do before :each do - @vendor = FarMar::Vendor.new(45,"Hyatt, Conroy and Ortiz",5,10) + @vendor = FarMar::Vendor.new(45, "Hyatt, Conroy and Ortiz", 5, 10) @vendor_2 = FarMar::Vendor.new(2690, "Mann-Lueilwitz", 4, 500) end From bcffc7fda929a235350857f4fff171c887c86601 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Thu, 22 Oct 2015 11:11:16 -0700 Subject: [PATCH 26/42] Added working market method to the vendor class and two spec tests. --- lib/far_mar/vendor.rb | 13 +++++++++++++ spec/far_mar/vendor_spec.rb | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 6549f4c0..4abd28ce 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -23,5 +23,18 @@ def self.find(id) vendor_array.find {|i| i.id == id} end + def market + # returns the FarMar::Market instance that is associated with this vendor + # using the FarMar::Vendor market_id field + market_array = [] + market_list = FarMar::Market.all + market_list.find_all do |i| + if i.id == market_id + market_array.push(i) + end + end + return market_array + end + end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index f5b890d5..d8ea6e6d 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -31,6 +31,13 @@ expect(@vendor.id).to eq 45 expect(@vendor_2.id).to eq 2690 end + + context "#market" do + it "returns an instance of FarMar::Market associated with the vendor" do + expect(@vendor.market.length).to eq 1 + expect(@vendor_2.market.length).to eq 1 + end + end end From c9c2b610b2bbdb16a1bf66d9b7847f7605d25a87 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Thu, 22 Oct 2015 11:25:17 -0700 Subject: [PATCH 27/42] Added working products method to the Vendor class and added some tests. --- lib/far_mar/product.rb | 2 +- lib/far_mar/sale.rb | 4 ++-- lib/far_mar/vendor.rb | 11 +++++++++++ spec/far_mar/vendor_spec.rb | 6 ++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index 65efe40a..9824228a 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -4,7 +4,7 @@ class Product def initialize(id, name, vendor_id) @id = id.to_i @name = name - @vendor_id = vendor_id + @vendor_id = vendor_id.to_i end def self.all diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index c9a974e3..ce4b2db7 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -5,8 +5,8 @@ def initialize(id, amount, purchase_time, vendor_id, product_id) @id = id.to_i @amount = amount @purchase_time = purchase_time.to_s - @vendor_id = vendor_id - @product_id = product_id + @vendor_id = vendor_id.to_i + @product_id = product_id.to_i end def self.all diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 4abd28ce..9608dd5c 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -36,5 +36,16 @@ def market return market_array end + def products + product_array = [] + product_list = FarMar::Product.all + product_list.find_all do |i| + if i.vendor_id == id + product_array.push(i) + end + end + return product_array + end + end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index d8ea6e6d..bd5e8827 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -38,6 +38,12 @@ expect(@vendor_2.market.length).to eq 1 end end + + context"#products" do + it "returns a collection of Far::Mar product instances" do + expect(@vendor.products.class).to be Array + end + end end From 65861fb2c7404b6ac0766332e55b80f162031833 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Thu, 22 Oct 2015 11:32:05 -0700 Subject: [PATCH 28/42] Added working sales method to the Vendor class and added a test. --- lib/far_mar/vendor.rb | 22 ++++++++++++++++++++++ spec/far_mar/vendor_spec.rb | 11 +++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 9608dd5c..94d44b53 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -47,5 +47,27 @@ def products return product_array end + def products + product_array = [] + product_list = FarMar::Product.all + product_list.find_all do |i| + if i.vendor_id == id + product_array.push(i) + end + end + return product_array + end + + def sales + sales_array = [] + sales_list = FarMar::Sale.all + sales_list.find_all do |i| + if i.vendor_id == id + sales_array.push(i) + end + end + return sales_array + end + end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index bd5e8827..3382f5c5 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -39,12 +39,19 @@ end end - context"#products" do - it "returns a collection of Far::Mar product instances" do + context "#products" do + it "returns a collection of FarMar::Product product instances" do expect(@vendor.products.class).to be Array end end + + context "#sales" do + it "returns a collection of FarMar::Sale sale instances" do + expect(@vendor.sales.class).to be Array + end end + + end From fb5f5e50f8ee5d113aa525537d8c1a82cedca5cd Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Thu, 22 Oct 2015 13:35:01 -0700 Subject: [PATCH 29/42] Added working vendor method to the Product method. Rspec tests are not working currently, but method works in irb. --- lib/far_mar/product.rb | 13 +++++++++++++ lib/far_mar/vendor.rb | 25 ++++++++++++++----------- spec/far_mar/vendor_spec.rb | 3 --- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index 9824228a..3125ebd1 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -23,5 +23,18 @@ def self.find(id) product_array = self.all product_array.find {|i| i.id == id} end + + def vendor + # returns the FarMar::Market instance that is associated with this vendor + # using the FarMar::Vendor market_id field + vendor_array = [] + vendor_list = FarMar::Product.all + vendor_list.find_all do |i| + if i.id == vendor_id + vendor_array.push(i) + end + end + return vendor_array + end end end diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 94d44b53..292ae27f 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -47,17 +47,6 @@ def products return product_array end - def products - product_array = [] - product_list = FarMar::Product.all - product_list.find_all do |i| - if i.vendor_id == id - product_array.push(i) - end - end - return product_array - end - def sales sales_array = [] sales_list = FarMar::Sale.all @@ -69,5 +58,19 @@ def sales return sales_array end + # def revenue + # sales.each do |i| + # + # come back to this one + # end + + # def self.by_market(market_id) + # by_market_array = [] + # by_market_array = self.find(market_id) + # by_market_array.find_all do |i| + # i.market_id == @id + # end + # end + end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 3382f5c5..2f388654 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -50,8 +50,5 @@ expect(@vendor.sales.class).to be Array end end - - - end From 92a9ac53570c6235b4ae717347aedfe413408be6 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Thu, 22 Oct 2015 13:39:50 -0700 Subject: [PATCH 30/42] Added working sales method to Product class. --- lib/far_mar/product.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index 3125ebd1..464408b8 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -36,5 +36,16 @@ def vendor end return vendor_array end + + def sales + sales_array = [] + sales_list = FarMar::Sale.all + sales_list.find_all do |i| + if i.product_id == id + sales_array.push(i) + end + end + return sales_array + end end end From f355d94c0233036ad151b49130d17a13e8d919e5 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Thu, 22 Oct 2015 13:49:01 -0700 Subject: [PATCH 31/42] fixed vendor_spec.rb file. 90% code coverage. --- spec/far_mar/vendor_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 2f388654..d2f3748c 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -31,7 +31,8 @@ expect(@vendor.id).to eq 45 expect(@vendor_2.id).to eq 2690 end - + end + context "#market" do it "returns an instance of FarMar::Market associated with the vendor" do expect(@vendor.market.length).to eq 1 @@ -50,5 +51,5 @@ expect(@vendor.sales.class).to be Array end end - + end From a2af6e63caa8f0d8070fd81873f122cf3f314dda Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Thu, 22 Oct 2015 14:49:27 -0700 Subject: [PATCH 32/42] Added working product method for sale class. --- lib/far_mar/sale.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index ce4b2db7..260acf8a 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -23,5 +23,34 @@ def self.find(id) sale_array = self.all sale_array.find {|i| i.id == id} end + + def vendor + # returns the FarMar::Market instance that is associated with this vendor + # using the FarMar::Vendor market_id field + vendor_array = [] + vendor_list = FarMar::Vendor.all + vendor_list.find_all do |i| + if i.id == vendor_id + vendor_array.push(i) + end + end + return vendor_array + end + + def product + product_list = FarMar::Product.all + product_list.find do |product| + product.id == self.product_id + end + end + # product_array = [] + # sales_list = FarMar::Sale.all + # sales_list.find_all do |sale| + # if sale.product_id == id + # product_array.push(i) + # end + # end + # return product_array + end end From 350f21d22a8123001ef2d934b2b5ae5e46ee41d3 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Thu, 22 Oct 2015 15:02:50 -0700 Subject: [PATCH 33/42] Added tests for product method in sale spec. All tests passing. --- spec/far_mar/sale_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index 89eae87d..e23ff8ae 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -31,4 +31,16 @@ expect(@sale_2.id).to eq 12001 end end + + context "#product" do + it "returns an instance of product" do + expect(@sale.product).to be_an_instance_of FarMar::Product + end + + it "returns the right product" do + expect(@sale.product.id).to eq 4 + expect(@sale_2.product.id).to eq 8192 + end + end + end From 20192f6ed2d08fb23a884cf4292bb83185b3d001 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Thu, 22 Oct 2015 17:20:45 -0700 Subject: [PATCH 34/42] Added working revenue method. --- lib/far_mar/sale.rb | 11 ++--------- lib/far_mar/vendor.rb | 33 ++++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index 260acf8a..e6f0946a 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -3,7 +3,7 @@ class Sale attr_accessor :id, :amount, :purchase_time, :vendor_id, :product_id def initialize(id, amount, purchase_time, vendor_id, product_id) @id = id.to_i - @amount = amount + @amount = amount.to_i @purchase_time = purchase_time.to_s @vendor_id = vendor_id.to_i @product_id = product_id.to_i @@ -43,14 +43,7 @@ def product product.id == self.product_id end end - # product_array = [] - # sales_list = FarMar::Sale.all - # sales_list.find_all do |sale| - # if sale.product_id == id - # product_array.push(i) - # end - # end - # return product_array + end end diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 292ae27f..177bd16e 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -58,12 +58,38 @@ def sales return sales_array end - # def revenue - # sales.each do |i| + def revenue + total_amount = 0 + sales.each do |sale| + total_amount += sale.amount + end + + return total_amount + + #I am currently in a particular instance of vendor + #I want to find all of the vendors sales + + #for each instance in the array, I want to take out the amount part + #then take out the number that is saved in the amount variable + #and add each of the amounts in the list together + # amount_array = [] + + + + # amount_array.push + + # return amount_array + end + + + # .inject { |sum, pennies| sum + pennies } # # come back to this one # end + end + end + # def self.by_market(market_id) # by_market_array = [] # by_market_array = self.find(market_id) @@ -71,6 +97,3 @@ def sales # i.market_id == @id # end # end - - end -end From 2da2f50e18a52321b45141512b5458881a5f90da Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Thu, 22 Oct 2015 20:08:08 -0700 Subject: [PATCH 35/42] Added working self.by_market class method to the Vendor class. --- lib/far_mar/vendor.rb | 41 +++++++++++-------------------------- spec/far_mar/vendor_spec.rb | 8 +++++++- 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 177bd16e..499dd87e 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -63,37 +63,20 @@ def revenue sales.each do |sale| total_amount += sale.amount end - return total_amount - - #I am currently in a particular instance of vendor - #I want to find all of the vendors sales - - #for each instance in the array, I want to take out the amount part - #then take out the number that is saved in the amount variable - #and add each of the amounts in the list together - # amount_array = [] - - - - # amount_array.push - - # return amount_array end + def self.by_market(market_id) + #returns all of the vendors with the given market_id + vendors_in_a_market_array = [] + vendor_list = FarMar::Vendor.all + vendor_list.find_all do |vendor| + if vendor.market_id == market_id + vendors_in_a_market_array.push(vendor) + end + end + return vendors_in_a_market_array + end - # .inject { |sum, pennies| sum + pennies } - # - # come back to this one - # end - - end end - - # def self.by_market(market_id) - # by_market_array = [] - # by_market_array = self.find(market_id) - # by_market_array.find_all do |i| - # i.market_id == @id - # end - # end +end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index d2f3748c..48a3eba4 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -32,7 +32,7 @@ expect(@vendor_2.id).to eq 2690 end end - + context "#market" do it "returns an instance of FarMar::Market associated with the vendor" do expect(@vendor.market.length).to eq 1 @@ -52,4 +52,10 @@ end end + context ".self.by_market" do + it "returns all the vendors with the given market_id" do + expect(FarMar::Vendor.by_market(10)).to eq @vendor + end + end + end From f80aeeed18b5ae8a1910fb30f5c7b05bf39969ea Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Thu, 22 Oct 2015 20:23:01 -0700 Subject: [PATCH 36/42] Added working self.by_vendor(vendor_id) method to the Product class. --- lib/far_mar/product.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index 464408b8..d6c1d78f 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -47,5 +47,18 @@ def sales end return sales_array end + + def self.by_vendor(vendor_id) + #returns all of the products with the given vendor_id + products_sold_by_a_vendor_array = [] + product_list = FarMar::Product.all + product_list.find_all do |product| + if product.vendor_id == vendor_id + products_sold_by_a_vendor_array.push(product) + end + end + return products_sold_by_a_vendor_array + end + end end From 762e2c1d3c7d642a4a91f473d890f6187d4573a2 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Fri, 23 Oct 2015 09:40:36 -0700 Subject: [PATCH 37/42] Added working self.between(beginning_time, end_time)method --- lib/far_mar/sale.rb | 19 +++++++++++++++++++ spec/far_mar/product_spec.rb | 6 +++++- spec/far_mar/vendor_spec.rb | 10 +++++----- spec/spec_helper.rb | 16 ++++++++++++++++ 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index e6f0946a..b8387d3c 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -45,5 +45,24 @@ def product end + def self.between(beginning_time, end_time) + #returns a collection of FarMar::Sale + #objects where the purchase time is between the two times given as arguments + sales_between_times_array = [] + list_of_sales = FarMar::Sale.all + list_of_sales.find_all do |sale| + if (beginning_time < sale.purchase_time) && (sale.purchase_time < end_time) + sales_between_times_array.push(sale) + end + end + return sales_between_times_array + end +# @begin = DateTime.strptime("2013-11-06 08:35:40 -0800", "%Y-%m-%d %H:%M:%S %z") +# @end = DateTime.strptime("2013-11-13 08:35:16 -0800", "%Y-%m-%d +# +# list_of_sales.each do |sale_object| +# sale_object.purchase_time > beginning_time && sale_object.purchase_time < end_time + + end end diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 3c0ed6c9..1d496bcd 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -32,6 +32,10 @@ end end - + context ".self.by_vendor(vendor_id)" do + it "returns all of the products with a given vendor id" do + expect(FarMar::Product.by_vendor(6).length).to eq 3 + end + end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 48a3eba4..ae2f4b39 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -52,10 +52,10 @@ end end - context ".self.by_market" do - it "returns all the vendors with the given market_id" do - expect(FarMar::Vendor.by_market(10)).to eq @vendor - end - end + # context ".self.by_market" do + # it "returns all the vendors with the given market_id" do + # expect(FarMar::Vendor.by_market(10)).to eq + # end + # end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f7dc6dfb..14061ed2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,3 +2,19 @@ SimpleCov.start require './lib/far_mar' + +# RSpec.configure do |config| +# config.after(:suite) do +# num_failed = RSpec.world +# .filtered_examples +# .values +# .flatten +# .count(&:exception) +# ​ +# if num_failed == 0 +# `say "You did it Amy! You're amazing!"` +# else +# `say "Keep going! Only #{num_failed} #{num_failed > 1 ? "tests" : "test"} to go!"` +# end +# end +# end From f3b18235540d5b3dd7c66a1bd880177c7f6f12d9 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Fri, 23 Oct 2015 09:55:14 -0700 Subject: [PATCH 38/42] Added working spec for .self.between(beginning_time, end_time) method. --- spec/far_mar/sale_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index e23ff8ae..0ceee323 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -43,4 +43,14 @@ end end + context ".self.between(beginning_time, end_time)" do + it "returns an array of sales" do + expect(FarMar::Sale.between("2013-11-07 20:25:38 -0800", "2013-11-08 10:38:56 -0800").class).to eq Array + end + + it "returns the expected number of sales" do + expect(FarMar::Sale.between("2013-11-07 20:25:38 -0800", "2013-11-08 10:38:56 -0800").length).to eq 1090 + end + end + end From 10344904a8f49434ccc3c14106edfe19a08b7dac Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Fri, 23 Oct 2015 13:06:51 -0700 Subject: [PATCH 39/42] Added working self.find method to sale class. All specs passing. --- lib/far_mar/sale.rb | 17 ++++++++--------- spec/far_mar/sale_spec.rb | 8 +++++++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index b8387d3c..f22cccd2 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -20,27 +20,26 @@ def self.all end def self.find(id) - sale_array = self.all - sale_array.find {|i| i.id == id} + #self.find(id) - returns an instance of Sale where the value of the id field + #in the CSV matches the passed parameter. + self.all.find {|i| i.id == id} end def vendor # returns the FarMar::Market instance that is associated with this vendor # using the FarMar::Vendor market_id field - vendor_array = [] vendor_list = FarMar::Vendor.all - vendor_list.find_all do |i| - if i.id == vendor_id - vendor_array.push(i) - end + vendor_list.find do |vendor| + vendor.id == vendor_id end - return vendor_array end def product + #product - returns the FarMar::Product + # instance that is associated with this sale using the FarMar::Sale product_id field product_list = FarMar::Product.all product_list.find do |product| - product.id == self.product_id + product.id == product_id end end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index 0ceee323..d5dc68b9 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -43,6 +43,12 @@ end end + context "#vendor" do + it "returns an instance of a vendor" do + expect(@sale.vendor).to be_an_instance_of FarMar::Vendor + end + end + context ".self.between(beginning_time, end_time)" do it "returns an array of sales" do expect(FarMar::Sale.between("2013-11-07 20:25:38 -0800", "2013-11-08 10:38:56 -0800").class).to eq Array @@ -52,5 +58,5 @@ expect(FarMar::Sale.between("2013-11-07 20:25:38 -0800", "2013-11-08 10:38:56 -0800").length).to eq 1090 end end - + end From 27edf3f4001dfe6e7dd1c11065cd9a192a5ed75c Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Fri, 23 Oct 2015 13:31:19 -0700 Subject: [PATCH 40/42] Added working product spec test. All tests passing. --- lib/far_mar/market.rb | 3 +-- lib/far_mar/product.rb | 24 ++++++++++++++---------- lib/far_mar/vendor.rb | 3 +-- spec/far_mar/product_spec.rb | 6 ++++++ 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index 6c8db4cd..937abcd1 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -26,8 +26,7 @@ def self.all def self.find(id) #returns an instance of Market where the value in the id field of the CSV file matches the passed parameter - market_array = self.all - market_array.find {|i| i.id == id} + self.all.find {|i| i.id == id} end def vendors diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index d6c1d78f..b86f8502 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -20,21 +20,25 @@ def self.all def self.find(id) #returns an instance of Product where the value in the id field of the CSV file matches the passed parameter - product_array = self.all - product_array.find {|i| i.id == id} + self.all.find {|i| i.id == id} end def vendor # returns the FarMar::Market instance that is associated with this vendor # using the FarMar::Vendor market_id field - vendor_array = [] - vendor_list = FarMar::Product.all - vendor_list.find_all do |i| - if i.id == vendor_id - vendor_array.push(i) - end + # vendor_array = [] + # vendor_list = FarMar::Product.all + # vendor_list.find_all do |i| + # if i.id == vendor_id + # vendor_array.push(i) + # end + # end + # return vendor_array + + vendor_list = FarMar::Vendor.all + vendor_list.find do |vendor| + vendor.id == vendor_id end - return vendor_array end def sales @@ -59,6 +63,6 @@ def self.by_vendor(vendor_id) end return products_sold_by_a_vendor_array end - + end end diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 499dd87e..b0934a3c 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -19,8 +19,7 @@ def self.all end def self.find(id) - vendor_array = self.all - vendor_array.find {|i| i.id == id} + self.all.find {|i| i.id == id} end def market diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 1d496bcd..0976860b 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -32,6 +32,12 @@ end end + context "#vendor" do + it "returns an instance of Vendor" do + expect(@product.vendor).to be_an_instance_of FarMar::Vendor + end + end + context ".self.by_vendor(vendor_id)" do it "returns all of the products with a given vendor id" do expect(FarMar::Product.by_vendor(6).length).to eq 3 From 80696d7e247a7246f881baf69042e3d01f0edd56 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Fri, 23 Oct 2015 15:13:55 -0700 Subject: [PATCH 41/42] Added working rspec tests for self.find(id) method in the product_spec.rb file. --- lib/far_mar/product.rb | 7 +++++-- lib/far_mar/sale.rb | 2 +- spec/far_mar/product_spec.rb | 13 +++++++++++-- spec/far_mar/vendor_spec.rb | 16 +++++++++++----- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index b86f8502..f0fe300e 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -20,7 +20,7 @@ def self.all def self.find(id) #returns an instance of Product where the value in the id field of the CSV file matches the passed parameter - self.all.find {|i| i.id == id} + all.find {|i| i.id == id} end def vendor @@ -42,10 +42,13 @@ def vendor end def sales + #sales - returns a collection + #of FarMar::Sale instances that are associated + #using the FarMar::Sale product_id field. sales_array = [] sales_list = FarMar::Sale.all sales_list.find_all do |i| - if i.product_id == id + if i.product_id == @id sales_array.push(i) end end diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index f22cccd2..b8bbc666 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -22,7 +22,7 @@ def self.all def self.find(id) #self.find(id) - returns an instance of Sale where the value of the id field #in the CSV matches the passed parameter. - self.all.find {|i| i.id == id} + all.find {|i| i.id == id} end def vendor diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 0976860b..920f9a98 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -23,9 +23,12 @@ context ".self.find(id)" do it "returns an instance of Product" do - expect(@product.class).to be FarMar::Product + expect(FarMar::Product.find(12)).to be_an_instance_of FarMar::Product end + it "returns the right instance" do + expect(FarMar::Product.find(12).name).to eq "Gorgeous Fish" + end it "returns an instance with the same id as the value in the CSV file" do expect(@product.id).to eq 12 expect(@product_2.id).to eq 8193 @@ -36,7 +39,13 @@ it "returns an instance of Vendor" do expect(@product.vendor).to be_an_instance_of FarMar::Vendor end - end + end + + context "#sales" do + it "returns a collection of FarMar::Sale instances" do + expect(@product.sales.length).to eq 0 + end + end context ".self.by_vendor(vendor_id)" do it "returns all of the products with a given vendor id" do diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index ae2f4b39..b767e9c6 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -52,10 +52,16 @@ end end - # context ".self.by_market" do - # it "returns all the vendors with the given market_id" do - # expect(FarMar::Vendor.by_market(10)).to eq - # end - # end + context "#revenue" do + it "returns a sum of all the vendors sales" do + expect(@vendor.revenue).to eq 10150 + end + end + + context ".self.by_market(market_id)" do + it "returns all the vendors with the given market_id" do + expect(FarMar::Vendor.by_market(10).length).to eq 9 + end + end end From 490bf41fd358e841f9e53192b9deb06704c95e34 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Fri, 23 Oct 2015 15:27:49 -0700 Subject: [PATCH 42/42] Added working #sales test for Product class in the product_spec.rb file. --- lib/far_mar/product.rb | 2 +- spec/far_mar/market_spec.rb | 4 ++-- spec/far_mar/product_spec.rb | 2 +- spec/far_mar/sale_spec.rb | 4 ++-- spec/far_mar/vendor_spec.rb | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index f0fe300e..fd49072e 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -48,7 +48,7 @@ def sales sales_array = [] sales_list = FarMar::Sale.all sales_list.find_all do |i| - if i.product_id == @id + if i.product_id == id sales_array.push(i) end end diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index f8817e1d..b8aa4e55 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -22,8 +22,8 @@ end context ".self.find(id)" do - it "returns an instance of Market" do - expect(@market.class).to be FarMar::Market + it "returns the right instance" do + expect(FarMar::Market.find(14).name).to eq "Hartford Farmers Market" end it "returns an instance with the same id as the value in the CSV file" do diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 920f9a98..03963e8f 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -43,7 +43,7 @@ context "#sales" do it "returns a collection of FarMar::Sale instances" do - expect(@product.sales.length).to eq 0 + expect(@product_2.sales.length).to eq 2 end end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index d5dc68b9..32d97d24 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -22,8 +22,8 @@ end context ".self.find(id)" do - it "returns an instance of Sale" do - expect(@sale.class).to be FarMar::Sale + it "returns the right instance" do + expect(FarMar::Sale.find(14).amount).to eq 4978 end it "returns an instance with the same id as the value in the CSV file" do diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index b767e9c6..a6c85910 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -23,8 +23,8 @@ end context ".self.find(id)" do - it "returns an instance of Vendor" do - expect(@vendor.class).to be FarMar::Vendor + it "returns the right instance" do + expect(FarMar::Vendor.find(45).name).to eq "Hyatt, Conroy and Ortiz" end it "returns an instance with the same id as the value in the CSV file" do