test/unit/client_test.rb in brisk-bills-0.7.0 vs test/unit/client_test.rb in brisk-bills-0.8.1
- old
+ new
@@ -1,7 +1,7 @@
-require File.dirname(__FILE__) + '/../test_helper'
-require File.dirname(__FILE__) + '/../test_unit_factory_helper.rb'
+require 'test_helper'
+require 'test_unit_factory_helper'
class ClientTest < ActiveSupport::TestCase
fixtures :clients
fixtures :activity_types
@@ -306,15 +306,46 @@
# Create a payment for the second
payments << Factory.generate_payment( client, 500.00 )
# Now we test all the invoice_payment mappings to be sure they make sense ..
- assert_equal true, invoices[0].is_paid?
+ assert_equal true, invoices[0].is_paid?(true)
assert_equal [payments[3].id], invoices[0].payment_assignments(true).collect(&:payment_id)
- assert_equal true, invoices[1].is_paid?
+ assert_equal true, invoices[1].is_paid?(true)
assert_equal [payments[1].id, payments[2].id], invoices[1].payment_assignments(true).collect(&:payment_id)
- assert_equal true, invoices[2].is_paid?
+ assert_equal true, invoices[2].is_paid?(true)
assert_equal [payments[0].id], invoices[2].payment_assignments(true).collect(&:payment_id)
end
-end
\ No newline at end of file
+
+ def test_find_invoiceable_clients_at
+
+ # Because we're using fixtures - we have some pre-existing clients and activities here .
+ # I really don't want 'em for this test though:
+ Client.find(:all).each{|c| c.destroy}
+ Activity.find(:all).each{|a| a.destroy}
+
+ # OK - time to get started:
+
+ Factory.generate_payment Factory.create_client(:company_name => "All Paid Up, Inc."), Money.new(10000)
+
+
+ clientA = Factory.create_client :company_name => "Client A"
+ clientB = Factory.create_client :company_name => "Client B"
+ clientC = Factory.create_client :company_name => "Client C"
+ clientD = Factory.create_client :company_name => "Client D"
+
+ Factory.create_labor( {}, {:client => clientA, :occurred_on => (DateTime.now << 1)} )
+ Factory.create_labor( {}, {:client => clientA, :occurred_on => (DateTime.now << 2)} )
+ Factory.create_labor( {}, {:client => clientA, :occurred_on => (DateTime.now >> 1)} )
+ Factory.create_labor( {}, {:client => clientB, :occurred_on => (DateTime.now << 1)} )
+ Factory.create_labor( {}, {:client => clientC, :occurred_on => (DateTime.now >> 1)} )
+ Factory.create_labor( {}, {:client => clientD, :occurred_on => (DateTime.now << 1), :is_published => false} )
+ Factory.create_labor( {}, {:client_id => nil, :occurred_on => (DateTime.now << 1)} )
+
+ invoiceable_clients = Client.find_invoiceable_clients_at(DateTime.now)
+
+ assert_equal 2, invoiceable_clients.length
+ assert_equal [clientA.id, clientB.id], invoiceable_clients.collect(&:id)
+ end
+end