From 3fd06549d49d7bbd5b58b8f8345893021c34b8bb Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 6 Sep 2016 13:21:05 -0700 Subject: [PATCH 01/42] SETUP files --- .gitignore | 51 ++++++++++++++++++ .ruby-gemset | 1 + .ruby-version | 1 + FarMar.rb | 3 ++ Rakefile | 15 ++++++ far_mar.rb | 9 ++++ lib/Market.rb | 3 ++ lib/Product.rb | 3 ++ lib/Sale.rb | 4 ++ lib/Vendor.rb | 4 ++ project_plan.txt | 121 +++++++++++++++++++++++++++++++++++++++++++ specs/spec_helper.rb | 9 ++++ 12 files changed, 224 insertions(+) create mode 100644 .gitignore create mode 100644 .ruby-gemset create mode 100644 .ruby-version create mode 100644 FarMar.rb create mode 100644 Rakefile create mode 100644 far_mar.rb create mode 100644 lib/Market.rb create mode 100644 lib/Product.rb create mode 100644 lib/Sale.rb create mode 100644 lib/Vendor.rb create mode 100644 project_plan.txt create mode 100644 specs/spec_helper.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..251342cb --- /dev/null +++ b/.gitignore @@ -0,0 +1,51 @@ +*.gem +*.rbc +/.config +/coverage/ +/InstalledFiles +/pkg/ +/spec/reports/ +/spec/examples.txt +/test/tmp/ +/test/version_tmp/ +/tmp/ + +# Used by dotenv library to load environment variables. +# .env + +## Specific to RubyMotion: +.dat* +.repl_history +build/ +*.bridgesupport +build-iPhoneOS/ +build-iPhoneSimulator/ + +## Specific to RubyMotion (use of CocoaPods): +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# vendor/Pods/ + +## Documentation cache and generated files: +/.yardoc/ +/_yardoc/ +/doc/ +/rdoc/ + +## Environment normalization: +/.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 +.DS_Store \ No newline at end of file diff --git a/.ruby-gemset b/.ruby-gemset new file mode 100644 index 00000000..73f861e5 --- /dev/null +++ b/.ruby-gemset @@ -0,0 +1 @@ +farmar diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 00000000..276cbf9e --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.3.0 diff --git a/FarMar.rb b/FarMar.rb new file mode 100644 index 00000000..a65c8d04 --- /dev/null +++ b/FarMar.rb @@ -0,0 +1,3 @@ +module FarMar + +end \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 00000000..9e53df88 --- /dev/null +++ b/Rakefile @@ -0,0 +1,15 @@ +# copied from Scrabble project + +require 'rake/testtask' + +Rake::TestTask.new do |t| + t.libs = ["lib", "specs"] + t.warning = false + t.verbose = false + t.test_files = FileList['specs/*_spec.rb'] + puts "Running TestTask" +end + +task default: :test do + puts "Running my Rakefile" +end \ No newline at end of file diff --git a/far_mar.rb b/far_mar.rb new file mode 100644 index 00000000..b994ff57 --- /dev/null +++ b/far_mar.rb @@ -0,0 +1,9 @@ +# [] gems your project needs +require 'csv' + +# [x] our namespace module +module FarMar; end + +# all of our data classes that live in the module +require 'lib/farmar_market' +# [] ...require all needed classes \ No newline at end of file diff --git a/lib/Market.rb b/lib/Market.rb new file mode 100644 index 00000000..b3f8e2fa --- /dev/null +++ b/lib/Market.rb @@ -0,0 +1,3 @@ +class FarMar::Market + +end \ No newline at end of file diff --git a/lib/Product.rb b/lib/Product.rb new file mode 100644 index 00000000..6b7c91f5 --- /dev/null +++ b/lib/Product.rb @@ -0,0 +1,3 @@ +class FarMar::Product + +end \ No newline at end of file diff --git a/lib/Sale.rb b/lib/Sale.rb new file mode 100644 index 00000000..20dbf739 --- /dev/null +++ b/lib/Sale.rb @@ -0,0 +1,4 @@ +class FarMar::Sale + + +end \ No newline at end of file diff --git a/lib/Vendor.rb b/lib/Vendor.rb new file mode 100644 index 00000000..05af1c1f --- /dev/null +++ b/lib/Vendor.rb @@ -0,0 +1,4 @@ +class FarMar::Vendor + + +end \ No newline at end of file diff --git a/project_plan.txt b/project_plan.txt new file mode 100644 index 00000000..352a1be1 --- /dev/null +++ b/project_plan.txt @@ -0,0 +1,121 @@ +Project Structure + +Create a Ruby class to represent each kind of data in the support/ directory. In the Product Data section, there are detailed descriptions of each csv file contents and its relation to other objects in the system. Your implementation will have class methods to handle finding, sorting, and collecting the data into instances representing individual rows of data. Each of those instances will have instance methods to provide details about the object. + +Encapsulation + +[ ] file named /far_mar.rb. It will manage our data classes. It should look something like: + +# gems your project needs +require 'csv' + +# our namespace module +module FarMar; end + +# all of our data classes that live in the module +require 'lib/farmar_market' +# ...require all needed classes +Each class you build will live in the /lib directory, and belong to the FarMar module: + +# lib/farmar_market.rb +class FarMar::Market + # Your code goes here +end + +The module provides a namespace for the application. A namespace ensures the classes we create will not 'collide' or 'overlap' with a class that could exist elsewhere in a codebase (like in a gem). + +For example, Sale is a very generic class name that could very realistically exist in many codebases. Creating a module called FarMar allows us to specify which Sale we're talking about; FarMar::Sale is much more explicit and likely to be unique. + +Specs & Testing + +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 + +Each individual market has many vendors associated with it. The FarMar::Market data, in order in the CSV, consists of: + +ID - (Fixnum) a unique identifier for that market +Name - (String) the name of the market (not guaranteed unique) +Address - (String) street address of the market +City - (String) city in which the market is located +County - (String) county in which the market is located +State - (String) state in which the market is located +Zip - (String) zipcode in which the market is located +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: + +ID - (Fixnum) uniquely identifies the vendor +Name - (String) the name of the vendor (not guaranteed unique) +No. of Employees - (Fixnum) How many employees the vendor has at the market +Market_id - (Fixnum) a reference to which market the vendor attends +FarMar::Product + +Each product belongs to a vendor. The vendor_id field refers to the FarMar::Vendor ID field. The FarMar::Product data, in order in the CSV, consists of: + +ID - (Fixnum) uniquely identifies the product +Name - (String) the name of the product (not guaranteed unique) +Vendor_id - (Fixnum) a reference to which vendor sells this 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: + +ID - (Fixnum) uniquely identifies the sale +Amount - (Fixnum) the amount of the transaction, in cents (i.e., 150 would be $1.50) +Purchase_time - (Datetime) when the sale was completed +Vendor_id - (Fixnum) a reference to which vendor completed the sale +Product_id - (Fixnum) a reference to which product was sold +Requirements +############################## +Baseline +############################## +Project Setup +############################### +You'll be working as an individual on this project. - but it's ok to get help from collleagues +################################### + +[x] Fork the Ada-C6 repo to your Github account. +[x] Clone your fork to your projects directory, and cd into the cloned repo. +Create a gemset for your project +$ echo 2.3.0 > .ruby-version +$ echo farmar > .ruby-gemset +$ cd . +Install necessary gems via Terminal: +$ 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. +Once you have completed your baseline, you must submit a pull-request and get it approved by an instructor. +Primary Requirements + +For each of the data classes build the following methods: + +self.all: returns a collection of instances, representing all of the objects described in the CSV +self.find(id): returns an instance of the object where the value of the id field in the CSV matches the passed parameter. +Additional FarMar::Market Methods + +#vendors: returns a collection of FarMar::Vendor instances that are associated with the market by the market_id field. +Additional FarMar::Vendor Methods + +#market: returns the FarMar::Market instance that is associated with this vendor using the FarMar::Vendor market_id field +#products: returns a collection of FarMar::Product instances that are associated by the FarMar::Product vendor_id field. +#sales: returns a collection of FarMar::Sale instances that are associated by the vendor_id field. +#revenue: returns the the sum of all of the vendor's sales (in cents) +self.by_market(market_id): returns all of the vendors with the given market_id +Additional FarMar::Product Methods + +#vendor: returns the FarMar::Vendor instance that is associated with this vendor using the FarMar::Product vendor_id field +#sales: returns a collection of FarMar::Sale instances that are associated using the FarMar::Sale product_id field. +#number_of_sales: returns the number of times this product has been sold. +self.by_vendor(vendor_id): returns all of the products with the given vendor_id +Additional FarMar::Sale Methods + +#vendor: returns the FarMar::Vendor instance that is associated with this sale using the FarMar::Sale vendor_id field +#product: returns the FarMar::Product instance that is associated with this sale using the FarMar::Sale product_id field +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 \ No newline at end of file diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb new file mode 100644 index 00000000..36f95f1f --- /dev/null +++ b/specs/spec_helper.rb @@ -0,0 +1,9 @@ +require 'simplecov' +SimpleCov.start #class method + +require 'minitest' +require 'minitest/spec' +require 'minitest/autorun' +require 'minitest/reporters' + +Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new \ No newline at end of file From 4294c5a5a7b29bdb13a6f32badf208adf506a815 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 6 Sep 2016 14:35:05 -0700 Subject: [PATCH 02/42] UPDATE files to meet baseline requirements --- FarMar.rb | 4 +++- far_mar.rb | 9 ++++++++- lib/Market.rb | 19 ++++++++++++++++++- specs/Market_spec.rb | 14 ++++++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 specs/Market_spec.rb diff --git a/FarMar.rb b/FarMar.rb index a65c8d04..c5e244b5 100644 --- a/FarMar.rb +++ b/FarMar.rb @@ -1,3 +1,5 @@ module FarMar -end \ No newline at end of file +end + +# TODO add some require relatives here (classes) \ No newline at end of file diff --git a/far_mar.rb b/far_mar.rb index b994ff57..7966ca41 100644 --- a/far_mar.rb +++ b/far_mar.rb @@ -1,9 +1,16 @@ # [] gems your project needs require 'csv' +require 'simplecov' +require 'minitest-reporter' # [x] our namespace module module FarMar; end # all of our data classes that live in the module require 'lib/farmar_market' -# [] ...require all needed classes \ No newline at end of file + +# [] ...require all needed classes +require 'lib/Market.rb' +require 'lib/Product.rb' +require 'lib/Sale.rb' +require 'lib/Vendor.rb' \ No newline at end of file diff --git a/lib/Market.rb b/lib/Market.rb index b3f8e2fa..28a39b5a 100644 --- a/lib/Market.rb +++ b/lib/Market.rb @@ -1,3 +1,20 @@ +require_relative '../FarMar.rb' + class FarMar::Market -end \ No newline at end of file + attr_reader :ID, :name, :city, :county, :state, :zip + + def initialiaze + + @ID = ID + @name = name + @city = city + @county = county + @state = state + @zip = zip + + end + +end + +nada_whole_foods = FarMar::Market.new("Better Than Whole Foods") \ No newline at end of file diff --git a/specs/Market_spec.rb b/specs/Market_spec.rb new file mode 100644 index 00000000..15233c3d --- /dev/null +++ b/specs/Market_spec.rb @@ -0,0 +1,14 @@ +require_relative 'spec_helper.rb' +require_relative '../lib/Market.rb' + +# copied shamelessy and without remorse from Scrabble + +describe "Testing Market Class" do + + it "Tests that the instatiation of the Market class requires EXACTLY one arugment" do + # TODO this is a bogous test fix it + expect( proc {FarMar::Market.new("One").must_be_kind_of(FarMar::Market)}) + expect( proc {FarMar::Market.new}).must_raise(ArgumentError) + expect( proc {FarMar::Market.new("One", "Two")}).must_raise(ArgumentError) + end +end \ No newline at end of file From 579fdee82e771d3019a9aac5b24ec5a2242b5636 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Wed, 7 Sep 2016 20:13:35 -0700 Subject: [PATCH 03/42] DELETE extraneous file, UPDATE lib files --- FarMar.rb | 5 ----- lib/Market.rb | 4 ++-- specs/Product_spec.rb | 0 specs/Sale_spec.rb | 0 specs/Vendor_spec.rb | 0 5 files changed, 2 insertions(+), 7 deletions(-) delete mode 100644 FarMar.rb create mode 100644 specs/Product_spec.rb create mode 100644 specs/Sale_spec.rb create mode 100644 specs/Vendor_spec.rb diff --git a/FarMar.rb b/FarMar.rb deleted file mode 100644 index c5e244b5..00000000 --- a/FarMar.rb +++ /dev/null @@ -1,5 +0,0 @@ -module FarMar - -end - -# TODO add some require relatives here (classes) \ No newline at end of file diff --git a/lib/Market.rb b/lib/Market.rb index 28a39b5a..73017a39 100644 --- a/lib/Market.rb +++ b/lib/Market.rb @@ -2,11 +2,11 @@ class FarMar::Market - attr_reader :ID, :name, :city, :county, :state, :zip + attr_reader :MARKET_ID, :name, :city, :county, :state, :zip def initialiaze - @ID = ID + @MARKET_ID = market_id @name = name @city = city @county = county diff --git a/specs/Product_spec.rb b/specs/Product_spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/Sale_spec.rb b/specs/Sale_spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/Vendor_spec.rb b/specs/Vendor_spec.rb new file mode 100644 index 00000000..e69de29b From 9b3b709bfc4aa7212860d6701571c6152e4969ba Mon Sep 17 00:00:00 2001 From: jm-rives Date: Wed, 7 Sep 2016 20:28:13 -0700 Subject: [PATCH 04/42] MIN working code --- far_mar.rb | 12 ++++++------ lib/Market.rb | 18 +++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/far_mar.rb b/far_mar.rb index 7966ca41..c7730ee0 100644 --- a/far_mar.rb +++ b/far_mar.rb @@ -1,16 +1,16 @@ # [] gems your project needs require 'csv' require 'simplecov' -require 'minitest-reporter' +require 'minitest/reporters' # [x] our namespace module module FarMar; end # all of our data classes that live in the module -require 'lib/farmar_market' +#require 'lib/far_mar_market' # [] ...require all needed classes -require 'lib/Market.rb' -require 'lib/Product.rb' -require 'lib/Sale.rb' -require 'lib/Vendor.rb' \ No newline at end of file +require './lib/Market.rb' +require './lib/Product.rb' +require './lib/Sale.rb' +require './lib/Vendor.rb' \ No newline at end of file diff --git a/lib/Market.rb b/lib/Market.rb index 73017a39..73168917 100644 --- a/lib/Market.rb +++ b/lib/Market.rb @@ -1,20 +1,20 @@ -require_relative '../FarMar.rb' +# require_relative '../FarMar.rb' class FarMar::Market attr_reader :MARKET_ID, :name, :city, :county, :state, :zip - def initialiaze + def initialize(name) - @MARKET_ID = market_id + # @MARKET_ID = market_id @name = name - @city = city - @county = county - @state = state - @zip = zip - + # @city = city + # @county = county + # @state = state + # @zip = zip + end end -nada_whole_foods = FarMar::Market.new("Better Than Whole Foods") \ No newline at end of file +nada_whole_foods = FarMar::Market.new("All the whole fuds, half the check") From 0a395df4d95282acbc0e3a7fd75606d76cfb0216 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Wed, 7 Sep 2016 20:33:55 -0700 Subject: [PATCH 05/42] ADD start up logging --- far_mar.rb | 4 +++- lib/Market.rb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/far_mar.rb b/far_mar.rb index c7730ee0..727d85ae 100644 --- a/far_mar.rb +++ b/far_mar.rb @@ -10,7 +10,9 @@ module FarMar; end #require 'lib/far_mar_market' # [] ...require all needed classes +puts "Loading the project library." require './lib/Market.rb' require './lib/Product.rb' require './lib/Sale.rb' -require './lib/Vendor.rb' \ No newline at end of file +require './lib/Vendor.rb' +puts "Done Loading library!" \ No newline at end of file diff --git a/lib/Market.rb b/lib/Market.rb index 73168917..e36c9786 100644 --- a/lib/Market.rb +++ b/lib/Market.rb @@ -1,4 +1,4 @@ -# require_relative '../FarMar.rb' +puts "Loading Market.rb" class FarMar::Market @@ -18,3 +18,5 @@ def initialize(name) end nada_whole_foods = FarMar::Market.new("All the whole fuds, half the check") + +puts "Done loading Market.rb" \ No newline at end of file From 7718fd698f7009351e172115a0cb7e52da91fc1d Mon Sep 17 00:00:00 2001 From: jm-rives Date: Wed, 7 Sep 2016 21:35:13 -0700 Subject: [PATCH 06/42] Waypoint - set instance variables in constructor --- lib/Market.rb | 72 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 10 deletions(-) diff --git a/lib/Market.rb b/lib/Market.rb index e36c9786..599748b5 100644 --- a/lib/Market.rb +++ b/lib/Market.rb @@ -4,19 +4,71 @@ class FarMar::Market attr_reader :MARKET_ID, :name, :city, :county, :state, :zip - def initialize(name) - - # @MARKET_ID = market_id - @name = name - # @city = city - # @county = county - # @state = state - # @zip = zip + def initialize(market_row) # could take an array + + @MARKET_ID = market_row[0] + @name = market_row[1] + @city = market_row[3] + @county = market_row[4] + @state = market_row[5] + @zip = market_row[6] end + def self.all + # collection use array + + end + end +# werks +# CSV.foreach('./support/markets.csv') do |row| +# puts row.inspect +# end + +market_array = CSV.read('./support/markets.csv') # reads a line, and produces an array of an array of strings + +puts "We loaded #{market_array.length} arrays." + +puts "This is the first array" +print market_array[0] +puts +print market_array[0][1] +puts "\n\n" +# add additional pieces for constructor +really_dumb_market = FarMar::Market.new(market_array[0]) +puts really_dumb_market.inspect + + + + +FarMar::Market.all + + + + + + + + + + + + + + + + + + + + + + + + + + -nada_whole_foods = FarMar::Market.new("All the whole fuds, half the check") +puts "Done loading Market.rb" -puts "Done loading Market.rb" \ No newline at end of file From b67fd6305d098ac6245cabdda9672eb1020731e2 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Thu, 8 Sep 2016 16:42:59 -0700 Subject: [PATCH 07/42] STOPPED Here. Was working on how to construct instance variables with the CSV elements. --- far_mar.rb | 86 ++++++++++++++++++++++++++++++++++++++++++++++----- lib/Market.rb | 38 +++++++---------------- lib/Sale.rb | 10 +++++- lib/Vendor.rb | 16 ++++++++-- 4 files changed, 114 insertions(+), 36 deletions(-) diff --git a/far_mar.rb b/far_mar.rb index 727d85ae..d5702295 100644 --- a/far_mar.rb +++ b/far_mar.rb @@ -1,4 +1,4 @@ -# [] gems your project needs +# [x] gems your project needs require 'csv' require 'simplecov' require 'minitest/reporters' @@ -9,10 +9,82 @@ module FarMar; end # all of our data classes that live in the module #require 'lib/far_mar_market' -# [] ...require all needed classes +# [x] ...require all needed classes puts "Loading the project library." -require './lib/Market.rb' -require './lib/Product.rb' -require './lib/Sale.rb' -require './lib/Vendor.rb' -puts "Done Loading library!" \ No newline at end of file + +require './lib/Market' +require './lib/Product' +require './lib/Sale' +require './lib/Vendor' + +puts "Done Loading library!" + + +###### TESTING MARKET +market_array = CSV.read('./support/markets.csv') # reads a line, and produces an array of an array of strings + +puts "We loaded #{market_array.length} Market arrays." + +puts "This is the first Market array" +print market_array[0] +puts "\n\n" +print market_array[0][1] +puts "\n\n" + +# add additional pieces for constructor +nada_whole_fudz = FarMar::Market.new(market_array[0]) +puts "\n\n\n" + +#puts nada_whole_fudz.inspect +#FarMar::Market.all + + +############ TESTING VENDOR +puts "Loading Vendor.rb data...\n.\n.\n." # puts logging + +vendor_array = CSV.read('./support/vendors.csv') + +puts "We loaded #{vendor_array.length} Vendor arrays.\n\n" + +puts + +vendor_1 = FarMar::Vendor.new(vendor_row) + + +puts vendor_1 + +############### TESTING SALE + + + +############### TESTING + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/Market.rb b/lib/Market.rb index 599748b5..9fabeb85 100644 --- a/lib/Market.rb +++ b/lib/Market.rb @@ -1,12 +1,10 @@ -puts "Loading Market.rb" - class FarMar::Market - attr_reader :MARKET_ID, :name, :city, :county, :state, :zip + attr_reader :market_id, :name, :city, :county, :state, :zip def initialize(market_row) # could take an array - - @MARKET_ID = market_row[0] + #initialize is NOT a constructor see the iterwebs + @market_id = market_row[0] @name = market_row[1] @city = market_row[3] @county = market_row[4] @@ -16,33 +14,21 @@ def initialize(market_row) # could take an array end def self.all - # collection use array + # need a constructor loops + market_hash = {} + CSV.foreach('./support/vendors.csv') do |row| + # maybe I do need to build an hash (dict) + # instance variables would be the key/ import csv data would be the value + market_hash.push(market_row) + end + end end -# werks -# CSV.foreach('./support/markets.csv') do |row| -# puts row.inspect -# end - -market_array = CSV.read('./support/markets.csv') # reads a line, and produces an array of an array of strings - -puts "We loaded #{market_array.length} arrays." - -puts "This is the first array" -print market_array[0] -puts -print market_array[0][1] -puts "\n\n" -# add additional pieces for constructor -really_dumb_market = FarMar::Market.new(market_array[0]) -puts really_dumb_market.inspect - - +# testing content moved to far_mar.rb -FarMar::Market.all diff --git a/lib/Sale.rb b/lib/Sale.rb index 20dbf739..726743c3 100644 --- a/lib/Sale.rb +++ b/lib/Sale.rb @@ -1,4 +1,12 @@ -class FarMar::Sale +class FarMar::Sale # can only chain one to another + attr_reader :sale_id, :sale_amount, :purchase_date, :vendor_id, :product_id + + def initialize(sale_row) + @sale_id = sale_row[0] + @sale_amount = sale_row[1] # in cents + @purchase_date = sale_row[2] + # should not have to require vendor_id or product_id + end end \ No newline at end of file diff --git a/lib/Vendor.rb b/lib/Vendor.rb index 05af1c1f..16b2d0a2 100644 --- a/lib/Vendor.rb +++ b/lib/Vendor.rb @@ -1,4 +1,16 @@ -class FarMar::Vendor +class FarMar::Vendor < FarMar::Market # [x] is this the correct syntax? nope, fixed NOT FarMar::Vendor < Market it's FarMar::Vendor < FarMar::Market +attr_reader :vendor_id, :vendor_name, :employee_count, :market_id -end \ No newline at end of file + def initialize(vendor_row) + + @vendor_id = vendor_row[0] + @vendor_name = vendor_row[1] + @employee_count = vendor_row[2] + # should not have to enter market_id here + + end +end + + +# testing content moved to far_mar.rb \ No newline at end of file From c15dd890ecf42ffb77ce311c98a93294f0191b67 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Fri, 9 Sep 2016 10:14:18 -0700 Subject: [PATCH 08/42] ADD self.all method! Thanks Maya --- far_mar.rb | 32 +++++++++++++-------------- lib/Market.rb | 60 ++++++++++++++++++++++++++++++++++++--------------- lib/Sale.rb | 8 +++---- lib/Vendor.rb | 27 ++++++++++++++++++----- 4 files changed, 85 insertions(+), 42 deletions(-) diff --git a/far_mar.rb b/far_mar.rb index d5702295..5539390e 100644 --- a/far_mar.rb +++ b/far_mar.rb @@ -20,38 +20,38 @@ module FarMar; end puts "Done Loading library!" -###### TESTING MARKET -market_array = CSV.read('./support/markets.csv') # reads a line, and produces an array of an array of strings +###### TESTING MARKET ############ +puts "Started loading data!\n\n\n" +puts FarMar::Market.all.inspect # works as desired +puts "Done loading data!" +#for class method call syntax is Module::class.method(* put parameters here if needed) (don't include the self part) + +# if there is a parameter write the arugment here + +# FarMar::Market.all # this will match one of the the market id numbers + -puts "We loaded #{market_array.length} Market arrays." -puts "This is the first Market array" -print market_array[0] -puts "\n\n" -print market_array[0][1] -puts "\n\n" # add additional pieces for constructor -nada_whole_fudz = FarMar::Market.new(market_array[0]) -puts "\n\n\n" #puts nada_whole_fudz.inspect #FarMar::Market.all ############ TESTING VENDOR -puts "Loading Vendor.rb data...\n.\n.\n." # puts logging +# puts "Loading Vendor.rb data...\n.\n.\n." # puts logging -vendor_array = CSV.read('./support/vendors.csv') +# vendor_array = CSV.read('./support/vendors.csv') -puts "We loaded #{vendor_array.length} Vendor arrays.\n\n" +# puts "We loaded #{vendor_array.length} Vendor arrays.\n\n" -puts +# puts -vendor_1 = FarMar::Vendor.new(vendor_row) +# vendor_1 = FarMar::Vendor.new(vendor_row) -puts vendor_1 +# puts vendor_1 ############### TESTING SALE diff --git a/lib/Market.rb b/lib/Market.rb index 9fabeb85..d8e50eb0 100644 --- a/lib/Market.rb +++ b/lib/Market.rb @@ -1,35 +1,61 @@ class FarMar::Market - attr_reader :market_id, :name, :city, :county, :state, :zip + attr_reader :id, :name, :city, :county, :state, :zip - def initialize(market_row) # could take an array + def initialize(id, name, address, city, county, state, zip) # could take an array #initialize is NOT a constructor see the iterwebs - @market_id = market_row[0] - @name = market_row[1] - @city = market_row[3] - @county = market_row[4] - @state = market_row[5] - @zip = market_row[6] + @id = id + @name = name + @address = address + @city = city + @county = county + @state = state + @zip = zip end - def self.all - # need a constructor loops - market_hash = {} - CSV.foreach('./support/vendors.csv') do |row| + def self.all # works as desired [] repeat for each class + # [x] need a constructor loops + market_array = [] + + CSV.foreach('./support/markets.csv') do |line| # maybe I do need to build an hash (dict) # instance variables would be the key/ import csv data would be the value - market_hash.push(market_row) - end - - + id = line[0] + name = line[1] + address = line[2] + city = line[3] + county = line[4] + state = line[5] + zip = line[6] + + market_array << FarMar::Market.new(id, name, address, city, county, state, zip) + # market_array is an array of market objects e.g [#] + end + return market_array end + # returns and instance of an object where + # the value of the id field in the CSV + # matches the passed parameter + def self.find(id) + CSV.foreach('.support/markets.csv') do |line| + if id == line[0] + return line + else + continue + end + end + end end # testing content moved to far_mar.rb +# instance method must call on the INSTANCE +# class methods call directly on the class - +# initialize during the instantiation of the instance variables +# a market is a line +# a row is column diff --git a/lib/Sale.rb b/lib/Sale.rb index 726743c3..5c2dd011 100644 --- a/lib/Sale.rb +++ b/lib/Sale.rb @@ -1,11 +1,11 @@ class FarMar::Sale # can only chain one to another - attr_reader :sale_id, :sale_amount, :purchase_date, :vendor_id, :product_id + attr_reader :id, :sale_amount, :purchase_date, :id, def initialize(sale_row) - @sale_id = sale_row[0] - @sale_amount = sale_row[1] # in cents - @purchase_date = sale_row[2] + @id = id + @sale_amount = sale_amount # in cents + @purchase_date = purchase_date # should not have to require vendor_id or product_id end diff --git a/lib/Vendor.rb b/lib/Vendor.rb index 16b2d0a2..5254e7a0 100644 --- a/lib/Vendor.rb +++ b/lib/Vendor.rb @@ -1,14 +1,31 @@ class FarMar::Vendor < FarMar::Market # [x] is this the correct syntax? nope, fixed NOT FarMar::Vendor < Market it's FarMar::Vendor < FarMar::Market -attr_reader :vendor_id, :vendor_name, :employee_count, :market_id +attr_reader :id, :vendor_name, :employee_count, :market_id - def initialize(vendor_row) + def initialize(id, vendor_name, employee_count) - @vendor_id = vendor_row[0] - @vendor_name = vendor_row[1] - @employee_count = vendor_row[2] + @id = id + @vendor_name = vendor_name + @employee_count = employee_count # should not have to enter market_id here + end + + def self.all + # need a constructor loops + market_array = [] + + CSV.foreach('./support/vendors.csv') do |line| + # maybe I do need to build an hash (dict) + # instance variables would be the key/ import csv data would be the value + id = line[0] + vendor_name = line[1] + employee_count = line[2] + + new_market = FarMar::Market.new(id, vendor_name, employee_count) + end + + end end From 27af45a83ae7936e91d4e1f2497b6f1517ac8461 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Fri, 9 Sep 2016 10:47:51 -0700 Subject: [PATCH 09/42] ADD find(id) method. Thanks Maya --- far_mar.rb | 8 ++++---- lib/Market.rb | 21 +++++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/far_mar.rb b/far_mar.rb index 5539390e..6c1f7484 100644 --- a/far_mar.rb +++ b/far_mar.rb @@ -21,16 +21,16 @@ module FarMar; end ###### TESTING MARKET ############ -puts "Started loading data!\n\n\n" -puts FarMar::Market.all.inspect # works as desired -puts "Done loading data!" +# puts "Started loading data!\n\n\n" +# puts FarMar::Market.all.inspect # works as desired +# puts "Done loading data!" #for class method call syntax is Module::class.method(* put parameters here if needed) (don't include the self part) # if there is a parameter write the arugment here # FarMar::Market.all # this will match one of the the market id numbers - +puts FarMar::Market.find('4') # add additional pieces for constructor diff --git a/lib/Market.rb b/lib/Market.rb index d8e50eb0..2f051c94 100644 --- a/lib/Market.rb +++ b/lib/Market.rb @@ -35,17 +35,18 @@ def self.all # works as desired [] repeat for each class return market_array end - # returns and instance of an object where - # the value of the id field in the CSV - # matches the passed parameter - def self.find(id) - CSV.foreach('.support/markets.csv') do |line| - if id == line[0] - return line - else - continue + # returns an the market object associated with the Market id + + def self.find(id) # this parameter takes string + # find the market object with the id + found_market = nil # because there is no string + all.each do |market| + if market.id == id + found_market = market + break + end end - end + return found_market end end From 1b87fdbd6e22f8e5df09da6daf5fdc3d3f248a3f Mon Sep 17 00:00:00 2001 From: jm-rives Date: Fri, 9 Sep 2016 12:53:04 -0700 Subject: [PATCH 10/42] ADD Vendor .all method --- far_mar.rb | 4 +++- lib/Vendor.rb | 23 +++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/far_mar.rb b/far_mar.rb index 6c1f7484..f0556618 100644 --- a/far_mar.rb +++ b/far_mar.rb @@ -40,7 +40,7 @@ module FarMar; end ############ TESTING VENDOR -# puts "Loading Vendor.rb data...\n.\n.\n." # puts logging +puts "Loading Vendor.rb data...\n.\n.\n." # puts logging # vendor_array = CSV.read('./support/vendors.csv') @@ -52,6 +52,8 @@ module FarMar; end # puts vendor_1 +puts FarMar::Vendor.all +#puts FarMar::Market.find('4') ############### TESTING SALE diff --git a/lib/Vendor.rb b/lib/Vendor.rb index 5254e7a0..68534a6c 100644 --- a/lib/Vendor.rb +++ b/lib/Vendor.rb @@ -1,31 +1,30 @@ -class FarMar::Vendor < FarMar::Market # [x] is this the correct syntax? nope, fixed NOT FarMar::Vendor < Market it's FarMar::Vendor < FarMar::Market +class FarMar::Vendor -attr_reader :id, :vendor_name, :employee_count, :market_id + attr_reader :id, :vendor_name, :employee_count, :market_id - def initialize(id, vendor_name, employee_count) + def initialize(id, vendor_name, employee_count, market_id) @id = id @vendor_name = vendor_name @employee_count = employee_count + @market_id = market_id # should not have to enter market_id here end - def self.all - # need a constructor loops - market_array = [] - + def self.all + + vendor_array = [] + CSV.foreach('./support/vendors.csv') do |line| - # maybe I do need to build an hash (dict) - # instance variables would be the key/ import csv data would be the value id = line[0] vendor_name = line[1] employee_count = line[2] + market_id = line[3] - new_market = FarMar::Market.new(id, vendor_name, employee_count) + vendor_array << FarMar::Vendor.new(id, vendor_name, employee_count, market_id) end - - + return vendor_array end end From a9ae5ee300aed8b7ac498d202e7f9c9b8869acb6 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Fri, 9 Sep 2016 13:21:21 -0700 Subject: [PATCH 11/42] ADD Vendor self.find method, updated local initial test files --- far_mar.rb | 10 ++++++---- lib/Market.rb | 3 ++- lib/Vendor.rb | 13 +++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/far_mar.rb b/far_mar.rb index f0556618..ea9f9735 100644 --- a/far_mar.rb +++ b/far_mar.rb @@ -30,7 +30,8 @@ module FarMar; end # FarMar::Market.all # this will match one of the the market id numbers -puts FarMar::Market.find('4') +puts "This is the Market object that matches the id #{FarMar::Market.find('4')}" +puts "This is what the Market object that matches the id #{FarMar::Market.find('4').inspect}" # add additional pieces for constructor @@ -40,7 +41,7 @@ module FarMar; end ############ TESTING VENDOR -puts "Loading Vendor.rb data...\n.\n.\n." # puts logging +puts "Loading Vendor.rb data\n.\n.\n." # puts logging # vendor_array = CSV.read('./support/vendors.csv') @@ -52,8 +53,9 @@ module FarMar; end # puts vendor_1 -puts FarMar::Vendor.all -#puts FarMar::Market.find('4') +#puts FarMar::Vendor.all +puts "This is the Vendor object that matches the vendor id #{FarMar::Vendor.find('4')}" +puts "This is what the Vendor object that matches the vendor id #{FarMar::Vendor.find('4').inspect} class." ############### TESTING SALE diff --git a/lib/Market.rb b/lib/Market.rb index 2f051c94..7831e508 100644 --- a/lib/Market.rb +++ b/lib/Market.rb @@ -15,7 +15,7 @@ def initialize(id, name, address, city, county, state, zip) # could take an arra end def self.all # works as desired [] repeat for each class - # [x] need a constructor loops + market_array = [] CSV.foreach('./support/markets.csv') do |line| @@ -40,6 +40,7 @@ def self.all # works as desired [] repeat for each class def self.find(id) # this parameter takes string # find the market object with the id found_market = nil # because there is no string + all.each do |market| if market.id == id found_market = market diff --git a/lib/Vendor.rb b/lib/Vendor.rb index 68534a6c..6ea373cc 100644 --- a/lib/Vendor.rb +++ b/lib/Vendor.rb @@ -26,6 +26,19 @@ def self.all end return vendor_array end + + def self.find(id) + + found_vendor = nil + + all.each do |vendor| + if vendor.id == id + found_vendor = vendor + break + end + end + return found_vendor + end end From f779f55e1fb13ce6b8cf4757fcebd403156f91b7 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Fri, 9 Sep 2016 14:50:42 -0700 Subject: [PATCH 12/42] ADD Product self.all & self.find methods --- far_mar.rb | 26 ++++++++++++++++++++------ lib/Product.rb | 38 ++++++++++++++++++++++++++++++++++++++ lib/Sale.rb | 39 ++++++++++++++++++++++++++++++++++++--- lib/Vendor.rb | 2 +- 4 files changed, 95 insertions(+), 10 deletions(-) diff --git a/far_mar.rb b/far_mar.rb index ea9f9735..0461ebf9 100644 --- a/far_mar.rb +++ b/far_mar.rb @@ -19,8 +19,10 @@ module FarMar; end puts "Done Loading library!" - -###### TESTING MARKET ############ +################################### +###### TESTING MARKET ############ +################################### +puts "\n\n\nTime to test the Market class methods!\n\n" # puts "Started loading data!\n\n\n" # puts FarMar::Market.all.inspect # works as desired # puts "Done loading data!" @@ -39,9 +41,11 @@ module FarMar; end #puts nada_whole_fudz.inspect #FarMar::Market.all +############################################# +############ TESTING VENDOR ############### +############################################# -############ TESTING VENDOR -puts "Loading Vendor.rb data\n.\n.\n." # puts logging +puts "\n\n\nTime to test the Vendor class methods!\n\n" # puts logging # vendor_array = CSV.read('./support/vendors.csv') @@ -57,11 +61,21 @@ module FarMar; end puts "This is the Vendor object that matches the vendor id #{FarMar::Vendor.find('4')}" puts "This is what the Vendor object that matches the vendor id #{FarMar::Vendor.find('4').inspect} class." -############### TESTING SALE +################################################ +############### TESTING SALE ################## +################################################ +puts "\n\n\nTime to test the Sale class methods!\n\n" +puts "This is the Sale object that matches the sale id #{FarMar::Sale.find('4')}" +puts "This is what the Sale object that matches the sale id #{FarMar::Sale.find('4').inspect} class." +################################################ +############### TESTING PRODUCT ################ +################################################ -############### TESTING +puts "\n\n\nTime to test the Product class methods!\n\n" +puts "This is the Product object that matches the Product id #{FarMar::Product.find('4')}" +puts "This is what the Product object that matches the PRODUCTb id #{FarMar::Product.find('4').inspect} class." diff --git a/lib/Product.rb b/lib/Product.rb index 6b7c91f5..3740ab1f 100644 --- a/lib/Product.rb +++ b/lib/Product.rb @@ -1,3 +1,41 @@ class FarMar::Product + attr_reader :id, :product_name, :vendor_id + + def initialize(id, product_name, vendor_id) + + @id = id + @product_name = product_name + @vendor_id = vendor_id + + end + + def self.all + + product_array = [] + + CSV.foreach('./support/products.csv') do |line| + + id = line[0] + product_name = line[1] + vendor_id = line[2] + + product_array << FarMar::Product.new(id, product_name, vendor_id) + + end + return product_array + end + + def self.find(id) + + found_product = nil + + all.each do |product| + if product.id == id + found_product = product + break + end + end + return found_product + end end \ No newline at end of file diff --git a/lib/Sale.rb b/lib/Sale.rb index 5c2dd011..4a5495dd 100644 --- a/lib/Sale.rb +++ b/lib/Sale.rb @@ -1,12 +1,45 @@ class FarMar::Sale # can only chain one to another - attr_reader :id, :sale_amount, :purchase_date, :id, + attr_reader :id, :sale_amount, :purchase_date, :vendor_id, :product_id + + def initialize(id, sale_amount, purchase_date, vendor_id, product_id) - def initialize(sale_row) @id = id @sale_amount = sale_amount # in cents @purchase_date = purchase_date - # should not have to require vendor_id or product_id + #WRONG! should not have to require vendor_id or product_id + @vendor_id = vendor_id + @product_id = product_id + + end + + def self.all + + sale_array = [] + + CSV.foreach('./support/sales.csv') do |line| + id = line[0] + sale_amount = line[1] # in cents + purchase_date = line[2] + vendor_id = line[3] + product_id = line[4] + + sale_array << FarMar::Sale.new(id, sale_amount, purchase_date, vendor_id,product_id) + + end + return sale_array end + def self.find(id) + + found_sale = nil + + all.each do |sale| + if sale.id == id + found_sale = sale + break + end + end + return found_sale + end end \ No newline at end of file diff --git a/lib/Vendor.rb b/lib/Vendor.rb index 6ea373cc..ed2b98aa 100644 --- a/lib/Vendor.rb +++ b/lib/Vendor.rb @@ -8,7 +8,7 @@ def initialize(id, vendor_name, employee_count, market_id) @vendor_name = vendor_name @employee_count = employee_count @market_id = market_id - # should not have to enter market_id here + #WRONG! # should not have to enter market_id here end From b6c593e3ee658dde8d1f28873bdef2931ad5eeab Mon Sep 17 00:00:00 2001 From: jm-rives Date: Sun, 11 Sep 2016 14:35:58 -0700 Subject: [PATCH 13/42] ADD tests for the Market.all methods --- far_mar.rb | 78 ++++++++++++++++++++++---------------------- lib/Market.rb | 12 +++---- lib/Sale.rb | 3 ++ specs/Market_spec.rb | 44 ++++++++++++++++++++----- 4 files changed, 84 insertions(+), 53 deletions(-) diff --git a/far_mar.rb b/far_mar.rb index 0461ebf9..7ca09a78 100644 --- a/far_mar.rb +++ b/far_mar.rb @@ -19,63 +19,63 @@ module FarMar; end puts "Done Loading library!" -################################### -###### TESTING MARKET ############ -################################### -puts "\n\n\nTime to test the Market class methods!\n\n" -# puts "Started loading data!\n\n\n" -# puts FarMar::Market.all.inspect # works as desired -# puts "Done loading data!" -#for class method call syntax is Module::class.method(* put parameters here if needed) (don't include the self part) +# ################################### +# ###### TESTING MARKET ############ +# ################################### +# puts "\n\n\nTime to test the Market class methods!\n\n" +# # puts "Started loading data!\n\n\n" +# # puts FarMar::Market.all.inspect # works as desired +# # puts "Done loading data!" +# #for class method call syntax is Module::class.method(* put parameters here if needed) (don't include the self part) -# if there is a parameter write the arugment here +# # if there is a parameter write the arugment here -# FarMar::Market.all # this will match one of the the market id numbers +# # FarMar::Market.all # this will match one of the the market id numbers -puts "This is the Market object that matches the id #{FarMar::Market.find('4')}" -puts "This is what the Market object that matches the id #{FarMar::Market.find('4').inspect}" +# puts "This is the Market object that matches the id #{FarMar::Market.find('4')}" +# puts "This is what the Market object that matches the id #{FarMar::Market.find('4').inspect}" -# add additional pieces for constructor +# # add additional pieces for constructor -#puts nada_whole_fudz.inspect -#FarMar::Market.all +# #puts nada_whole_fudz.inspect +# #FarMar::Market.all -############################################# -############ TESTING VENDOR ############### -############################################# +# ############################################# +# ############ TESTING VENDOR ############### +# ############################################# -puts "\n\n\nTime to test the Vendor class methods!\n\n" # puts logging +# puts "\n\n\nTime to test the Vendor class methods!\n\n" # puts logging -# vendor_array = CSV.read('./support/vendors.csv') +# # vendor_array = CSV.read('./support/vendors.csv') -# puts "We loaded #{vendor_array.length} Vendor arrays.\n\n" +# # puts "We loaded #{vendor_array.length} Vendor arrays.\n\n" -# puts +# # puts -# vendor_1 = FarMar::Vendor.new(vendor_row) +# # vendor_1 = FarMar::Vendor.new(vendor_row) -# puts vendor_1 -#puts FarMar::Vendor.all -puts "This is the Vendor object that matches the vendor id #{FarMar::Vendor.find('4')}" -puts "This is what the Vendor object that matches the vendor id #{FarMar::Vendor.find('4').inspect} class." +# # puts vendor_1 +# #puts FarMar::Vendor.all +# puts "This is the Vendor object that matches the vendor id #{FarMar::Vendor.find('4')}" +# puts "This is what the Vendor object that matches the vendor id #{FarMar::Vendor.find('4').inspect} class." -################################################ -############### TESTING SALE ################## -################################################ +# ################################################ +# ############### TESTING SALE ################## +# ################################################ -puts "\n\n\nTime to test the Sale class methods!\n\n" -puts "This is the Sale object that matches the sale id #{FarMar::Sale.find('4')}" -puts "This is what the Sale object that matches the sale id #{FarMar::Sale.find('4').inspect} class." +# puts "\n\n\nTime to test the Sale class methods!\n\n" +# puts "This is the Sale object that matches the sale id #{FarMar::Sale.find('4')}" +# puts "This is what the Sale object that matches the sale id #{FarMar::Sale.find('4').inspect} class." -################################################ -############### TESTING PRODUCT ################ -################################################ +# ################################################ +# ############### TESTING PRODUCT ################ +# ################################################ -puts "\n\n\nTime to test the Product class methods!\n\n" -puts "This is the Product object that matches the Product id #{FarMar::Product.find('4')}" -puts "This is what the Product object that matches the PRODUCTb id #{FarMar::Product.find('4').inspect} class." +# puts "\n\n\nTime to test the Product class methods!\n\n" +# puts "This is the Product object that matches the Product id #{FarMar::Product.find('4')}" +# puts "This is what the Product object that matches the PRODUCTb id #{FarMar::Product.find('4').inspect} class." diff --git a/lib/Market.rb b/lib/Market.rb index 7831e508..f4209c31 100644 --- a/lib/Market.rb +++ b/lib/Market.rb @@ -1,8 +1,8 @@ class FarMar::Market - attr_reader :id, :name, :city, :county, :state, :zip + attr_reader :id, :name, :address, :city, :county, :state, :zip_code - def initialize(id, name, address, city, county, state, zip) # could take an array + def initialize(id, name, address, city, county, state, zip_code) # could take an array #initialize is NOT a constructor see the iterwebs @id = id @name = name @@ -10,10 +10,11 @@ def initialize(id, name, address, city, county, state, zip) # could take an arra @city = city @county = county @state = state - @zip = zip + @zip_code = zip_code end + # returns an array of market objects e.g [#] def self.all # works as desired [] repeat for each class market_array = [] @@ -27,9 +28,9 @@ def self.all # works as desired [] repeat for each class city = line[3] county = line[4] state = line[5] - zip = line[6] + zip_code = line[6] - market_array << FarMar::Market.new(id, name, address, city, county, state, zip) + market_array << FarMar::Market.new(id, name, address, city, county, state, zip_code) # market_array is an array of market objects e.g [#] end return market_array @@ -84,5 +85,4 @@ def self.find(id) # this parameter takes string -puts "Done loading Market.rb" diff --git a/lib/Sale.rb b/lib/Sale.rb index 4a5495dd..65729fe3 100644 --- a/lib/Sale.rb +++ b/lib/Sale.rb @@ -12,6 +12,9 @@ def initialize(id, sale_amount, purchase_date, vendor_id, product_id) @product_id = product_id end + # these can be re-used with a base class and + # a method to read in the files + # it's called inheritance def self.all diff --git a/specs/Market_spec.rb b/specs/Market_spec.rb index 15233c3d..25387b45 100644 --- a/specs/Market_spec.rb +++ b/specs/Market_spec.rb @@ -1,14 +1,42 @@ require_relative 'spec_helper.rb' -require_relative '../lib/Market.rb' +require_relative '../far_mar.rb' -# copied shamelessy and without remorse from Scrabble -describe "Testing Market Class" do +# copied shamelessy and without remorse from Scrabble +# +describe "Testing market" do - it "Tests that the instatiation of the Market class requires EXACTLY one arugment" do - # TODO this is a bogous test fix it - expect( proc {FarMar::Market.new("One").must_be_kind_of(FarMar::Market)}) - expect( proc {FarMar::Market.new}).must_raise(ArgumentError) - expect( proc {FarMar::Market.new("One", "Two")}).must_raise(ArgumentError) + it "creates a new instance of Market" do + + id = 4 + name = "Nada Whole Fudz" + address = "1215 Harry Hines Blvd" + city = "Portland" + county = "King" + state = "Washington" + zip_code = 98101 + + new_market1 = FarMar::Market.new(id, name, address, city, county, state, zip_code) + + new_market1.id.must_equal id + new_market1.name.must_equal name + new_market1.address.must_equal address + new_market1.city.must_equal city + new_market1.county.must_equal county + new_market1.state.must_equal state + new_market1.zip_code.must_equal 98101 + end + + it "Tests that we can call self.all " do + new_market_array = FarMar::Market.all + new_market_array.must_be_kind_of Array + new_market_array[0].must_be_kind_of FarMar::Market + + end + + + + + end \ No newline at end of file From 8c3ebe2333e6319da4c7acea5be84011237e34c0 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Sun, 11 Sep 2016 14:59:28 -0700 Subject: [PATCH 14/42] ADD tests for Market .find method --- lib/Market.rb | 2 +- specs/Market_spec.rb | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/Market.rb b/lib/Market.rb index f4209c31..5dd6ba19 100644 --- a/lib/Market.rb +++ b/lib/Market.rb @@ -36,7 +36,7 @@ def self.all # works as desired [] repeat for each class return market_array end - # returns an the market object associated with the Market id + # returns an the market object or nil associated with the Market id def self.find(id) # this parameter takes string # find the market object with the id diff --git a/specs/Market_spec.rb b/specs/Market_spec.rb index 25387b45..54e46c71 100644 --- a/specs/Market_spec.rb +++ b/specs/Market_spec.rb @@ -3,9 +3,9 @@ # copied shamelessy and without remorse from Scrabble -# + describe "Testing market" do - + # test for the self.all method it "creates a new instance of Market" do id = 4 @@ -35,6 +35,28 @@ end + it "Tests that the object number == the CSV array length" do + # returns an array of an array of strings + new_market_array = FarMar::Market.all + csv_array_array = CSV.read('./support/markets.csv') + csv_array_array.length.must_equal new_market_array.length + end + + # testing the self.find methods + + it "Tests that the id parameter returns a matching market id" do + new_market = FarMar::Market.find('474') + new_market.must_be_kind_of FarMar::Market + new_market.id.must_equal '474' + end + + it "Tests that the method returns nil if no match for market id found" do + new_market = FarMar::Market.find('501') + new_market.must_equal nil + + end + + From ea37c3e184994b6038d5f576748cc77e45921dca Mon Sep 17 00:00:00 2001 From: jm-rives Date: Sun, 11 Sep 2016 15:12:25 -0700 Subject: [PATCH 15/42] ADD Vendor tests --- specs/Vendor_spec.rb | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/specs/Vendor_spec.rb b/specs/Vendor_spec.rb index e69de29b..c4206963 100644 --- a/specs/Vendor_spec.rb +++ b/specs/Vendor_spec.rb @@ -0,0 +1,55 @@ +require_relative 'spec_helper.rb' +require_relative '../far_mar.rb' + +describe "Testing vendor" do + # test for the self.all method + it "creates a new instance of Vendor" do + # dummy data + id = 4 + vendor_name = "Nada && Sons" + employee_count = 10 + market_id = 5 + # instantiates new vendor for testing + new_vendor1 = FarMar::Vendor.new(id, vendor_name, employee_count, market_id) + + new_vendor1.id.must_equal id + new_vendor1.vendor_name.must_equal vendor_name + new_vendor1.employee_count.must_equal employee_count + new_vendor1.market_id.must_equal market_id + + end + + it "Tests that we can call self.all " do + new_vendor_array = FarMar::Vendor.all + new_vendor_array.must_be_kind_of Array + new_vendor_array[0].must_be_kind_of FarMar::Vendor + + end + + it "Tests that the object number == the CSV array length" do + # # returns an array of an array of strings + new_vendor_array = FarMar::Vendor.all + csv_array_array = CSV.read('./support/vendors.csv') + csv_array_array.length.must_equal new_vendor_array.length + end + + # testing the self.find methods + + it "Tests that the id parameter returns a matching market id" do + new_vendor = FarMar::Vendor.find('474') + new_vendor.must_be_kind_of FarMar::Vendor + new_vendor.id.must_equal '474' + end + + it "Tests that the method returns nil if no match for market id found" do + new_vendor = FarMar::Vendor.find('2691') + new_vendor.must_equal nil + + end + + + + + + +end \ No newline at end of file From 8def31db1aee74568669a66794d9aeb04b730f1c Mon Sep 17 00:00:00 2001 From: jm-rives Date: Sun, 11 Sep 2016 15:39:36 -0700 Subject: [PATCH 16/42] ADD Additional FarMar::Market methods --- lib/Market.rb | 14 +++++++++++++- lib/Vendor.rb | 2 +- specs/Market_spec.rb | 11 ++++++++++- specs/Product_spec.rb | 1 + specs/Sale_spec.rb | 1 + specs/Vendor_spec.rb | 1 + 6 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/Market.rb b/lib/Market.rb index 5dd6ba19..2a9a1384 100644 --- a/lib/Market.rb +++ b/lib/Market.rb @@ -36,7 +36,7 @@ def self.all # works as desired [] repeat for each class return market_array end - # returns an the market object or nil associated with the Market id + # returns the market object or nil associated with the Market id def self.find(id) # this parameter takes string # find the market object with the id @@ -50,6 +50,18 @@ def self.find(id) # this parameter takes string end return found_market end + + def self.vendors(market_id) #111 for the test case + + found_vendor = [] + + FarMar::Vendor.all.each do |vendor| + if vendor.market_id == market_id + found_vendor.push(vendor) + end + end + return found_vendor + end end # testing content moved to far_mar.rb diff --git a/lib/Vendor.rb b/lib/Vendor.rb index ed2b98aa..11c38b75 100644 --- a/lib/Vendor.rb +++ b/lib/Vendor.rb @@ -11,7 +11,7 @@ def initialize(id, vendor_name, employee_count, market_id) #WRONG! # should not have to enter market_id here end - + # returns an array of Vendors def self.all vendor_array = [] diff --git a/specs/Market_spec.rb b/specs/Market_spec.rb index 54e46c71..24d3a755 100644 --- a/specs/Market_spec.rb +++ b/specs/Market_spec.rb @@ -56,8 +56,17 @@ end + it "Tests that a market id will return its associated vendor(s)" do + new_vendor_search = FarMar::Market.vendors("111") + new_vendor_search.must_be_kind_of Array + new_vendor_search.length.must_equal 2 + + end - + it "Tests that an invalid market id will return an empty array" do + new_vendor_search = FarMar::Market.vendors("11111") + new_vendor_search.length.must_equal 0 + end diff --git a/specs/Product_spec.rb b/specs/Product_spec.rb index e69de29b..2f1610c7 100644 --- a/specs/Product_spec.rb +++ b/specs/Product_spec.rb @@ -0,0 +1 @@ +# defered .all & .find as low yield after completing for Market and Ve \ No newline at end of file diff --git a/specs/Sale_spec.rb b/specs/Sale_spec.rb index e69de29b..c990707c 100644 --- a/specs/Sale_spec.rb +++ b/specs/Sale_spec.rb @@ -0,0 +1 @@ +# defered .all & .find as low yield after completing for Market and Vendor \ No newline at end of file diff --git a/specs/Vendor_spec.rb b/specs/Vendor_spec.rb index c4206963..3a45ecbc 100644 --- a/specs/Vendor_spec.rb +++ b/specs/Vendor_spec.rb @@ -51,5 +51,6 @@ + end \ No newline at end of file From d9b3ff6d1037f084e1dbeadf63e3cbb15ac1605a Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 11:10:40 -0700 Subject: [PATCH 17/42] ADD bug fix, tests, comment --- lib/Market.rb | 6 ++++-- specs/Market_spec.rb | 12 ++++-------- specs/Product_spec.rb | 2 +- specs/spec_helper.rb | 1 + 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/Market.rb b/lib/Market.rb index 2a9a1384..829d2c31 100644 --- a/lib/Market.rb +++ b/lib/Market.rb @@ -51,12 +51,14 @@ def self.find(id) # this parameter takes string return found_market end - def self.vendors(market_id) #111 for the test case + # returns an array of vendors whose market_id matches this markets id + # instance method stuck to the current instantiation of market + def vendors #111 for the test case found_vendor = [] FarMar::Vendor.all.each do |vendor| - if vendor.market_id == market_id + if vendor.market_id == @id found_vendor.push(vendor) end end diff --git a/specs/Market_spec.rb b/specs/Market_spec.rb index 24d3a755..d6878acf 100644 --- a/specs/Market_spec.rb +++ b/specs/Market_spec.rb @@ -57,17 +57,13 @@ end it "Tests that a market id will return its associated vendor(s)" do - new_vendor_search = FarMar::Market.vendors("111") - new_vendor_search.must_be_kind_of Array - new_vendor_search.length.must_equal 2 + new_market = FarMar::Market.find('111') + found_vendors = new_market.vendors + found_vendors.must_be_kind_of Array + found_vendors.length.must_equal 2 end - it "Tests that an invalid market id will return an empty array" do - new_vendor_search = FarMar::Market.vendors("11111") - new_vendor_search.length.must_equal 0 - end - end \ No newline at end of file diff --git a/specs/Product_spec.rb b/specs/Product_spec.rb index 2f1610c7..c990707c 100644 --- a/specs/Product_spec.rb +++ b/specs/Product_spec.rb @@ -1 +1 @@ -# defered .all & .find as low yield after completing for Market and Ve \ No newline at end of file +# defered .all & .find as low yield after completing for Market and Vendor \ No newline at end of file diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index 36f95f1f..d743c6e2 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -5,5 +5,6 @@ require 'minitest/spec' require 'minitest/autorun' require 'minitest/reporters' +require 'minitest/pride' Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new \ No newline at end of file From da39cde442786dcf5a3e97f0d0bcdc995fc22ad1 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 11:18:01 -0700 Subject: [PATCH 18/42] ADD method --- far_mar.rb | 56 ---------------------------------------------- specs/Sale_spec.rb | 13 ++++++++++- 2 files changed, 12 insertions(+), 57 deletions(-) diff --git a/far_mar.rb b/far_mar.rb index 7ca09a78..6e5635e2 100644 --- a/far_mar.rb +++ b/far_mar.rb @@ -19,63 +19,7 @@ module FarMar; end puts "Done Loading library!" -# ################################### -# ###### TESTING MARKET ############ -# ################################### -# puts "\n\n\nTime to test the Market class methods!\n\n" -# # puts "Started loading data!\n\n\n" -# # puts FarMar::Market.all.inspect # works as desired -# # puts "Done loading data!" -# #for class method call syntax is Module::class.method(* put parameters here if needed) (don't include the self part) -# # if there is a parameter write the arugment here - -# # FarMar::Market.all # this will match one of the the market id numbers - -# puts "This is the Market object that matches the id #{FarMar::Market.find('4')}" -# puts "This is what the Market object that matches the id #{FarMar::Market.find('4').inspect}" - - -# # add additional pieces for constructor - -# #puts nada_whole_fudz.inspect -# #FarMar::Market.all - -# ############################################# -# ############ TESTING VENDOR ############### -# ############################################# - -# puts "\n\n\nTime to test the Vendor class methods!\n\n" # puts logging - -# # vendor_array = CSV.read('./support/vendors.csv') - -# # puts "We loaded #{vendor_array.length} Vendor arrays.\n\n" - -# # puts - -# # vendor_1 = FarMar::Vendor.new(vendor_row) - - -# # puts vendor_1 -# #puts FarMar::Vendor.all -# puts "This is the Vendor object that matches the vendor id #{FarMar::Vendor.find('4')}" -# puts "This is what the Vendor object that matches the vendor id #{FarMar::Vendor.find('4').inspect} class." - -# ################################################ -# ############### TESTING SALE ################## -# ################################################ - -# puts "\n\n\nTime to test the Sale class methods!\n\n" -# puts "This is the Sale object that matches the sale id #{FarMar::Sale.find('4')}" -# puts "This is what the Sale object that matches the sale id #{FarMar::Sale.find('4').inspect} class." - -# ################################################ -# ############### TESTING PRODUCT ################ -# ################################################ - -# puts "\n\n\nTime to test the Product class methods!\n\n" -# puts "This is the Product object that matches the Product id #{FarMar::Product.find('4')}" -# puts "This is what the Product object that matches the PRODUCTb id #{FarMar::Product.find('4').inspect} class." diff --git a/specs/Sale_spec.rb b/specs/Sale_spec.rb index c990707c..3ed73944 100644 --- a/specs/Sale_spec.rb +++ b/specs/Sale_spec.rb @@ -1 +1,12 @@ -# defered .all & .find as low yield after completing for Market and Vendor \ No newline at end of file +require_relative 'spec_helper.rb' +require_relative '../far_mar.rb' + +describe "Testing sale" do | + + + + + + | + +end \ No newline at end of file From 5039d88e84af1d666a02fd9efea714c2fd03f0af Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 11:29:47 -0700 Subject: [PATCH 19/42] ADD test check new instance of sale created --- specs/Sale_spec.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/specs/Sale_spec.rb b/specs/Sale_spec.rb index 3ed73944..861a1a29 100644 --- a/specs/Sale_spec.rb +++ b/specs/Sale_spec.rb @@ -1,12 +1,23 @@ require_relative 'spec_helper.rb' require_relative '../far_mar.rb' -describe "Testing sale" do | +describe "Testing sale" do + it "creates a new instance of Sale" do + id = 5 + sale_amount = 4440 + purchase_date = "2013-11-10 05:19:05 -0800" + vendor_id = 1 + product_id = 1 + # instantiates new sale for testing + quotidian_sale = FarMar::Sale.new(id, sale_amount, purchase_date, vendor_id, product_id) + quotidian_sale.id.must_equal id + quotidian_sale.sale_amount.must_equal sale_amount + quotidian_sale.purchase_date.must_equal purchase_date + quotidian_sale.vendor_id.must_equal vendor_id + quotidian_sale.product_id.must_equal product_id + end - - | - end \ No newline at end of file From ef8f3163fd46aa8608c04604c09c1dcfe384433f Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 11:38:26 -0700 Subject: [PATCH 20/42] Add test that sale is kind of array --- specs/Sale_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/specs/Sale_spec.rb b/specs/Sale_spec.rb index 861a1a29..757690bc 100644 --- a/specs/Sale_spec.rb +++ b/specs/Sale_spec.rb @@ -20,4 +20,10 @@ end + it "Tests that we can call self.all" do + quotidian_sale = FarMar::Sale.all + quotidian_sale.must_be_kind_of Array + + end + end \ No newline at end of file From 850049905b0107ac95a14e93cc8c182147040838 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 11:49:41 -0700 Subject: [PATCH 21/42] ADD test to check that one object is created for each line of csv --- specs/Sale_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/specs/Sale_spec.rb b/specs/Sale_spec.rb index 757690bc..c7437414 100644 --- a/specs/Sale_spec.rb +++ b/specs/Sale_spec.rb @@ -23,7 +23,13 @@ it "Tests that we can call self.all" do quotidian_sale = FarMar::Sale.all quotidian_sale.must_be_kind_of Array + quotidian_sale[0].must_be_kind_of FarMar::Sale + end + it "Tests that the object number == the CSV array length" do + quotidian_sale_array = FarMar::Sale.all + csv_sale_array = CSV.read('./support/sales.csv') + csv_sale_array.length.must_equal quotidian_sale_array.length end end \ No newline at end of file From d570c7afe44c77943f06bec84c087eeb70ad7796 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 11:59:21 -0700 Subject: [PATCH 22/42] ADD final test for Sale.rb --- specs/Sale_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/specs/Sale_spec.rb b/specs/Sale_spec.rb index c7437414..28e8f181 100644 --- a/specs/Sale_spec.rb +++ b/specs/Sale_spec.rb @@ -32,4 +32,17 @@ csv_sale_array.length.must_equal quotidian_sale_array.length end + # testing the self.find methods + + it "Tests that the id parameter returns a matching sale id" do + quotidian_sale = FarMar::Sale.find('32') + quotidian_sale.must_be_kind_of FarMar::Sale + quotidian_sale.id.must_equal '32' + end + + it "Tests that the method returns nil if no match for the sale id is found" do + quotidian_sale = FarMar::Sale.find('13000') + quotidian_sale.must_equal nil + + end end \ No newline at end of file From d16ba205525fe253d94d40d35ee0983c7591effb Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 12:21:02 -0700 Subject: [PATCH 23/42] ADD test for product self.all method --- specs/Product_spec.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/specs/Product_spec.rb b/specs/Product_spec.rb index c990707c..cad1c76b 100644 --- a/specs/Product_spec.rb +++ b/specs/Product_spec.rb @@ -1 +1,22 @@ -# defered .all & .find as low yield after completing for Market and Vendor \ No newline at end of file +require_relative 'spec_helper.rb' +require_relative '../far_mar.rb' + +describe "Testing product" do + # tests for the self.all method + it "creates a new instance of Vendor" do + id = 6 + product_name = "Smooth Mushrooms" + vendor_id = 4 + + quotidian_product = FarMar::Product.new(id, product_name, vendor_id) + quotidian_product.id.must_equal id + quotidian_product.product_name.must_equal product_name + end + + it "Tests that we can call self.all" do + quotidian_product_array = FarMar::Product.all + quotidian_product_array.must_be_kind_of Array + quotidian_product_array[0].must_be_kind_of FarMar::Product + end + +end \ No newline at end of file From 874a34cbb8ea7ab4a522463bf929cc13391ec6f8 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 12:33:42 -0700 Subject: [PATCH 24/42] ADD tests that the self.all method returns all expected objects --- specs/Product_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/specs/Product_spec.rb b/specs/Product_spec.rb index cad1c76b..03b5b0d4 100644 --- a/specs/Product_spec.rb +++ b/specs/Product_spec.rb @@ -19,4 +19,10 @@ quotidian_product_array[0].must_be_kind_of FarMar::Product end + it "Test that the object number == the CSV array length" do + quotidian_product_array = FarMar::Product.all + csv_array_array = CSV.read('./support/products.csv') + csv_array_array.length.must_equal quotidian_product_array.length + end + end \ No newline at end of file From 169ceb19c066cf891ffba7120fc75b60721efc6d Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 12:57:05 -0700 Subject: [PATCH 25/42] ADD Additional vendor method testing --- lib/Market.rb | 9 +++++---- specs/Product_spec.rb | 12 ++++++++++++ specs/Vendor_spec.rb | 10 ++++------ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/Market.rb b/lib/Market.rb index 829d2c31..4cfe4a9c 100644 --- a/lib/Market.rb +++ b/lib/Market.rb @@ -52,17 +52,18 @@ def self.find(id) # this parameter takes string end # returns an array of vendors whose market_id matches this markets id - # instance method stuck to the current instantiation of market + # instance method running inside an instance of market + # because it is running *inside* of market it can refer to @id def vendors #111 for the test case - found_vendor = [] + found_vendors = [] FarMar::Vendor.all.each do |vendor| if vendor.market_id == @id - found_vendor.push(vendor) + found_vendors.push(vendor) end end - return found_vendor + return found_vendors end end diff --git a/specs/Product_spec.rb b/specs/Product_spec.rb index 03b5b0d4..62c44fd4 100644 --- a/specs/Product_spec.rb +++ b/specs/Product_spec.rb @@ -24,5 +24,17 @@ csv_array_array = CSV.read('./support/products.csv') csv_array_array.length.must_equal quotidian_product_array.length end + # testing the self.find methods + + it "Tests that the id parameter returns a matching product id" do + quotidian_product = FarMar::Product.find('30') + quotidian_product.must_be_kind_of FarMar::Product + quotidian_product.id.must_equal '30' + end + + it "Tests that the method returns nil if no match is found" do + quotidian_product = FarMar::Product.find('8195') + quotidian_product.must_equal nil + end end \ No newline at end of file diff --git a/specs/Vendor_spec.rb b/specs/Vendor_spec.rb index 3a45ecbc..61d561d7 100644 --- a/specs/Vendor_spec.rb +++ b/specs/Vendor_spec.rb @@ -44,13 +44,11 @@ it "Tests that the method returns nil if no match for market id found" do new_vendor = FarMar::Vendor.find('2691') new_vendor.must_equal nil - end + # testing the additiona FarMar::Vendor methods + it "Tests that the instance method named market returns the FarMar::Market instance associated with the vendor using FarMar::Vendor.market_id field" do + new_vendor = FarMar::Vendor.find('474') + end - - - - - end \ No newline at end of file From 32fb7fc02e665ed0edabca74043c21b61875be5c Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 13:03:58 -0700 Subject: [PATCH 26/42] ADD tests that market method returns associated market --- specs/Vendor_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/specs/Vendor_spec.rb b/specs/Vendor_spec.rb index 61d561d7..01fec265 100644 --- a/specs/Vendor_spec.rb +++ b/specs/Vendor_spec.rb @@ -49,6 +49,9 @@ # testing the additiona FarMar::Vendor methods it "Tests that the instance method named market returns the FarMar::Market instance associated with the vendor using FarMar::Vendor.market_id field" do new_vendor = FarMar::Vendor.find('474') + new_vendor.market_id.must_equal '89' + + end end \ No newline at end of file From 01b3705884f3cb5ca54e63ec70c508854c1594c2 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 13:16:23 -0700 Subject: [PATCH 27/42] ADD Vendor method market --- lib/Vendor.rb | 5 +++++ specs/Market_spec.rb | 4 ++++ specs/Vendor_spec.rb | 5 ++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/Vendor.rb b/lib/Vendor.rb index 11c38b75..e0f004f7 100644 --- a/lib/Vendor.rb +++ b/lib/Vendor.rb @@ -39,7 +39,12 @@ def self.find(id) end return found_vendor end + + def market + + end end + # testing content moved to far_mar.rb \ No newline at end of file diff --git a/specs/Market_spec.rb b/specs/Market_spec.rb index d6878acf..a8ac7bac 100644 --- a/specs/Market_spec.rb +++ b/specs/Market_spec.rb @@ -61,6 +61,10 @@ found_vendors = new_market.vendors found_vendors.must_be_kind_of Array found_vendors.length.must_equal 2 + + found_vendors.each do |vendor| + vendor.market_id.must_equal "111" + end end diff --git a/specs/Vendor_spec.rb b/specs/Vendor_spec.rb index 01fec265..372363b4 100644 --- a/specs/Vendor_spec.rb +++ b/specs/Vendor_spec.rb @@ -47,11 +47,10 @@ end # testing the additiona FarMar::Vendor methods - it "Tests that the instance method named market returns the FarMar::Market instance associated with the vendor using FarMar::Vendor.market_id field" do + it "Tests that the instance method named market returns the FarMar::Market instance associated with the vendor using FarMar::Vendor.market_id field" do new_vendor = FarMar::Vendor.find('474') new_vendor.market_id.must_equal '89' - - + new_vendor.market end end \ No newline at end of file From 69c5cc30f0291411c6f986433fed79a3dadc0aec Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 13:27:18 -0700 Subject: [PATCH 28/42] ADD get_market testing and method to Vendor class --- lib/Vendor.rb | 6 ++++-- specs/Vendor_spec.rb | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Vendor.rb b/lib/Vendor.rb index e0f004f7..789b7e13 100644 --- a/lib/Vendor.rb +++ b/lib/Vendor.rb @@ -40,8 +40,10 @@ def self.find(id) return found_vendor end - def market - + #this method returns an instance of market that matches this vendors market_id + def get_market + found_market = FarMar::Market.find(@market_id) + return found_market end end diff --git a/specs/Vendor_spec.rb b/specs/Vendor_spec.rb index 372363b4..03a7d34e 100644 --- a/specs/Vendor_spec.rb +++ b/specs/Vendor_spec.rb @@ -49,8 +49,8 @@ # testing the additiona FarMar::Vendor methods it "Tests that the instance method named market returns the FarMar::Market instance associated with the vendor using FarMar::Vendor.market_id field" do new_vendor = FarMar::Vendor.find('474') - new_vendor.market_id.must_equal '89' - new_vendor.market + found_market = new_vendor.get_market + found_market.id.must_equal '89' end end \ No newline at end of file From 6b4fed474a60809962984899c6c088be652fefcf Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 13:48:19 -0700 Subject: [PATCH 29/42] ADD testing for get_product instance method --- lib/Market.rb | 2 +- lib/Vendor.rb | 13 +++++++++++++ specs/Market_spec.rb | 2 +- specs/Vendor_spec.rb | 22 ++++++++++++++++++++-- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/Market.rb b/lib/Market.rb index 4cfe4a9c..eaf800af 100644 --- a/lib/Market.rb +++ b/lib/Market.rb @@ -54,7 +54,7 @@ def self.find(id) # this parameter takes string # returns an array of vendors whose market_id matches this markets id # instance method running inside an instance of market # because it is running *inside* of market it can refer to @id - def vendors #111 for the test case + def get_vendors #111 for the test case found_vendors = [] diff --git a/lib/Vendor.rb b/lib/Vendor.rb index 789b7e13..a32da09b 100644 --- a/lib/Vendor.rb +++ b/lib/Vendor.rb @@ -45,6 +45,19 @@ def get_market found_market = FarMar::Market.find(@market_id) return found_market end + + def get_products + + found_products = [] + + FarMar::Product.all.each do |product| + if product.vendor_id == @id + found_products.push(product) + end + end + return found_products + end + end diff --git a/specs/Market_spec.rb b/specs/Market_spec.rb index a8ac7bac..bc838b88 100644 --- a/specs/Market_spec.rb +++ b/specs/Market_spec.rb @@ -58,7 +58,7 @@ it "Tests that a market id will return its associated vendor(s)" do new_market = FarMar::Market.find('111') - found_vendors = new_market.vendors + found_vendors = new_market.get_vendors found_vendors.must_be_kind_of Array found_vendors.length.must_equal 2 diff --git a/specs/Vendor_spec.rb b/specs/Vendor_spec.rb index 03a7d34e..8a9084a2 100644 --- a/specs/Vendor_spec.rb +++ b/specs/Vendor_spec.rb @@ -47,10 +47,28 @@ end # testing the additiona FarMar::Vendor methods - it "Tests that the instance method named market returns the FarMar::Market instance associated with the vendor using FarMar::Vendor.market_id field" do + it "Tests that the instance method named get_market returns the FarMar::Market instance associated with the vendor using FarMar::Vendor.market_id field" do new_vendor = FarMar::Vendor.find('474') found_market = new_vendor.get_market found_market.id.must_equal '89' end -end \ No newline at end of file + it "Tests that the instance method named get_products returns a list of FarMar::Product instnaces associated by product id" do + new_vendor = FarMar::Vendor.find('474') + found_products = new_vendor.get_products + found_products.length.must_equal 5 + #5 + end +end + + + + + + + + + + + + From fd67c524510c9c1c7a648d1ac4ec42394f44e8c3 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 13:55:00 -0700 Subject: [PATCH 30/42] ADD additional get_products test --- specs/Vendor_spec.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/specs/Vendor_spec.rb b/specs/Vendor_spec.rb index 8a9084a2..a9660934 100644 --- a/specs/Vendor_spec.rb +++ b/specs/Vendor_spec.rb @@ -46,19 +46,24 @@ new_vendor.must_equal nil end - # testing the additiona FarMar::Vendor methods + # testing the additional FarMar::Vendor methods it "Tests that the instance method named get_market returns the FarMar::Market instance associated with the vendor using FarMar::Vendor.market_id field" do new_vendor = FarMar::Vendor.find('474') found_market = new_vendor.get_market found_market.id.must_equal '89' end - it "Tests that the instance method named get_products returns a list of FarMar::Product instnaces associated by product id" do + it "Tests that the instance method named get_products returns a list of FarMar::Product instnaces associated by vendor id" do new_vendor = FarMar::Vendor.find('474') found_products = new_vendor.get_products + found_products.must_be_kind_of Array found_products.length.must_equal 5 - #5 + + found_products.each do |product| + product.vendor_id.must_equal "474" + end end + end From d3e4f37491f994bb81d058a5cfc700192c956570 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 14:08:14 -0700 Subject: [PATCH 31/42] ADD vendor get_sales method & test --- lib/Vendor.rb | 11 +++++++++++ specs/Vendor_spec.rb | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/Vendor.rb b/lib/Vendor.rb index a32da09b..6175d927 100644 --- a/lib/Vendor.rb +++ b/lib/Vendor.rb @@ -58,6 +58,17 @@ def get_products return found_products end + def get_sales + + found_sales = [] + FarMar::Sale.all.each do |sale| + if sale.vendor_id == @id + found_sales.push(sale) + end + end + return found_sales + end + end diff --git a/specs/Vendor_spec.rb b/specs/Vendor_spec.rb index a9660934..45b1c360 100644 --- a/specs/Vendor_spec.rb +++ b/specs/Vendor_spec.rb @@ -64,6 +64,14 @@ end end + it "Tests that the instance method named get_sales returns a list of FarMar::Sale instances associated by vendor_id field" do + new_vendor = FarMar::Vendor.find('474') + found_sales = new_vendor.get_sales + found_sales.length.must_equal 2 + + + end + end From 74fbd3f2aa0e41d7361edaf1bcb8dba2bc6b5fe4 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 14:34:31 -0700 Subject: [PATCH 32/42] ADD get_revunue testing and method --- lib/Vendor.rb | 9 +++++++++ specs/Vendor_spec.rb | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/Vendor.rb b/lib/Vendor.rb index 6175d927..06aef8a7 100644 --- a/lib/Vendor.rb +++ b/lib/Vendor.rb @@ -69,6 +69,15 @@ def get_sales return found_sales end + def get_revenue + found_sales = get_sales + sum_revenue = 0 + found_sales.each do |sale| + sum_revenue += sale.sale_amount.to_f + end + return sum_revenue + end + end diff --git a/specs/Vendor_spec.rb b/specs/Vendor_spec.rb index 45b1c360..2629880e 100644 --- a/specs/Vendor_spec.rb +++ b/specs/Vendor_spec.rb @@ -69,7 +69,15 @@ found_sales = new_vendor.get_sales found_sales.length.must_equal 2 + found_sales.each do |sale| + sale.vendor_id.must_equal '474' + end + end + it "Tests that the instance method get_revenue returns the sum of sales for the instance of vendor in cents." do + new_vendor = FarMar::Vendor.find('474') + revenue_earned = new_vendor.get_revenue + revenue_earned.must_equal 11176 end end From cea82337858cdcb92261580d0711ab829c1fd678 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 15:05:13 -0700 Subject: [PATCH 33/42] ADD self.by_market tests and method --- lib/Vendor.rb | 10 ++++++++++ specs/Vendor_spec.rb | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Vendor.rb b/lib/Vendor.rb index 06aef8a7..b05f1b5a 100644 --- a/lib/Vendor.rb +++ b/lib/Vendor.rb @@ -78,6 +78,16 @@ def get_revenue return sum_revenue end + def self.by_market(market_id) + found_vendors = [] + + all.each do |vendor| + if vendor.market_id == market_id + found_vendors.push(vendor) + end + end + return found_vendors + end end diff --git a/specs/Vendor_spec.rb b/specs/Vendor_spec.rb index 2629880e..02cf0a11 100644 --- a/specs/Vendor_spec.rb +++ b/specs/Vendor_spec.rb @@ -53,7 +53,7 @@ found_market.id.must_equal '89' end - it "Tests that the instance method named get_products returns a list of FarMar::Product instnaces associated by vendor id" do + it "Tests that the instance method named get_products returns a list of FarMar::Product instances associated by vendor id" do new_vendor = FarMar::Vendor.find('474') found_products = new_vendor.get_products found_products.must_be_kind_of Array @@ -80,6 +80,11 @@ revenue_earned.must_equal 11176 end + it "Tests that self.by_market returns all vendors associated with a market_id" do + found_vendors = FarMar::Vendor.by_market('2') + found_vendors.length.must_equal 3 + + end end From f6e3e2d32ecd43df8311cda678aecd9469e466e1 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 15:19:40 -0700 Subject: [PATCH 34/42] ADD get_vendor method --- specs/Product_spec.rb | 4 ++++ specs/Vendor_spec.rb | 3 +++ 2 files changed, 7 insertions(+) diff --git a/specs/Product_spec.rb b/specs/Product_spec.rb index 62c44fd4..d0733a9f 100644 --- a/specs/Product_spec.rb +++ b/specs/Product_spec.rb @@ -37,4 +37,8 @@ quotidian_product.must_equal nil end + it "Tests that get_vendor returns an instance of FarMar::Vendor using the FarMar::Product vendor_id field" do + + end + end \ No newline at end of file diff --git a/specs/Vendor_spec.rb b/specs/Vendor_spec.rb index 02cf0a11..061fbe04 100644 --- a/specs/Vendor_spec.rb +++ b/specs/Vendor_spec.rb @@ -84,6 +84,9 @@ found_vendors = FarMar::Vendor.by_market('2') found_vendors.length.must_equal 3 + found_vendors.each do |vendor| + vendor.market_id.must_equal '2' + end end end From 0f73a72d26411f3fb3b306fb85f327d5533beb6d Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 15:32:56 -0700 Subject: [PATCH 35/42] ADD get_vendor method and tests --- lib/Product.rb | 6 ++++++ lib/Vendor.rb | 1 - specs/Product_spec.rb | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Product.rb b/lib/Product.rb index 3740ab1f..efca72c2 100644 --- a/lib/Product.rb +++ b/lib/Product.rb @@ -38,4 +38,10 @@ def self.find(id) end return found_product end + + def get_vendor + #vendor: returns the FarMar::Vendor instance that is associated with this vendor using the FarMar::Product vendor_id field + found_vendor = FarMar::Vendor.find(@vendor_id) + return found_vendor + end end \ No newline at end of file diff --git a/lib/Vendor.rb b/lib/Vendor.rb index b05f1b5a..164c46a0 100644 --- a/lib/Vendor.rb +++ b/lib/Vendor.rb @@ -92,4 +92,3 @@ def self.by_market(market_id) -# testing content moved to far_mar.rb \ No newline at end of file diff --git a/specs/Product_spec.rb b/specs/Product_spec.rb index d0733a9f..d87fc76e 100644 --- a/specs/Product_spec.rb +++ b/specs/Product_spec.rb @@ -38,6 +38,10 @@ end it "Tests that get_vendor returns an instance of FarMar::Vendor using the FarMar::Product vendor_id field" do + new_product = FarMar::Product.find('30') + found_vendor = new_product.get_vendor + #vendor 11, depressed beets + found_vendor.id.must_equal '11' end From 0d0e1f6e1ff1a7e74d0c86c1c6e442c4736fc0c3 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 15:43:09 -0700 Subject: [PATCH 36/42] ADD product get_sales tests and method --- lib/Product.rb | 21 ++++++++++++++++++++- specs/Product_spec.rb | 27 ++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/lib/Product.rb b/lib/Product.rb index efca72c2..bd42ea85 100644 --- a/lib/Product.rb +++ b/lib/Product.rb @@ -44,4 +44,23 @@ def get_vendor found_vendor = FarMar::Vendor.find(@vendor_id) return found_vendor end -end \ No newline at end of file + + def get_sales + + end + +end + + + + + + + + + + + + + + diff --git a/specs/Product_spec.rb b/specs/Product_spec.rb index d87fc76e..f910b0cd 100644 --- a/specs/Product_spec.rb +++ b/specs/Product_spec.rb @@ -42,7 +42,32 @@ found_vendor = new_product.get_vendor #vendor 11, depressed beets found_vendor.id.must_equal '11' + end + + #sales: returns a collection of FarMar::Sale instances that are associated using the FarMar::Sale product_id field. + + # 64,8362,2013-11-07 05:30:08 -0800,11,30 + it "returns an array of FarMar::Sale instance that use the FarMar::Sale product_id field" do + new_product = FarMar::Product.find('30') + found_sales = new_product.get_sales end -end \ No newline at end of file + +end + + + + + + + + + + + + + + + + From c7cbda2279ae05f49138432e45f7a29101b06d85 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 15:55:29 -0700 Subject: [PATCH 37/42] ADD sales_count test --- lib/Product.rb | 9 ++++++++- specs/Product_spec.rb | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/Product.rb b/lib/Product.rb index bd42ea85..8326f18a 100644 --- a/lib/Product.rb +++ b/lib/Product.rb @@ -40,13 +40,20 @@ def self.find(id) end def get_vendor - #vendor: returns the FarMar::Vendor instance that is associated with this vendor using the FarMar::Product vendor_id field found_vendor = FarMar::Vendor.find(@vendor_id) return found_vendor end def get_sales + found_sales = [] + FarMar::Sale.all.each do |sale| + if sale.product_id == @id + found_sales.push(sale) + end + end + return found_sales + end end diff --git a/specs/Product_spec.rb b/specs/Product_spec.rb index f910b0cd..c1677b66 100644 --- a/specs/Product_spec.rb +++ b/specs/Product_spec.rb @@ -47,12 +47,16 @@ #sales: returns a collection of FarMar::Sale instances that are associated using the FarMar::Sale product_id field. # 64,8362,2013-11-07 05:30:08 -0800,11,30 - it "returns an array of FarMar::Sale instance that use the FarMar::Sale product_id field" do + it "Tests that it returns an array of FarMar::Sale instance that use the FarMar::Sale product_id field" do new_product = FarMar::Product.find('30') found_sales = new_product.get_sales - + found_sales.length.must_equal 1 + found_sales.first.product_id.must_equal '30' end + it "Tests that sale_count returns the count of sales for the instance of a product" do + + end end From 2fd2778ca24576481069a0060612f72d025fcc04 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 16:07:41 -0700 Subject: [PATCH 38/42] ADD sale_count method and tests --- lib/Product.rb | 3 +++ specs/Product_spec.rb | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/lib/Product.rb b/lib/Product.rb index 8326f18a..ae73d530 100644 --- a/lib/Product.rb +++ b/lib/Product.rb @@ -53,7 +53,10 @@ def get_sales end end return found_sales + end + def sale_count + return get_sales.length end end diff --git a/specs/Product_spec.rb b/specs/Product_spec.rb index c1677b66..fca25813 100644 --- a/specs/Product_spec.rb +++ b/specs/Product_spec.rb @@ -55,6 +55,10 @@ end it "Tests that sale_count returns the count of sales for the instance of a product" do + new_product = FarMar::Product.find('30') + sale_count_of_product = new_product.sale_count + sale_count_of_product.must_equal 1 + end From 5c368c912185405fceed23323910d859c85fb85f Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 17:00:43 -0700 Subject: [PATCH 39/42] ADD .by_vendor tests and method --- lib/Product.rb | 12 ++++++++++++ specs/Product_spec.rb | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/lib/Product.rb b/lib/Product.rb index ae73d530..54db0950 100644 --- a/lib/Product.rb +++ b/lib/Product.rb @@ -59,6 +59,18 @@ def sale_count return get_sales.length end + def self.by_vendor(vendor_id) + found_products = [] + + all.each do |product| + if product.vendor_id == vendor_id + found_products.push(product) + end + end + return found_products + end + + end diff --git a/specs/Product_spec.rb b/specs/Product_spec.rb index fca25813..b3c362cc 100644 --- a/specs/Product_spec.rb +++ b/specs/Product_spec.rb @@ -58,7 +58,11 @@ new_product = FarMar::Product.find('30') sale_count_of_product = new_product.sale_count sale_count_of_product.must_equal 1 + end + it "Test that it self.by_vendor(vendor_id): returns all of the products with the given vendor_id" do + found_products = FarMar::Product.by_vendor('474') + found_products.length.must_equal 5 end From 6302d813fb27021a17fb29191c03344a4ac28658 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 17:05:19 -0700 Subject: [PATCH 40/42] Add get_vendor Sale method test --- specs/Sale_spec.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/specs/Sale_spec.rb b/specs/Sale_spec.rb index 28e8f181..a78eb242 100644 --- a/specs/Sale_spec.rb +++ b/specs/Sale_spec.rb @@ -43,6 +43,26 @@ it "Tests that the method returns nil if no match for the sale id is found" do quotidian_sale = FarMar::Sale.find('13000') quotidian_sale.must_equal nil + end + + it "Tests that the get_vendor method returns the FarMar::Vendor instance that is associated with this sale using the FarMar::Sale vendor_id field" do end -end \ No newline at end of file + + + +end + + + + + + + + + + + + + + From 690b918e8f4633d176cc8240ad34136939fb18ce Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 17:12:46 -0700 Subject: [PATCH 41/42] ADD get_vendor passing tests and method --- lib/Sale.rb | 19 ++++++++++++++++++- specs/Sale_spec.rb | 5 ++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/Sale.rb b/lib/Sale.rb index 65729fe3..75aa8d3e 100644 --- a/lib/Sale.rb +++ b/lib/Sale.rb @@ -45,4 +45,21 @@ def self.find(id) end return found_sale end -end \ No newline at end of file + + def get_vendor + found_vendor = FarMar::Vendor.find(@vendor_id) + return found_vendor + end + +end + + + + + + + + + + + diff --git a/specs/Sale_spec.rb b/specs/Sale_spec.rb index a78eb242..b82bef7b 100644 --- a/specs/Sale_spec.rb +++ b/specs/Sale_spec.rb @@ -46,7 +46,10 @@ end it "Tests that the get_vendor method returns the FarMar::Vendor instance that is associated with this sale using the FarMar::Sale vendor_id field" do - + new_sale = FarMar::Sale.find('32') + found_vendor = new_sale.get_vendor + #vendor_id 7 product_id 14 + found_vendor.id.must_equal '7' end From b500ab544841c9df3421794af4afe2cdb77684d6 Mon Sep 17 00:00:00 2001 From: jm-rives Date: Tue, 20 Sep 2016 19:17:56 -0700 Subject: [PATCH 42/42] ADD Dr. Who test and method --- lib/Sale.rb | 27 +++++++++++++++++++++++++++ specs/Sale_spec.rb | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/lib/Sale.rb b/lib/Sale.rb index 75aa8d3e..39ddaf5f 100644 --- a/lib/Sale.rb +++ b/lib/Sale.rb @@ -51,6 +51,33 @@ def get_vendor return found_vendor end + def get_product + found_product = FarMar::Product.find(@product_id) + return found_product + end + + # expects string, returns Sale objects + def self.between(begin_time, end_time) + + found_sales = [] + + start_time = Time.parse(begin_time) + finish_time = Time.parse(end_time) + + all.each do |sale| + + purchase_date = sale.purchase_date + sale_time = Time.parse(purchase_date) + + if sale_time >= start_time && + sale_time <= finish_time + + found_sales.push(sale) + end + end + return found_sales + end + end diff --git a/specs/Sale_spec.rb b/specs/Sale_spec.rb index b82bef7b..08f394e1 100644 --- a/specs/Sale_spec.rb +++ b/specs/Sale_spec.rb @@ -1,5 +1,6 @@ require_relative 'spec_helper.rb' require_relative '../far_mar.rb' +require 'date' describe "Testing sale" do @@ -48,10 +49,49 @@ it "Tests that the get_vendor method returns the FarMar::Vendor instance that is associated with this sale using the FarMar::Sale vendor_id field" do new_sale = FarMar::Sale.find('32') found_vendor = new_sale.get_vendor - #vendor_id 7 product_id 14 + #vendor_id 7 found_vendor.id.must_equal '7' end + it "Tests that get_product returns the FarMar::Product instance that is associated with this sale using the FarMar::Sale product_id field" do + new_sale = FarMar::Sale.find('32') + found_product = new_sale.get_product + #product_id 14 + found_product.id.must_equal '14' + end + + # "2013-11-13 04:14:40 -0800" + it "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" do + + # tests for a single instance + start_time = "2013-11-13 04:14:40 -0800" + end_time = "2013-11-13 04:14:40 -0800" + + found_sales = FarMar::Sale.between(start_time, end_time) + found_sales.length.must_equal 1 + + # tests for many instances + start_time = "2013-11-13 00:00:00 -0800" + end_time = "2013-11-13 23:59:59 -0800" + + found_sales = FarMar::Sale.between(start_time, end_time) + found_sales.length.must_equal 669 + + # tests for instances where no sales are made + start_time = "2013-11-13 23:59:59 -0800" + end_time = "2013-11-13 00:00:00 -0800" + + found_sales = FarMar::Sale.between(start_time, end_time) + found_sales.length.must_equal 0 + + + # dr. who test because wiggly wobbly timey wimey + start_time = "1900-01-01 00:00:01 -0800" + end_time = "3000-12-31 23:59:59 -0800" + + found_sales = FarMar::Sale.between(start_time, end_time) + found_sales.length.must_equal 12798 + end end