Permalink
Browse files

Create gem, try to get harness working, give up, cry, copy files over…

… manually, scream Yoho's name into the sky...
  • Loading branch information...
1 parent b8eecb0 commit 994ed3dd7fb85b300d6611b59e5ce45452b9515e @thejonanshow committed Mar 29, 2012
View
Binary file not shown.
View
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -9,4 +9,4 @@
config.before(:suite) do
SalesEngine.startup
end
-end
+end
@@ -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
@@ -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

0 comments on commit 994ed3d

Please sign in to comment.