diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..4ebc8aea --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +coverage diff --git a/README.md b/README.md index 576e36ae..7762bef9 100644 --- a/README.md +++ b/README.md @@ -84,21 +84,21 @@ Each sale belongs to a vendor __AND__ a product. The `vendor_id` and `product_id ### Baseline #### Project Setup 1. You'll be working as an individual on this project. -1. Fork the Ada-C6 repo to your Github account. -1. Clone your fork to your projects directory, and `cd` into the cloned repo. -1. Create a _gemset_ for your project +1. Fork the Ada-C6 repo to your Github account. DONE +1. Clone your fork to your projects directory, and `cd` into the cloned repo. DONE +1. Create a _gemset_ for your project IGNORE 1. `$ echo 2.3.0 > .ruby-version` 1. `$ echo farmar > .ruby-gemset` 1. `$ cd .` -1. Install necessary gems via Terminal: +1. Install necessary gems via Terminal: DONE - `$ gem install minitest-reporters` - `$ gem install simplecov` #### Baseline Requirements -- Create a class for each of the data types listed above. Each class should be a part of the `FarMar` module. -- You should be able to create instances of these classes that know about their associated data file. -- Create your `far_mar.rb` file which will bring together all classes created in the previous step. -- 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. +- Create a class for each of the data types listed above. Each class should be a part of the `FarMar` module. DONE +- You should be able to create instances of these classes that know about their associated data file. DONE (specific CSV to be read in) +- Create your `far_mar.rb` file which will bring together all classes created in the previous step. DONE +- 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. DONE - **Once you have completed your baseline, you must submit a pull-request and get it approved by an instructor.** ## Primary Requirements @@ -154,4 +154,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..64751eb9 --- /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..5366c21c --- /dev/null +++ b/far_mar.rb @@ -0,0 +1,9 @@ +require 'csv' +require 'date' + +module FarMar; end + +require_relative 'lib/farmar_market' +require_relative 'lib/farmar_vendor' +require_relative 'lib/farmar_product' +require_relative 'lib/farmar_sale' diff --git a/lib/farmar_market.rb b/lib/farmar_market.rb new file mode 100644 index 00000000..e392717a --- /dev/null +++ b/lib/farmar_market.rb @@ -0,0 +1,111 @@ +module FarMar + class Market + attr_reader :id, :name, :state + + def initialize(id, name, address, city, county, state, zip) + @id = id.to_i + @name = name + @address = address + @city = city + @county = county + @state = state + @zip = zip + end + + def self.all + all_markets = [] + CSV.read('support/markets.csv').each do |line| + all_markets << FarMar::Market.new(line[0], line[1], line[2], line[3], line[4], line[5], line[6]) + end + return all_markets + end + + def self.find(id) + self.all.find do |market| + market.id == id + end + end + + + def self.find_by_name(name) + self.all.find do |market| + market.name.upcase == name.upcase + end + end + + # def self.find_all_by_state(state) + # state_markets = self.all.select do |market| + # market.state.upcase == state.upcase + # end + # return state_markets + # end + + def vendors + FarMar::Vendor.all.select do |vendor| + vendor.market_id == @id + end + end + + def self.search(search_term) + all_markets = self.all + all_vendors = FarMar::Vendor.all + + matching_market_names = all_markets.select do |market| + market.name.upcase.include?(search_term.upcase) + end + + # matching_vendor_name_markets = [] stalls in terminal + # all_vendors.each do |vendor| + # if vendor.name.upcase.include?(search_term.upcase) + # matching_vendor_name_markets << FarMar::Market.find(vendor.market_id) + # end + # end + matching_vendors = all_vendors.select do |vendor| + vendor.name.upcase.include?(search_term.upcase) + end + + matching_vendor_name_markets = matching_vendors.map do |vendor| + FarMar::Market.find(vendor.market_id) + end + + matching_markets = matching_market_names + matching_vendor_name_markets + + return matching_markets.uniq + end + + def products + market_products = [] + vendors.each do |vendor| + market_products += vendor.products + end + return market_products + end + + def preferred_vendor(date = nil) # use default/optional date? + if date == nil + preferred_vendor = vendors.max_by do |vendor| + vendor.revenue + end + else + preferred_vendor = vendors.max_by do |vendor| + vendor.revenue(date) + end + end + return preferred_vendor + end + + def worst_vendor(date = nil) + if date == nil + preferred_vendor = vendors.min_by do |vendor| + vendor.revenue + end + else + preferred_vendor = vendors.min_by do |vendor| + vendor.revenue(date) + end + end + return preferred_vendor + end + + end +end diff --git a/lib/farmar_product.rb b/lib/farmar_product.rb new file mode 100644 index 00000000..51332c7e --- /dev/null +++ b/lib/farmar_product.rb @@ -0,0 +1,60 @@ +module FarMar + class Product + attr_reader :id, :name, :vendor_id + + def initialize(id, name, vendor_id) + @id = id.to_i + @name = name + @vendor_id = vendor_id.to_i + end + + def self.all + all_products = [] + CSV.read('support/products.csv').each do |line| + all_products << FarMar::Product.new(line[0], line[1], line[2]) + end + return all_products + end + + def self.find(id) + self.all.find do |product| + product.id == id + end + end + + # def self.find_by_name(name) + # self.all.find do |product| + # product.name.upcase == name.upcase + # end + # end + + def vendor + FarMar::Vendor.find(@vendor_id) + end + + def sales + product_sales = FarMar::Sale.all.select do |sale| + sale.product_id == @id + end + return product_sales + end + + def number_of_sales + sales.length + end + + def self.by_vendor(vendor_id) + vendor_products = self.all.select do |product| + product.vendor_id == vendor_id + end + return vendor_products + end + + # def self.most_revenue(n) + # all_products = self.all.sort_by do |product| + # product. + # + # end + + end +end diff --git a/lib/farmar_sale.rb b/lib/farmar_sale.rb new file mode 100644 index 00000000..1a16eef6 --- /dev/null +++ b/lib/farmar_sale.rb @@ -0,0 +1,44 @@ +module FarMar + class Sale + + attr_reader :id, :amount, :vendor_id, :product_id, :purchase_time + + def initialize(id, amount, purchase_time, vendor_id, product_id) + @id = id.to_i + @amount = amount.to_i + @purchase_time = DateTime.parse(purchase_time.to_s) + @vendor_id = vendor_id.to_i + @product_id = product_id.to_i + end + + def self.all + all_sales = [] + CSV.read('support/sales.csv').each do |line| + all_sales << FarMar::Sale.new(line[0], line[1], line[2], line[3], line[4]) + end + return all_sales + end + + def self.find(id) + self.all.find do |sale| + sale.id == id + end + end + + def vendor + FarMar::Vendor.find(@vendor_id) + end + + def product + FarMar::Product.find(@product_id) + end + + def self.between(beginning_time, end_time) + sales_window = self.all.select do |sale| + sale.purchase_time > beginning_time && sale.purchase_time < end_time + end + return sales_window + end + + end +end diff --git a/lib/farmar_vendor.rb b/lib/farmar_vendor.rb new file mode 100644 index 00000000..bf54db9d --- /dev/null +++ b/lib/farmar_vendor.rb @@ -0,0 +1,92 @@ +module FarMar + class Vendor + attr_reader :id, :name, :market_id + + def initialize(id, name, employee_count, market_id) + @id = id.to_i + @name = name + @employee_count = employee_count.to_i + @market_id = market_id.to_i + end + + def self.all + all_vendors = [] + CSV.read('support/vendors.csv').each do |line| + all_vendors << FarMar::Vendor.new(line[0], line[1], line[2], line[3]) + end + return all_vendors + end + + def self.find(id) + all_vendors = self.all + all_vendors.each do |vendor| + if vendor.id == id + return vendor + end + end + end + + # def self.find_by_name(name) + # self.all.each do |vendor| + # vendor.name.upcase == name.upcase + # end + # end + + def market + FarMar::Market.find(@market_id) + end + + def products + FarMar::Product.all.select do |product| + product.vendor_id == @id + end + end + + def sales + FarMar::Sale.all.select do |sale| + sale.vendor_id == @id + end + end + + def revenue(date = nil) + vendor_sales = sales + if date != nil + beginning_time = DateTime.new(date.year, date.month, date.day, 0, 0, 0, '-8') + end_time = DateTime.new(date.year, date.month, date.day, 23, 59, 59, '-8') + + vendor_sales_by_date = vendor_sales.select do |sale| + sale.purchase_time > beginning_time && sale.purchase_time < end_time + end + + vendor_sales = vendor_sales_by_date + end + + revenue = 0 + vendor_sales.each do |sale| + revenue += sale.amount + end + + # revenue_total = revenue_array.reduce(:+) + + if revenue == nil + return 0 + else + return revenue + end + end + + # def self.most_revenue(n) + # vendors_by_revenue = self.all.sort_by do |vendor| + # vendor.revenue + # end + # return vendors_by_revenue[-n..-1] + # end + + def self.by_market(market_id) + self.all.select do |vendor| + vendor.market_id == market_id + end + end + + end +end diff --git a/specs/farmar_market_spec.rb b/specs/farmar_market_spec.rb new file mode 100644 index 00000000..bd049821 --- /dev/null +++ b/specs/farmar_market_spec.rb @@ -0,0 +1,160 @@ +require_relative 'spec_helper' + +describe FarMar::Market do + describe "#initialize" do + market = FarMar::Market.new(5, "Columbia City Farmers Market", "40 S Edmunds Rd", "Seattle", "King", "WA", "98118") + + it "should create an instance of FarMar::Market class" do + market.must_be_instance_of(FarMar::Market) + end + + it "should pass 7 arguments: ID - (Fixnum), Name - (String), Address - (String), City - (String), County - (String), State - (String), Zip - (String) and allow reading of ID" do + market.id.must_equal(5) + end + + end + + describe "self.all" do + all_markets = FarMar::Market.all + + it "should return an array" do + all_markets.must_be_kind_of(Array) + end + + it "should return an array of FarMar::Market instances" do + all_markets[8].must_be_instance_of(FarMar::Market) + end + + it "should return a collection of FarMar::Market instances created from the CSV file" do + all_markets[6].name.must_equal("Petaluma Evening Farmers' Market") + end + end + + describe "self.find(id)" do + market_12 = FarMar::Market.find(12) + + it "should return an instance of FarMar::Market" do + market_12.must_be_instance_of(FarMar::Market) + end + + it "should return the instance of FarMar::Market that matches the passed id" do + market_12.id.must_equal(12) + end + + it "should return the instance of FarMar::Market that matches the passed id, check for name" do + market_12.name.must_equal("Coxsackie Farmers' Market") + end + + end + + describe "#vendors" do + silverdale = FarMar::Market.find(2) + + it "should return a collection of FarMar::Vendor instances associated with the market" do + silverdale.vendors.must_be_kind_of(Array) + end + + it "should return an array of the vendors associated with silverdale market" do + vendors = silverdale.vendors + vendor_names = vendors.map do |vendor| + vendor.name + end + vendor_names.must_include("Quigley, Breitenberg and Schuster") + end + end + + describe "find_by_name(name)" do + it "should return the instance that matches the passed name" do + FarMar::Market.find_by_name("Coxsackie Farmers' Market").id.must_equal(FarMar::Market.find(12).id) + end + + end + + # describe "find_all_by_state(state)" do + # it "should return an array of instances that match the passed state" do + # markets_wa = FarMar::Market.find_all_by_state("Washington") + # + # markets_wa[rand(1..(markets_wa.length - 1))].state.upcase.must_equal("WASHINGTON") + # + # end + # end + + describe "#products" do + market_products = FarMar::Market.find(77).products + + it "should return an array of Product instances" do + market_products[rand(0..(market_products.length - 1))].must_be_instance_of(FarMar::Product) + end + + it "should return an array of Products associated to the market through the Vendor class" do + vendor_id = market_products[rand(0..(market_products.length - 1))].vendor_id + market_id = FarMar::Vendor.find(vendor_id).market_id + market_id.must_equal(77) + end + + end + + describe "self.search(search_term)" do + search_king = FarMar::Market.search("king") + + it "should return an array of Market instances" do + search_king[0].must_be_instance_of(FarMar::Market) + end + + it "should return an array of Market instances where market name matches search term" do + names = search_king.map do |market| + market.name.upcase + end + names.must_include("KING FARMERS MARKET") + end + + it "should return an array of Market instances where vendor name matches search term" do + matching_vendors = [] + search_king.each do |market| + matching_vendors += market.vendors + end + + vendor_names = matching_vendors.map do |vendor| + vendor.name + end + vendor_names.must_include("Kulas, King and Kohler") + end + + end + + describe "#preferred_vendor(date optional)" do + market_12 = FarMar::Market.find(12) + market_99 = FarMar::Market.find(99) + date = DateTime.new(2013, 11, 11, 0, 0, 0, '-8') + + it "should return a Vendor instance" do + market_12.preferred_vendor.must_be_instance_of(FarMar::Vendor) + end + + it "should return the vendor with the highest overall revenue" do + market_12.preferred_vendor.revenue.must_be(:>, FarMar::Vendor.find(53).revenue) + end + + it "should return the vendor with the highest revenue for that date if a date is passed" do + market_99.preferred_vendor(date).id.must_equal(516) + end + + it "should return the vendor with the highest revenue for that date if a date is passed" do + market_99.preferred_vendor(date).revenue.must_be(:>, market_99.vendors[0].revenue) + end + end + + describe "#worst_vendor(optional date)" do + market_99 = FarMar::Market.find(99) + date = DateTime.new(2013, 11, 11, 0, 0, 0, '-8') + + it "should return the vendor with the lowest revenue" do + market_99.worst_vendor.id.must_equal(517) + end + + it "should return the vendor with the lowest revenue on a given date" do # multiple worst vendors? + market_99.worst_vendor(date).revenue.must_equal(0) + end + + end +end diff --git a/specs/farmar_product_spec.rb b/specs/farmar_product_spec.rb new file mode 100644 index 00000000..4eac5286 --- /dev/null +++ b/specs/farmar_product_spec.rb @@ -0,0 +1,123 @@ +require_relative 'spec_helper' + +describe FarMar::Product do + describe "#initialize" do + product = FarMar::Product.new(2, "Jelly beans", 4) + + it "should create an instance of FarMar::Product class" do + product.must_be_instance_of(FarMar::Product) + end + + it "should pass 3 arguments: ID - (Fixnum), Name - (String), Vendor_id - (Fixnum) and allow reading of ID" do + product.id.must_equal(2) + end + + end + + describe "self.all" do + all_products = FarMar::Product.all + + it "should return an array" do + all_products.must_be_kind_of(Array) + end + + it "should return an array of FarMar::Product instances" do + all_products[8].must_be_instance_of(FarMar::Product) + end + + it "should return a collection of FarMar::Product instances created from the CSV file" do + all_products[6].name.must_equal("Quaint Beef") + end + end + + describe "self.find(id)" do + product_12 = FarMar::Product.find(12) + + it "should return an instance of FarMar::Product" do + product_12.must_be_instance_of(FarMar::Product) + end + + it "should return the instance of FarMar::Product that matches the passed id" do + product_12.id.must_equal(12) + end + + it "should return the instance of FarMar::Product that matches the passed id, check for name" do + product_12.name.must_equal("Gorgeous Fish") + end + end + + describe "#vendor" do + before(:each) do + @fish = FarMar::Product.find(127) + end + + it "should return an instance of FarMar::Vendor" do + @fish.vendor.must_be_instance_of(FarMar::Vendor) + end + + it "should return the instance of FarMar::Vendor that matches the Product instance's vendor_id" do + @fish.vendor.id.must_equal(@fish.vendor_id) + end + + end + + describe "#sales" do + before(:each) do + @greens = FarMar::Product.find(131) + end + + it "should return an array of FarMar::Sale instances" do + @greens.sales[1].must_be_instance_of(FarMar::Sale) + end + + it "should return FarMar::Sale instances that match the product_id" do + @greens.sales[1].product_id.must_equal(@greens.id) + end + + end + + describe "#number_of_sales" do + before(:each) do + @greens = FarMar::Product.find(131) + end + + it "should return the number of times this product has been sold" do + @greens.number_of_sales.must_equal(@greens.sales.length) + end + + end + + describe "self.by_vendor(vendor_id)" do + vendor_15_products = FarMar::Product.by_vendor(15) + + it "should return an array of Product instances" do + vendor_15_products[1].must_be_instance_of(FarMar::Product) + end + + it "should return the Product instances with vendor_id that matches the passed vendor_id" do + vendor_15_products[1].vendor_id.must_equal(15) + end + + end + + # describe "self.most_revenue(n)" do + # it "should return the top n product instances ranked by total revenue" do + # top_5 = FarMar::Product.most_revenue(5) + # (top_5.first > top_5.last).must_equal(true) + # end + # end + + # describe "self.find_by_name(name)" do + # it "should return the Product instance that matches the passed name" do + # FarMar::Product.find_by_name("gorgeous fish").id.must_equal(12) + # end + # end + + # describe "self.find_all_by_keyword(word)" do + # it "should return an array of Product instances that contain the keyword in the product name" do + # matches = FarMar::Product.find_all_by_keyword("fish") + # matches[rand(0..(matches.length - 1))].name.must_include("fish") + # end + # end + +end diff --git a/specs/farmar_sale_spec.rb b/specs/farmar_sale_spec.rb new file mode 100644 index 00000000..638efb74 --- /dev/null +++ b/specs/farmar_sale_spec.rb @@ -0,0 +1,100 @@ +require_relative 'spec_helper' + +describe FarMar::Sale do + + describe "#initialize" do + sale = FarMar::Sale.new(9, 500, Time.now, 4, 100) + + it "should create an instance of FarMar::Sale class" do + sale.must_be_instance_of(FarMar::Sale) + end + + it "should pass 5 arguments: ID - (Fixnum), Amount - (Fixnum), Purchase_time - (Datetime), Vendor_id - (Fixnum), Product_id - (Fixnum) and allow reading of ID" do + sale.id.must_equal(9) + end + + end + + describe "self.all" do + before (:each) do + @all_sales = FarMar::Sale.all + end + + it "should return an array" do + @all_sales.must_be_kind_of(Array) + end + + it "should return an array of FarMar::Sale instances" do + @all_sales[8].must_be_instance_of(FarMar::Sale) + end + + it "should return a collection of FarMar::Sale instances created from the CSV file" do + @all_sales[6].amount.must_equal(4095) + end + end + + describe "self.find(id)" do + before(:each) do + @sale_12 = FarMar::Sale.find(12) + end + + it "should return an instance of FarMar::Sale" do + @sale_12.must_be_instance_of(FarMar::Sale) + end + + it "should return the instance of FarMar::Sale that matches the passed id" do + @sale_12.id.must_equal(12) + end + + it "should return the instance of FarMar::Sale that matches the passed id, check for amount" do + @sale_12.amount.must_equal(5179) + end + + end + + describe "#vendor" do + before(:each) do + @sale = FarMar::Sale.find(38) + end + + it "should return a FarMar::Vendor instance" do + @sale.vendor.must_be_instance_of(FarMar::Vendor) + end + + it "should return the Vendor instance that matches the vendor_id of the Product instance" do + @sale.vendor.id.must_equal(@sale.vendor_id) + end + + end + + describe "#product" do + before(:each) do + @sale = FarMar::Sale.find(38) + end + + it "should return a FarMar::Product instance" do + @sale.product.must_be_instance_of(FarMar::Product) + end + + it "should return the Product instance associated with sale using Sale product_id" do + @sale.product.id.must_equal(@sale.product_id) + end + + end + + describe "self.between(beginning_time, end_time)" do + beginning_time = DateTime.new(2013, 11, 07, 20, 25, 00, '-8') + end_time = DateTime.new(2013, 11, 07, 20, 26, 00, '-8') + sales = FarMar::Sale.between(beginning_time, end_time) + it "should return an array of FarMar::Sale objects" do + sales[1].must_be_instance_of(FarMar::Sale) + end + + it "should return an array of Sale objects that were sold between the two times given" do + sales_ids = sales.map do |sale| + sale.id + end + sales_ids.must_include(37) + end + end +end diff --git a/specs/farmar_vendor_spec.rb b/specs/farmar_vendor_spec.rb new file mode 100644 index 00000000..2f44d674 --- /dev/null +++ b/specs/farmar_vendor_spec.rb @@ -0,0 +1,143 @@ +require_relative 'spec_helper' + +describe FarMar::Vendor do + describe "#initialize" do + vendor = FarMar::Vendor.new(8, "Kool Kumquats", 3, 7) + + it "should create an instance of FarMar::Vendor class" do + vendor.must_be_instance_of(FarMar::Vendor) + end + + it "should pass 4 arguments: ID - (Fixnum), Name - (String), No. of Employees - (Fixnum), Market_id - (Fixnum) and allow reading of ID" do + vendor.id.must_equal(8) + end + end + + describe "self.all" do + all_vendors = FarMar::Vendor.all + + it "should return an array" do + all_vendors.must_be_kind_of(Array) + end + + it "should return an array of FarMar::Vendor instances" do + all_vendors[8].must_be_instance_of(FarMar::Vendor) + end + + it "should return a collection of FarMar::Vendor instances created from the CSV file" do + all_vendors[6].name.must_equal("Bechtelar Inc") + end + end + + describe "self.find(id)" do + vendor_12 = FarMar::Vendor.find(12) + + it "should return an instance of FarMar::Vendor" do + vendor_12.must_be_instance_of(FarMar::Vendor) + end + + it "should return the instance of FarMar::Vendor that matches the passed id" do + vendor_12.id.must_equal(12) + end + + it "should return the instance of FarMar::Vendor that matches the passed id, check for name" do + vendor_12.name.must_equal("Windler Inc") + end + + end + + windler_vendor = FarMar::Vendor.find(12) + + describe "#market" do + it "should return a FarMar::Market instance" do + windler_vendor.market.must_be_instance_of(FarMar::Market) + end + + it "should return the FarMar::Market instance that is associated with this vendor using market_id" do + windler_vendor.market.name.must_equal("Dolgeville Farmer's Market") + end + end + + describe "#products" do + it "should return an array" do + windler_vendor.products.must_be_kind_of(Array) + end + + it "should return an array of FarMar::Product instances" do + windler_vendor.products[1].must_be_instance_of(FarMar::Product) + end + + it "should return a collection of Product instances associated with the vendor_id" do + windler_vendor.products[1].vendor_id.must_equal(12) + end + end + + describe "#sales" do + it "should return an array" do + windler_vendor.sales.must_be_kind_of(Array) + end + + it "should return an array of FarMar::Sale instances" do + windler_vendor.sales[1].must_be_instance_of(FarMar::Sale) + end + + it "should return an array of Sale instances that match the vendor_id" do + windler_vendor.sales[1].vendor_id.must_equal(12) + end + end + + describe "#revenue(date optional)" do + it "should return an integer" do + windler_vendor.revenue.must_be_kind_of(Fixnum) + end + + it "should return the sum of all the vendor's sales" do + windler_vendor.revenue.must_equal(10969) + end + + it "should return the total revenue for the passed date and vendor instance" do + welch_vendor = FarMar::Vendor.find(516) + date = DateTime.new(2013, 11, 11, 0, 0, 0, '-8') + welch_vendor.revenue(date).must_equal(17896) + end + + it "should return 0 if no sales were made" do + ersner_vendor = FarMar::Vendor.find(517) + date = DateTime.new(2013, 11, 11, 0, 0, 0, '-8') + ersner_vendor.revenue(date).must_equal(0) + end + + end + + describe "self.by_market(market_id)" do + vendor_14 = FarMar::Vendor.by_market(14) + + it "should return an array of vendors" do + vendor_14[1].must_be_instance_of(FarMar::Vendor) + end + + it "should return only vendors that match the passed market_id" do + vendor_14[1].market_id.must_equal(14) + end + + end + # + # describe "self.most_revenue(n)" do + # top_5 = FarMar::Vendor.most_revenue(5) + # + # it "should return an ordered collection of Vendor instances" do + # top_5.first.id.must_equal(500) + # end + # + # it "should be ranked by total revenue" do + # top_5.first.revenue.must_be(:>, top_5.last.revenue) + # end + # end + # + # describe "self.find_by_name(name)" do + # it "should return the Vendor instance that matches the passed name" do + # FarMar::Vendor.find_by_name("Windler Inc").id.must_equal(FarMar::Vendor.find(12).id) + # end + # end + +end diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb new file mode 100644 index 00000000..857f7fdf --- /dev/null +++ b/specs/spec_helper.rb @@ -0,0 +1,12 @@ +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