Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ash/master #50

Open
wants to merge 4 commits into
base: ash/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 61 additions & 5 deletions SPEC/far_mar/market_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,69 @@
require "spec_helper"
require 'spec_helper'

describe FarMar::Market do
before :each do
@market = FarMar::Market.new("Rainier")
end
before :each do
market_hash = {
id: "1",
name: "People's Co-op Farmers Market",
address: "30th and Burnside",
city: "Portland",
county: "Multnomah",
state: "Oregon",
zip: "97202"
}


@market = FarMar::Market.new(market_hash)
end

describe "self.new(name)" do
describe "self.new" do
it "creates a new instance of Market" do
expect(@market).to be_an_instance_of FarMar::Market
end


it "has a name property that is equal to what is passed in" do
expect(@market.city).to eq "Portland"
end

it "knows about its associated data file" do
expect(@market.market_csv).to eq ("./support/markets.csv")
end
end

describe "self.all" do
all_markets = FarMar::Market.all
it "returns an array" do
expect(all_markets.class).to eq Array
#test that it is an array
expect(all_markets[0]).to be_an_instance_of FarMar::Market
expect(all_markets[-1]).to be_an_instance_of FarMar::Market
market_csv= CSV.read("./support/markets.csv")
expect(all_markets.length).to eq (market_csv.length)
#all markets length to equal csv.length
end
end

#returns the instance of Market with matching the input # ID
describe "self.find(id)" do
it "returns an instance of FarMar::Market with its passed in id" do
expect(FarMar::Market.find(1)).to be_an_instance_of FarMar::Market
expect(FarMar::Market.find(1).name).to eq "People's Co-op Farmers Market"
end
end

describe "vendors" do
it "returns an array of FarMar::Vendor instances that are associated with the market_id field." do
expect(@market.vendors.class).to eq Array
end

it "returns 6" do
expect(@market.vendors.length).to eq 6
end

end
end

# it do
# expect(@market.vendors.length).to eq
# end
42 changes: 38 additions & 4 deletions SPEC/far_mar/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,46 @@

describe FarMar::Product do
before :each do
@product = FarMar::Product.new("cherries")
product_hash={
id: 1,
name: "Dry Beets",
vendor_id: 1
}
@product = FarMar::Product.new(product_hash)
end

describe "self.new(name)" do
it "creates a new instance of Market" do
describe "self.new" do
it "creates a new instance of Product" do
expect(@product).to be_an_instance_of FarMar::Product
end

it "has a name property that is equal to what is passed in" do
expect(@product.name).to eq "Dry Beets"
end

it "knows about its associated data file" do
expect(@product.products_csv).to eq ("./support/products.csv")
end
end

describe "self.all" do
all_products = FarMar::Product.all
it "returns an array" do
expect(all_products.class).to eq Array
#test that it is an array
expect(all_products[0]).to be_an_instance_of FarMar::Product
expect(all_products[-1]).to be_an_instance_of FarMar::Product
products_csv= CSV.read("./support/products.csv")
expect(all_products.length).to eq (products_csv.length)
#all markets length to equal csv.length
end
end

#returns the instance of Market with matching the input # ID
describe "self.find(id)" do
it "returns an instance of FarMar::Product with its passed in id" do
expect(FarMar::Product.find(1)).to be_an_instance_of FarMar::Product
expect(FarMar::Product.find(1).id).to eq 1
end
end
end
end
45 changes: 41 additions & 4 deletions SPEC/far_mar/sale_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,49 @@

describe FarMar::Sale do
before :each do
@sale = FarMar::Sale.new("pounds")
sale_hash = {
id: 1,
amount: 9290,
purchase_time: "2013-11-07 04:34:56 -0800",
vendor_id: 1,
product_id: 1
}

@sale = FarMar::Sale.new(sale_hash)
end

describe "self.new(name)" do
it "creates a new instance of Market" do
describe "self.new" do
it "creates a new instance of Sale" do
expect(@sale).to be_an_instance_of FarMar::Sale
end

it "has an id property that is equal to what it is passed in" do
expect(@sale.id).to eq 1
end

it "knows bout its associated data file" do
expect(@sale.sales_csv).to eq ("./support/sales.csv")
end
end

describe "self.all" do
all_sales = FarMar::Sale.all
it "returns an array" do
expect(all_sales.class).to eq Array
#test that it is an array
expect(all_sales[0]).to be_an_instance_of FarMar::Sale
expect(all_sales[-1]).to be_an_instance_of FarMar::Sale
sales_csv= CSV.read("./support/sales.csv")
expect(all_sales.length).to eq (sales_csv.length)
#all markets length to equal csv.length
end
end

