Skip to content

Commit

Permalink
Create gem, try to get harness working, give up, cry, copy files over…
Browse files Browse the repository at this point in the history
… manually, scream Yoho's name into the sky...
  • Loading branch information
thejonanshow committed Mar 29, 2012
1 parent b8eecb0 commit 994ed3d
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 41 deletions.
Binary file added sales_engine-1.gem
Binary file not shown.
24 changes: 24 additions & 0 deletions sales_engine.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- encoding: utf-8 -*-

lib = File.expand_path('../lib/', __FILE__)
$:.unshift lib unless $:.include?(lib)

require 'bundler/version'

Gem::Specification.new do |s|
s.name = "sales_engine"
s.version = 1
s.platform = Gem::Platform::RUBY
s.authors = ["Jonan Scheffler", "Nisarg Shah"]
s.email = ["jonanscheffler+nisargshah100@gmail.com"]
s.homepage = "https://1337807@github.com/1337807/sales_engine.git"
s.summary = "Infernal hellspawn of a project devised by evil pirate Yoho and deathlord Casimir"
s.description = "This calculates revenue of useless pretend merchants and makes programmers want to die."

s.required_rubygems_version = ">= 1.3.6"

s.add_development_dependency "rspec"

s.files = Dir.glob("lib/**/*")
s.require_path = 'lib'
end
6 changes: 4 additions & 2 deletions spec_evaluation/customer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
describe ".random" do
it "usually returns different things on subsequent calls" do
customer_one = SalesEngine::Customer.random
customer_two = SalesEngine::Customer.random

10.times do
customer_two = SalesEngine::Customer.random
break if customer_one.id != customer_two.id
customer_two = SalesEngine::Customer.random
end

customer_one.id.should_not == customer_two.id
Expand All @@ -19,7 +21,7 @@
describe ".find_by_last_name" do
it "finds a record" do
customer = SalesEngine::Customer.find_by_last_name "Ullrich"
customer.first_name.should == "Ramon"
%w(Ramon Brice Annabell).should include(customer.first_name)
end
end

Expand Down
11 changes: 6 additions & 5 deletions spec_evaluation/invoice_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
describe ".random" do
it "usually returns different things on subsequent calls" do
invoice_item_one = SalesEngine::InvoiceItem.random
invoice_item_two = SalesEngine::InvoiceItem.random

10.times do
invoice_item_two = SalesEngine::InvoiceItem.random
break if invoice_item_one.id != invoice_item_two.id
invoice_item_two = SalesEngine::InvoiceItem.random
end

invoice_item_one.id.should_not == invoice_item_two.id
Expand All @@ -17,7 +19,7 @@
describe ".find_by_item_id" do
it "can find a record" do
invoice_item = SalesEngine::InvoiceItem.find_by_item_id 123
invoice_item.invoice_id.should == 184
invoice_item.item.name.should == "Item Doloribus Ducimus"
end
end

Expand All @@ -34,14 +36,13 @@

describe "#item" do
it "exists" do
invoice_item.item.name.should == "Item Qui Esse"
invoice_item.item.name.should == "Item Cupiditate Magni"
end
end

describe "#invoice" do
it "exists" do
invoice_customer = SalesEngine::Customer.find_by_id invoice_item.customer_id
invoice_item.customer.last_name.should == invoice.customer.last_name
invoice_item.invoice.should be
end
end

Expand Down
23 changes: 20 additions & 3 deletions spec_evaluation/invoice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
describe ".random" do
it "usually returns different things on subsequent calls" do
invoice_one = SalesEngine::Invoice.random
invoice_two = SalesEngine::Invoice.random

10.times do
invoice_two = SalesEngine::Invoice.random
break if invoice_one.id != invoice_two.id
invoice_two = SalesEngine::Invoice.random
end

invoice_one.id.should_not == invoice_two.id
Expand Down Expand Up @@ -74,15 +76,30 @@
let(:customer) { SalesEngine::Customer.random }
let(:merchant) { SalesEngine::Merchant.random }
let(:items) do
(1..3).map { Item.random }
(1..3).map { SalesEngine::Item.random }
end
it "creates a new invoice" do

invoice = SalesEngine::Invoice.create(customer: customer, merchant: merchant, items: items)
pending "Verify relationships"

items.map(&:name).each do |name|
invoice.items.map(&:name).should include(name)
end

#invoice.merchant.id.should == merchant.id
invoice.customer.id.should == customer.id
end
end

describe "#charge" do
it "creates a transaction" do
invoice = SalesEngine::Invoice.find_by_id(100)
prior_transaction_count = invoice.transactions.count

invoice.charge(credit_card_number: '1111222233334444', credit_card_expiration_date: "10/14", result: "success")

invoice = SalesEngine::Invoice.find_by_id(invoice.id)
invoice.transactions.count.should == prior_transaction_count + 1
end
end

Expand Down
14 changes: 8 additions & 6 deletions spec_evaluation/item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
describe ".random" do
it "usually returns different things on subsequent calls" do
item_one =SalesEngine::Item.random
item_two = SalesEngine::Item.random

10.times do
item_two = SalesEngine::Item.random
break if item_one.id != item_two.id
item_two = SalesEngine::Item.random
end

item_one.id.should_not == item_two.id
Expand All @@ -16,7 +18,7 @@

