diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..2dc07618
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,36 @@
+*.gem
+*.rbc
+/.config
+/coverage/
+/specs/coverage
+/InstalledFiles
+/pkg/
+/spec/reports/
+/test/tmp/
+/test/version_tmp/
+/tmp/
+
+## Specific to RubyMotion:
+.dat*
+.repl_history
+build/
+
+## Documentation cache and generated files:
+/.yardoc/
+/_yardoc/
+/doc/
+/rdoc/
+
+## Environment normalisation:
+/.bundle/
+/vendor/bundle
+/lib/bundler/man/
+
+# for a library or gem, you might want to ignore these files since the code is
+# intended to run in multiple environments; otherwise, check them in:
+# Gemfile.lock
+# .ruby-version
+# .ruby-gemset
+
+# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
+.rvmrc
diff --git a/README.md b/README.md
index 576e36ae..af331f39 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,14 @@
# FarMar: The Farmers' Market Finder
In this assignment we will be creating an application to look up farmers markets and their related vendors, products, and sales. We will use __CSV__ files as our _database_.
+ Project Data
+ * [Markets](#markets)
+ * [Vendors](#vendors)
+ * [Products](#products)
+ * [Sales](#sales)
+ [Baseline](#baseline)
+ [Primary](#primary)
+
## Learning Goals
- Reinforce and practice all of the Ruby and programming concepts we've covered in class
- Practice writing specs and using TDD
@@ -44,7 +52,7 @@ For example, `Sale` is a very generic _class_ name that could very realistically
You must have __90% test coverage__ from `simplecov`. The HTML files that are generated from `simplecov` should _not_ be included in your git repository. Tests should be in the form of __minitest specs__. Complete the necessary boilerplate to create a `Rakefile` and `spec_helper.rb` so that all of your tests run when you run `$ rake` from the project root.
### Project Data
-#### FarMar::Market
+#### FarMar::Market
Each individual market has many vendors associated with it. The `FarMar::Market` data, in order in the CSV, consists of:
1. ID - (Fixnum) a unique identifier for that market
@@ -55,7 +63,7 @@ Each individual market has many vendors associated with it. The `FarMar::Market`
6. State - (String) state in which the market is located
7. Zip - (String) zipcode in which the market is located
-#### FarMar::Vendor
+#### FarMar::Vendor
Each vendor belongs to a market, the `market_id` field refers to the `FarMar::Market` ID field.
Each vendor has many products for sell. The `FarMar::Vendor` data, in order in the CSV, consists of:
@@ -64,14 +72,14 @@ Each vendor has many products for sell. The `FarMar::Vendor` data, in order in t
3. No. of Employees - (Fixnum) How many employees the vendor has at the market
4. Market_id - (Fixnum) a reference to which market the vendor attends
-#### FarMar::Product
+#### FarMar::Sale
Each sale belongs to a vendor __AND__ a product. The `vendor_id` and `product_id` fields refer to the `FarMar::Vendor` and `FarMar::Product` ID fields, respectively. The `FarMar::Sale` data, in order in the CSV, consists of:
1. ID - (Fixnum) uniquely identifies the sale
@@ -81,7 +89,7 @@ Each sale belongs to a vendor __AND__ a product. The `vendor_id` and `product_id
5. Product_id - (Fixnum) a reference to which product was sold
## Requirements
-### Baseline
+### Baseline
#### Project Setup
1. You'll be working as an individual on this project.
1. Fork the Ada-C6 repo to your Github account.
@@ -101,7 +109,7 @@ Each sale belongs to a vendor __AND__ a product. The `vendor_id` and `product_id
- Complete the boilerplate necessary for testing. You should be able to `$ rake` from the project root to run your specs. Have at least one spec to verify this setup before submitting your baseline.
- **Once you have completed your baseline, you must submit a pull-request and get it approved by an instructor.**
-## Primary Requirements
+## Primary Requirements
### For each of the data classes build the following methods:
1. `self.all`: returns a collection of instances, representing all of the objects described in the CSV
1. `self.find(id)`: returns an instance of the object where the value of the `id` field in the CSV matches the passed parameter.
@@ -154,4 +162,4 @@ Each sale belongs to a vendor __AND__ a product. The `vendor_id` and `product_id
#### Try some inheritance or some composition
- __Inheritance:__ Create a new _class_ that defines the shared/duplicated methods (i.e., `find`, `all`). Update your data classes to _inherit_ this _class_ .
-- __Composition with a Mixin:__ Create a new _module_ that defines the duplicated methods (i.e., `find`, `all`). Update your data classes to _mixin_ this _module_.
+- __Composition with a Mixin:__ Create a new _module_ that defines the duplicated methods (i.e., `find`, `all`). Update your data classes to _mixin_ this _module_.
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 00000000..82e5a661
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,7 @@
+require 'rake/testtask'
+
+Rake::TestTask.new do |t|
+ t.test_files = FileList['specs/*_spec.rb']
+ end
+
+task default: :test
diff --git a/far_mar.rb b/far_mar.rb
new file mode 100644
index 00000000..304ea712
--- /dev/null
+++ b/far_mar.rb
@@ -0,0 +1,11 @@
+require_relative "lib/market.rb"
+require_relative "lib/vendor.rb"
+require_relative "lib/product.rb"
+require_relative "lib/sale.rb"
+require 'csv'
+require 'date'
+module FarMar
+ # string_date = "2013-11-09 23:42:41 -0800"
+ # date = DateTime.parse(string_date)
+ # puts date
+end
diff --git a/lib/market.rb b/lib/market.rb
new file mode 100644
index 00000000..8502c093
--- /dev/null
+++ b/lib/market.rb
@@ -0,0 +1,49 @@
+module FarMar
+ class Market
+
+ attr_reader :id, :name, :address, :city, :county, :state, :zipcode
+
+ def initialize(id, name, address, city, county, state, zipcode)
+ @id = id
+ @name = name
+ @address = address
+ @city = city
+ @county = county
+ @state = state
+ @zipcode = zipcode
+ end
+
+ # Returns a collection of instances, representing all of the objects described in the CSV
+ def self.all
+ markets = {}
+ CSV.read('support/markets.csv').each do |line|
+ #these are the arguments fed into the class instance -don't confuse with an array
+ market = self.new(line[0].to_i,line[1],line[2],line[3],line[4],line[5],line[6])
+ markets[market.id] = market
+ end
+ return markets
+ end
+
+ # Returns an instance of the object where the value of the id field in the CSV matches the passed parameter.
+ def self.find(id)
+ markets = self.all
+ return markets[id]
+ end
+
+ #Returns a collection of Vendor instances, associated with the market by the market_id field.
+ def vendors
+ market_vendors = Vendor.all.select { |vendor_id, vendor|
+ vendor.market_id == id } # id is attr_reader id, no need for argument
+ return market_vendors
+ # Refactoring from:
+ # market_vendors = {}
+ # Vendor.all.each do |vendor_id, vendor|
+ # if vendor.market_id == id # id is attr_reader id, no need for argument
+ # market_vendors[vendor_id] = vendor
+ # end
+ # end #each
+ # return market_vendors
+ end
+
+ end #class
+end #module
diff --git a/lib/product.rb b/lib/product.rb
new file mode 100644
index 00000000..01ddf5cc
--- /dev/null
+++ b/lib/product.rb
@@ -0,0 +1,77 @@
+module FarMar
+ class Product
+ attr_reader :id, :name, :vendor_id
+ def initialize(id,name,vendor_id)
+ @id = id
+ @name = name
+ @vendor_id = vendor_id
+ end
+
+ # Returns a collection of instances, representing all of the objects described in the CSV
+ def self.all
+ products = {}
+ CSV.read('support/products.csv').each do |line|
+ product = self.new(line[0].to_i,line[1],line[2].to_i)
+ products[product.id] = product
+ end
+ return products
+ end
+
+ # Returns an instance of the object where the value of the id field in the CSV matches the passed parameter.
+ def self.find(id)
+ products = self.all
+ return products[id]
+ end
+
+ # Returns the Vendor instance, associated with this vendor using the Product vendor_id field
+ def vendor
+ product_vendor_array = Vendor.all.find { |ven_id, ven|
+ ven_id == vendor_id }
+ product_vendor = product_vendor_array[1] # second element in find array
+ return product_vendor # vendor object
+
+ # Refactoring:
+ # product_vendor = Vendor.new(:id, :name, :number_of_employees, :market_id)
+ # Vendor.all.each do |ven_id, ven|
+ # if ven_id == vendor_id
+ # product_vendor = ven
+ # break
+ # end
+ # end
+ # return product_vendor # vendor object, not hash
+ end
+
+ # Returns a collection of Sale instances, associated using the Sale product_id field.
+ def sales
+ product_sales = Sale.all.select { |sale_id, sale|
+ sale.product_id == id }
+ return product_sales
+
+ # Refactoring:
+ # product_sales = {}
+ # Sale.all.each do |sale_id, sale|
+ # if sale.product_id == id
+ # product_sales[sale_id] = sale
+ # end
+ # end
+ # return product_sales
+ end
+
+ #Returns the number of times this product has been sold.
+ def number_of_sales
+ return sales.length
+ end
+
+ #Returns all of the products with the given vendor_id
+ def self.by_vendor(ven_id)
+ vendor_products = {}
+ self.all.each do |pro_id, pro|
+ if ven_id == pro.vendor_id
+ vendor_products[pro_id] = pro
+ end
+ end
+ return vendor_products
+ end
+
+ end
+end
diff --git a/lib/sale.rb b/lib/sale.rb
new file mode 100644
index 00000000..c860d7d0
--- /dev/null
+++ b/lib/sale.rb
@@ -0,0 +1,67 @@
+module FarMar
+ class Sale
+
+ attr_reader :id, :amount, :purchase_time, :vendor_id, :product_id
+
+ def initialize(id, amount, purchase_time, vendor_id, product_id)
+ @id = id
+ @amount = amount #in cents
+ @purchase_time = purchase_time
+ @vendor_id = vendor_id
+ @product_id = product_id
+ end
+
+ # Returns a collection of instances, representing all of the objects described in the CSV
+ def self.all
+ sales = {}
+ CSV.read('support/sales.csv').each do |line|
+ sale = self.new(line[0].to_i,line[1].to_i,DateTime.parse(line[2]),line[3].to_i,line[4].to_i)
+ sales[sale.id] = sale
+ end
+ return sales # Never, ever, ever, ever, ever (!!) forget this one again.
+ end
+
+ # Returns an instance of the object where the value of the id field in the CSV matches the passed parameter.
+ def self.find(id)
+ vendors = self.all
+ return vendors[id]
+ end
+
+ # Returns the Vendor instance, associated with this sale, using the Sale vendor_id field
+ def vendor
+ sale_vendor = Vendor.new(:id, :name, :number_of_employees, :market_id)
+ Vendor.all.each do |ven_id, ven|
+ if ven_id == vendor_id
+ sale_vendor = ven
+ end
+ end
+ return sale_vendor
+ end
+
+ #Returns the Product instance, associated with this sale using the Sale product_id field
+ def product
+ sale_product = Product.new(:id, :name, :vendor_id)
+ Product.all.each do |pro_id, pro|
+ if pro_id == product_id
+ sale_product = pro
+ break
+ end
+ end
+ return sale_product
+ end
+
+ # Returns a collection of Sale objects where the purchase time is between the two times given as arguments
+ def self.between(beginning_time, end_time)
+ sales_within_times = {}
+ self.all.each do |sal_id, sal|
+ if beginning_time <= sal.purchase_time
+ if end_time >= sal.purchase_time
+ sales_within_times[sal_id] = sal
+ end
+ end
+ end
+ return sales_within_times
+ end
+
+ end #class
+end #module
diff --git a/lib/vendor.rb b/lib/vendor.rb
new file mode 100644
index 00000000..48eade81
--- /dev/null
+++ b/lib/vendor.rb
@@ -0,0 +1,81 @@
+module FarMar
+ class Vendor
+ attr_reader :id, :name, :number_of_employees, :market_id
+
+ def initialize(id,name,number_of_employees,market_id)
+ @id = id
+ @name = name
+ @number_of_employees = number_of_employees
+ @market_id = market_id
+ end
+
+ # Returns a collection of instances, representing all of the objects described in the CSV
+ def self.all
+ vendors = {}
+ CSV.read('support/vendors.csv').each do |line|
+ vendor = self.new(line[0].to_i,line[1],line[2].to_i,line[3].to_i)
+ vendors[vendor.id] = vendor
+ end
+ return vendors
+ end
+
+ # Returns an instance of the object where the value of the id field in the CSV matches the passed parameter.
+ def self.find(id)
+ vendors = self.all
+ return vendors[id]
+ end
+
+ # Returns the Market instance, associated with this vendor using the Vendor market_id field
+ def market
+ return @market_id
+ end
+
+ # Returns a collection of Product instances, associated by the Product vendor_id field.
+ def products
+ vendor_products = Product.all.select { |product_id, product| product.vendor_id == id}
+ return vendor_products
+ # Refactor from the old method below (turns out select does return a hash when used on a hash):
+ # vendor_products = {}
+ # Product.all.each do |product_id, product|
+ # if product.vendor_id == id # finding id because it is an attr_reader
+ # vendor_products[product_id] = product # creates a hash of products carried by specific vendor
+ # end
+ # end
+ # return vendor_products
+ end
+
+ #Returns a collection of Sale instances, associated by the vendor_id field.
+ def sales
+ vendor_sales = Sale.all.select { |sale_id, sale|
+ sale.vendor_id == id }
+ return vendor_sales
+ # Before refactoring:
+ # vendor_sales = {}
+ # Sale.all.each do |sale_id, sale|
+ # if sale.vendor_id == id
+ # vendor_sales[sale_id] = sale
+ # end
+ # end #each
+ # return vendor_sales
+ end #def
+
+ # Returns the the sum of all of the vendor's sales (in cents)
+ def revenue
+ revenue = 0
+ sales.each do |sale_id, sale|
+ revenue += (sale.amount) #in cents
+ end
+ return revenue
+ end
+
+ # Returns all of the vendors with the given market_ids
+ def self.by_market(market_id) # nifty select method! returns only those that are true as an array though
+ market_vendors = self.all.select { |vendor_id, vendor|
+ vendor.market == market_id }
+ return market_vendors # it is an array of hash
+ end
+
+ end
+
+
+end
diff --git a/specs/market_spec.rb b/specs/market_spec.rb
new file mode 100644
index 00000000..68700a6f
--- /dev/null
+++ b/specs/market_spec.rb
@@ -0,0 +1,75 @@
+require_relative 'spec_helper'
+module FarMar
+
+ describe Market do
+ describe "#initialize" do
+ let(:market) { Market.new(:id, :name, :address, :city, :county, :state, :zipcode) }
+
+ it "can create an instance of Market" do
+ market.must_be_instance_of(Market)
+ end
+ it "must respond to (have parameters of) of market information" do
+ market.must_respond_to(:id)
+ market.must_respond_to(:name)
+ market.must_respond_to(:address)
+ market.must_respond_to(:city)
+ market.must_respond_to(:county)
+ market.must_respond_to(:state)
+ market.must_respond_to(:zipcode)
+ end
+ end
+
+ describe "#self.all" do
+
+ it "should return a hash" do
+ Market.all.must_be_instance_of(Hash)
+ end
+ it "should return information about markets" do
+ # first listed market
+ Market.all[1].id.must_equal(1)
+ Market.all[1].name.must_equal("People's Co-op Farmers Market")
+ Market.all[1].address.must_equal("30th and Burnside")
+ Market.all[1].city.must_equal("Portland")
+ Market.all[1].county.must_equal("Multnomah")
+ Market.all[1].state.must_equal("Oregon")
+ Market.all[1].zipcode.must_equal("97202")
+ # last listed market
+ Market.all[500].id.must_equal(500)
+ Market.all[500].name.must_equal("Montefiore Medical Center Farmers Market_Thursday")
+ Market.all[500].address.must_equal("111 E. 210th Street")
+ Market.all[500].city.must_equal("Bronx")
+ Market.all[500].county.must_equal("Bronx")
+ Market.all[500].state.must_equal("New York")
+ Market.all[500].zipcode.must_equal("10467")
+ end
+
+ it "should be a collection of Market objects" do
+ Market.all.each do |market_id, market|
+ market_id.must_equal(market.id) # shows it's pairing up correctly
+ market.must_be_instance_of(Market) # shows the value objects are market instances
+ end
+ end
+ end #self.all
+ describe "#self.find(id)" do
+ it "should return an instance of a Market object of a certain id" do
+ random_market_id = rand(1..500)
+ Market.find(random_market_id).must_be_instance_of(Market)
+ Market.find(random_market_id).id.must_equal(random_market_id)
+ end
+ end #self.find(id)
+
+ describe "#vendors" do
+ it "should request vendors associated with itself (its instance of Market)" do
+ all_markets = Market.all
+ random_market_id = rand(1..500)
+ random_market = all_markets[random_market_id]
+ random_market.vendors.each do |vendor_id, vendor|
+ vendor.market_id.must_equal(random_market_id)
+ end
+ end
+ end #vendors
+
+ end #market
+
+
+end #module
diff --git a/specs/product_spec.rb b/specs/product_spec.rb
new file mode 100644
index 00000000..0656cc1d
--- /dev/null
+++ b/specs/product_spec.rb
@@ -0,0 +1,100 @@
+require_relative 'spec_helper'
+module FarMar
+
+ describe Product do
+
+ describe "#initialize" do
+ let(:product) { Product.new(:id, :name, :vendor_id) }
+
+
+ it "can create an instance of Product" do
+ product.must_be_instance_of(Product)
+ end
+ it "must respond to (have parameters of) of Product information" do
+ product.must_respond_to(:id)
+ product.must_respond_to(:name)
+ product.must_respond_to(:vendor_id)
+ end
+ end
+
+ describe "#self.all" do
+
+ it "should return a hash" do
+ Product.all.must_be_instance_of(Hash)
+ end
+ it "should return information about products" do
+ # first listed product
+ Product.all[1].id.must_equal(1)
+ Product.all[1].name.must_equal("Dry Beets")
+ Product.all[1].vendor_id.must_equal(1)
+ # last listed product
+ Product.all[8193].id.must_equal(8193)
+ Product.all[8193].name.must_equal("Cruel Beef")
+ Product.all[8193].vendor_id.must_equal(2690)
+ end
+
+ it "should be a collection of Product objects" do
+ Product.all.each do |product_id, product|
+ product_id.must_equal(product.id)
+ product.must_be_instance_of(Product)
+ end
+ end
+ end #self.all
+ describe "#self.find(id)" do
+ it "should return an instance of a Product object of a certain id" do
+ random_product_id = rand(1..8193)
+ Product.find(random_product_id).must_be_instance_of(Product)
+ Product.find(random_product_id).id.must_equal(random_product_id)
+ end
+ end #self.find(id)
+
+ #vendor: returns the FarMar::Vendor instance that is associated with this vendor using the FarMar::Product vendor_id field
+ describe "#vendor" do
+ let(:product_instance) { Product.new(298,"Curly Fruit",96) }
+ it "should return an instance of Vendor" do
+ product_instance.vendor.must_be_instance_of(Vendor)
+ end
+
+ it "should be associated with the vendor_id in its instance of Product" do
+ product_instance.vendor.id.must_equal(product_instance.vendor_id)
+ end
+ end
+ #sales: returns a collection of FarMar::Sale instances that are associated using the FarMar::Sale product_id field.
+ describe "#sales" do
+ let(:product_instance) { Product.new(298,"Curly Fruit",96) }
+ it "should return a hash" do
+ product_instance.sales.must_be_instance_of(Hash)
+ end
+
+ it "should return a collection of Sale instances associated by product_id" do
+ product_instance.sales.each do |sale_id, sale|
+ sale.must_be_instance_of(Sale)
+ product_instance.id.must_equal(sale.product_id)
+ end
+ end
+ end
+
+ #number_of_sales: returns the number of times this product has been sold.
+ describe "#number_of_sales" do
+ before(:each) do
+ @product_instance = Product.new(298,"Curly Fruit",96)
+ end
+
+ it "should return the number of times a product was sold" do
+ @product_instance.number_of_sales.must_equal(7)
+ end
+ end
+
+ describe "#self.by_vendor()" do
+ it "should return a collection of instances of Product" do
+ random_vendor_id = rand(1..2690)
+ Product.by_vendor(random_vendor_id).each do |pro_id, pro|
+ pro.must_be_instance_of(Product)
+ end
+ end
+ end
+
+
+
+ end
+end
diff --git a/specs/sale_spec.rb b/specs/sale_spec.rb
new file mode 100644
index 00000000..95432df6
--- /dev/null
+++ b/specs/sale_spec.rb
@@ -0,0 +1,96 @@
+require_relative 'spec_helper'
+module FarMar
+
+ describe Sale do
+ describe "#initialize" do
+ let(:sale) { Sale.new(:id, :amount, :purchase_time, :vendor_id, :product_id)}
+ it "can create an instance of Sale" do
+ sale.must_be_instance_of(Sale)
+ end
+ it "must respond to vendor parameters" do
+ sale.must_respond_to(:id)
+ sale.must_respond_to(:amount)
+ sale.must_respond_to(:purchase_time)
+ sale.must_respond_to(:vendor_id)
+ sale.must_respond_to(:product_id)
+ end
+ end
+
+ describe "#self.all" do
+
+ it "should return a hash" do
+ Sale.all.must_be_instance_of(Hash)
+ end
+ it "should return information about sales" do
+ # first sale in csv
+ Sale.all[1].id.must_equal(1) # The sale_id hash has a key: 1, it's not an array call
+ Sale.all[1].amount.must_equal(9290)
+ Sale.all[1].purchase_time.must_equal(DateTime.parse("2013-11-07 04:34:56 -0800"))
+ Sale.all[1].vendor_id.must_equal(1)
+ Sale.all[1].product_id.must_equal(1)
+ # last sale in csv
+ Sale.all[12001].id.must_equal(12001)
+ Sale.all[12001].amount.must_equal(8923)
+ Sale.all[12001].purchase_time.must_equal(DateTime.parse("2013-11-12 02:03:31 -0800"))
+ Sale.all[12001].vendor_id.must_equal(2690)
+ Sale.all[12001].product_id.must_equal(8192)
+ end
+
+ it "should be a collection of Sale objects" do
+ Sale.all.each do |sale_id, sale|
+ sale_id.must_equal(sale.id)
+ sale.must_be_instance_of(Sale)
+ end
+ end
+ it "should find a random Sale and decide it's an instance of Sale" do
+ random_sale_id = rand(1..12001)
+ Sale.all[random_sale_id].must_be_instance_of(Sale)
+ end
+ end
+
+ describe "#self.find(id)" do
+ it "should return an instance of a Sale of a certain id" do
+ random_sale_id = rand(1..12001)
+ Sale.find(random_sale_id).must_be_instance_of(Sale)
+ Sale.find(random_sale_id).id.must_equal(random_sale_id)
+ end
+ end
+
+ describe "#vendor" do
+ let(:sale_instance) { Sale.new(96,2289,DateTime.parse("2013-11-10 17:23:48 -0800"),19,57)}
+ it "should return an instance of Vendor" do
+ sale_instance.vendor.must_be_instance_of(Vendor)
+ end
+ it "should be associated with vendor_id" do
+ sale_instance.vendor.id.must_equal(sale_instance.vendor_id)
+ end
+ end
+
+ describe "#product" do
+ let(:sale_instance) { Sale.new(96,2289,DateTime.parse("2013-11-10 17:23:48 -0800"),19,57)}
+ it "should return an instance of Product" do
+ sale_instance.product.must_be_instance_of(Product)
+ end
+ it "should be associated by the sale using the product_id field" do
+ sale_instance.product.id.must_equal(sale_instance.product_id)
+ end
+ end
+
+ # using a known timestamp: "2013-11-11 03:37:15 -0800"
+ describe "#self.between(beginning_time, end_time)" do
+ before(:each) do
+ beginning_time = DateTime.parse("2013-11-11 03:36:15 -0800")
+ end_time = DateTime.parse("2013-11-11 03:38:15 -0800")
+ @sales = Sale.between(beginning_time, end_time)
+ end
+ it "should return a hash" do
+ @sales.must_be_instance_of(Hash)
+ end
+ it "should find sales objects within the test timeframe" do
+ @sales.length.must_be(:>,0)
+ end
+ end
+
+ end
+
+end
diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb
new file mode 100644
index 00000000..09d9efc0
--- /dev/null
+++ b/specs/spec_helper.rb
@@ -0,0 +1,10 @@
+require 'simplecov'
+SimpleCov.start
+require 'minitest'
+require 'minitest/spec'
+require "minitest/autorun"
+require "minitest/reporters"
+require 'minitest/pride'
+
+require_relative '../far_mar'
+Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
diff --git a/specs/vendor_spec.rb b/specs/vendor_spec.rb
new file mode 100644
index 00000000..6619dbb5
--- /dev/null
+++ b/specs/vendor_spec.rb
@@ -0,0 +1,100 @@
+require_relative 'spec_helper'
+module FarMar
+
+ describe Vendor do
+ describe "#initialize" do
+ let(:vendor) { Vendor.new(:id, :name, :number_of_employees, :market_id) }
+ it "can create an instance of Vendor" do
+ vendor.must_be_instance_of(Vendor)
+ end
+ # test below passed once there was attr_readers, instance variables not needed
+ it "must respond to (have parameters of) of vendor information" do
+ vendor.must_respond_to(:id)
+ vendor.must_respond_to(:name)
+ vendor.must_respond_to(:number_of_employees)
+ vendor.must_respond_to(:market_id)
+ end
+ end
+
+ describe "#self.all" do
+
+ it "should return a hash" do
+ Vendor.all.must_be_instance_of(Hash)
+ end
+ it "should return information about vendors" do
+ # first listed vendor
+ Vendor.all[1].id.must_equal(1)
+ Vendor.all[1].name.must_equal("Feil-Farrell")
+ Vendor.all[1].number_of_employees.must_equal(8)
+ Vendor.all[1].market_id.must_equal(1)
+ # last listed vendor
+ Vendor.all[2690].id.must_equal(2690)
+ Vendor.all[2690].name.must_equal("Mann-Lueilwitz")
+ Vendor.all[2690].number_of_employees.must_equal(4)
+ Vendor.all[2690].market_id.must_equal(500)
+ end
+ it "should be a collection of Vendor objects" do
+ Vendor.all.each do |vendor_id, vendor|
+ vendor_id.must_equal(vendor.id)
+ vendor.must_be_instance_of(Vendor)
+ end
+ end
+ end #self.all
+
+ describe "#self.find(id)" do
+ it "should return an instance of a Vendor object of a certain id" do
+ random_vendor_id = rand(1..2690)
+ Vendor.find(random_vendor_id).must_be_instance_of(Vendor)
+ Vendor.find(random_vendor_id).id.must_equal(random_vendor_id)
+ end
+ end #self.find(id)
+
+ describe "#market" do
+ before(:each) do
+ @vendor = Vendor.new(:id, :name, :number_of_employees, :market_id)
+ end
+ it "should reutrn the Market instance that it is associated to" do
+ @vendor.market.must_equal(@vendor.market_id)
+ end
+ end
+
+ describe "#products" do
+ it "should return a collection of Product instances associated to specific vendor" do
+ all_vendors = Vendor.all
+ random_vendor_id = rand(1..2690)
+ random_vendor = all_vendors[random_vendor_id]
+ random_vendor.products.each do |product_id, product|
+ product.vendor_id.must_equal(random_vendor_id)
+ end
+ end
+ end
+
+ describe "#sales" do
+ it "should return the sales associated to the instance of Vendor" do
+ all_vendors = Vendor.all
+ random_vendor_id = rand(1..2690)
+ random_vendor = all_vendors[random_vendor_id]
+ random_vendor.sales.each do |sale_id, sale|
+ sale.vendor_id.must_equal(random_vendor_id)
+ end
+ end
+ end
+
+ # Here is the specific vendor revenue for vendor 1: 38259 cents
+ describe "#revenue" do
+ it "returns the sum of all of the vendor's sales (in cents)" do
+ all_vendors = Vendor.all
+ all_vendors[1].revenue.must_equal(38259) # [1] does not indicate array loc, instead hash key: 1
+ end
+ end
+
+ describe "#self.by_market" do
+ it "should return instances of Vendor" do
+ random_market_id = rand(1..500)
+ Vendor.by_market(random_market_id).each do |vendor_id, vendor|
+ vendor.must_be_instance_of(Vendor)
+ end
+ end
+ end
+ end
+end