#returns the instance of Market with matching the input # ID
describe "self.find(id)" do
it "returns an instance of FarMar::Sale with its passed in id" do
expect(FarMar::Sale.find(1)).to be_an_instance_of FarMar::Sale
expect(FarMar::Sale.find(1).amount).to eq 9290
end
end
end
end
91 changes: 88 additions & 3 deletions SPEC/far_mar/vendor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,97 @@

describe FarMar::Vendor do
before :each do
@vendor = FarMar::Vendor.new("Earth Farms")
vendor_hash= {
id: 1,
name: "Feil-Farrell",
num_employees: 8,
market_id: 1
}

@vendor = FarMar::Vendor.new(vendor_hash)
end

describe "self.new(name)" do
describe "self.new" do
it "creates a new instance of Vendor" do
expect(@vendor).to be_an_instance_of FarMar::Vendor
end


it "has a name property that is equal to what is passed in" do
expect(@vendor.name).to eq "Feil-Farrell"
end

it "knows about its associated data file" do
expect(@vendor.vendor_csv).to eq ("./support/vendors.csv")
end
end

describe "self.all" do
all_vendors = FarMar::Vendor.all
it "returns an array" do
expect(all_vendors.class).to eq Array
#test that it is an array
expect(all_vendors[0]).to be_an_instance_of FarMar::Vendor
expect(all_vendors[-1]).to be_an_instance_of FarMar::Vendor
vendor_csv= CSV.read("./support/vendors.csv")
expect(all_vendors.length).to eq (vendor_csv.length)
#all markets length to equal csv.length
end
end

#returns the instance of Market with matching the input # ID
describe "self.find(id)" do
it "returns an instance of FarMar::Vendor with its passed in id" do
expect(FarMar::Vendor.find(1)).to be_an_instance_of FarMar::Vendor
expect(FarMar::Vendor.find(1).id).to eq 1
end
end

describe ".markets" do
it "returns an instance of FarMar::Market" do
expect(@vendor.market).to be_an_instance_of FarMar::Market
end

it "returns 6" do
expect(@vendor.market.name).to eq "People's Co-op Farmers Market"
end
end

describe ".product" do
it "returns a collection of FarMar::Product instances that are associated by the FarMar::Product vendor_id field." do
expect(FarMar::Product.find(1)).to be_an_instance_of FarMar::Product
expect(FarMar::Product.find(1).vendor_id).to eq 1
expect(@vendor.products.class).to eq Array
end

it "returns 1" do
@vendor.products.each do |product|
expect(product.vendor_id).to eq @vendor.id
end
end
end

describe ".sales" do
it "returns a collection of FarMar::Sale instances that are associated by the @vendor.id field" do
@vendor.sales.each do |sales|
expect(sales.vendor_id).to eq @vendor.id
end
end

it "returns an array" do
expect(@vendor.sales.class).to eq Array
end
end

describe ".revenue" do
it "returns the sum of Sale.amount values" do
expect(@vendor.revenue.class).to eq Fixnum
end
end

it "returns 9290 for the sume of Sale.amount" do
FarMar::Sales.each do |sale|
expect(sale.amount).to eq 9290
end
end
end
end
2 changes: 1 addition & 1 deletion SPEC/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "simplecov"
SimpleCov.start

require "pry"
require "./lib/far_mar"
70 changes: 68 additions & 2 deletions lib/far_mar/market.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,73 @@
require 'csv'

module FarMar
class Market
def initialize(name)
@name = name
attr_reader :id, :name, :address, :city, :county, :state, :zip, :market_csv
def initialize(market_hash)
@id = market_hash[:id].to_i
@name = market_hash[:name]
@address = market_hash[:address]
@city = market_hash[:city]
@county = market_hash[:county]
@state = market_hash[:state]
@zip = market_hash[:zip]
@market_csv = ("./support/markets.csv")

end


def self.all
@@markets_all ||=

CSV.read("support/markets.csv").map do |row|
#binding.pry
FarMar::Market.new({
id: row[0].to_i,
name: row[1],
address: row[2],
city: row[3],
county: row[4],
state: row[5],
zip: row[6]
})
end
end

def self.find(id)
# all_markets = FarMar::Market.all
all.find do |market|
market.id == id
end
end

def vendors
#create an empty array
#match FarMar::Market id with FarMar:: Vendor id
FarMar::Vendor.all.find_all do |vendor|
vendor.market_id == @id
end
end
end
end

#
#
#
#
#
#
#
#
#
#
#
#
# market_hash =
# { id: 1738,
# name: "Newtown",
# address: "123 Fake St. SW",
# city: "Seattle",
# county: "King",
# state: "WA",
# zip: "98146"
# }
Loading