describe ".find_by_unit_price" do
it "can find one record" do
item =SalesEngine::Item.find_by_unit_price 93519
item = SalesEngine::Item.find_by_unit_price BigDecimal.new("935.19")
item.name.should == "Item Alias Nihil"
end
end
Expand Down Expand Up @@ -65,18 +67,18 @@

describe ".most_items" do
it "returns the top n items ranked by most sold" do
most = SalesEngine::Item.most_items(42)
most = SalesEngine::Item.most_items(37)

most.second.name.should == "Item Dicta Autem"
most.last.name.should == "Item Quidem Dolorum"
most[1].name.should == "Item Nam Magnam"
most.last.name.should == "Item Ut Quaerat"
end
end

describe "#best_day" do
let(:item) { SalesEngine::Item.find_by_name "Item Accusamus Ut" }

it "returns something castable to date" do
date = Date.parse "Tue, 27 Mar 2012"
date = Date.parse "Sat, 24 Mar 2012"
item.best_day.to_date.should == date
end
end
Expand Down
44 changes: 22 additions & 22 deletions spec_evaluation/merchant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
describe ".random" do
it "usually returns different things on subsequent calls" do
merchant_one = SalesEngine::Merchant.random
merchant_two = SalesEngine::Merchant.random

10.times do
merchant_two = SalesEngine::Merchant.random
break if merchant_one.id != merchant_two.id
merchant_two = SalesEngine::Merchant.random
end

merchant_one.id.should_not == merchant_two.id
Expand Down Expand Up @@ -61,7 +63,8 @@
it "returns all revenue for a given date" do
date = Date.parse "Tue, 20 Mar 2012"

SalesEngine::Merchant.revenue(date).to_f.should be_within(0.001).of(263902466.0)
revenue = SalesEngine::Merchant.revenue(date)
revenue.should == BigDecimal.new("2549722.91")
end
end

Expand All @@ -75,7 +78,7 @@

describe ".most_items" do
it "returns the top n item-sellers" do
most = SalesEngine::Merchant.most_revenue(4)
most = SalesEngine::Merchant.most_items(5)
most.first.name.should == "Kassulke, O'Hara and Quitzon"
most.last.name.should == "Daugherty Group"
end
Expand All @@ -86,50 +89,47 @@
let(:merchant) { SalesEngine::Merchant.find_by_name "Dicki-Bednar" }

it "reports all revenue" do
merchant.revenue.to_f.should be_within(0.001).of(118422772.0)
merchant.revenue.should == BigDecimal.new("1148393.74")
end
end
context "given a date" do
let(:merchant) { SalesEngine::Merchant.find_by_name "Nienow-Quigley" }
let(:merchant) { SalesEngine::Merchant.find_by_name "Willms and Sons" }

it "restricts to that date" do
date = Date.parse "Wed, 21 Mar 2012"
date = Date.parse "Fri, 09 Mar 2012"

merchant.revenue(date).to_f.should be_within(0.001).of(4521907.0)
merchant.revenue(date).should == BigDecimal.new("8373.29")
end
end
end

describe "#favorite_customer" do
let(:merchant) { SalesEngine::Merchant.find_by_name "Terry-Moore" }
let(:customer_names) do
[["Jayme", "Hammes"], ["Elmer", "Konopelski"], ["Eleanora", "Kling"],
["Friedrich", "Rowe"], ["Orion", "Hills"], ["Lambert", "Abernathy"]]
end

it "returns the customer with the most transactions" do
customer = merchant.favorite_customer
customer.first_name.should == "Orion"
customer.last_name.should == "Hills"
customer_names.any? do |first_name, last_name|
customer.first_name == first_name
customer.last_name == last_name
end.should be_true
end
end

describe "#customers_with_pending_invoices" do
let(:merchant) { SalesEngine::Merchant.find_by_name "Parisian Group" }

it "returns the total number of customers with pending invoices" do
customers = merchant.customers_with_pending_invoices
customers.count.should == 6
customers.count.should == 4
customers.any? do |customer|
customer.last_name == "Gaylord"
customer.last_name == "Ledner"
end.should be_true
end
end
end

context "Business Intelligence" do
describe ".revenue" do
it "returns all revenue for a given date" do
date = Date.parse "Tue, 20 Mar 2012"

revenue = SalesEngine::Merchant.revenue(date)
revenue.should == BigDecimal.new("2549722.91")
end
end
end

end
2 changes: 1 addition & 1 deletion spec_evaluation/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
config.before(:suite) do
SalesEngine.startup
end
end
end
6 changes: 4 additions & 2 deletions spec_evaluation/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
describe ".random" do
it "usually returns different things on subsequent calls" do
transaction_one = SalesEngine::Transaction.random
transaction_two = SalesEngine::Transaction.random

10.times do
transaction_two = SalesEngine::Transaction.random
break if transaction_one.id != transaction_two.id
transaction_two = SalesEngine::Transaction.random
end

transaction_one.id.should_not == transaction_two.id
Expand All @@ -25,7 +27,7 @@
describe ".find_all_by_result" do
it "can find multiple records" do
transactions = SalesEngine::Transaction.find_all_by_result "success"
transactions.should have(4648).transactions
transactions.count.should be_within(2).of(4648)
end
end
end
Expand Down

0 comments on commit 994ed3d

Please sign in to comment.