turingstudio-freshbooks-rb 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,64 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe FreshBooks::Category do
4
+ before(:each) do
5
+ @attributes = {
6
+ :name => 'Test',
7
+ :tax1 => 0
8
+ }
9
+ @category = FreshBooks::Category.new(@attributes)
10
+ @category.create
11
+ end
12
+
13
+ after(:each) do
14
+ @category.delete rescue nil
15
+ end
16
+
17
+ it "should list all categorys" do
18
+ FreshBooks::Category.list.size.should > 0
19
+ end
20
+
21
+ it "should find category by id" do
22
+ category = FreshBooks::Category.get(@category.category_id)
23
+ category.should_not be_nil
24
+ @attributes.each do |field, value|
25
+ category.send(field).should == @category.send(field)
26
+ end
27
+ end
28
+
29
+ it "should create a new category" do
30
+ categorys = FreshBooks::Category.list
31
+
32
+ category = FreshBooks::Category.new(@attributes.update(:name => 'Test2'))
33
+ category.create.should_not be_nil
34
+
35
+ FreshBooks::Category.list.size.should == categorys.size + 1
36
+
37
+ category.delete
38
+ end
39
+
40
+ it "should update an existing category" do
41
+ categorys = FreshBooks::Category.list
42
+ @category.name = 'Test2'
43
+ @category.update.should be_true
44
+ FreshBooks::Category.get(@category.category_id).name.should == 'Test2'
45
+ FreshBooks::Category.list.size.should == categorys.size
46
+ end
47
+
48
+ it "should delete category" do
49
+ categorys = FreshBooks::Category.list
50
+ @category.delete.should be_true
51
+ FreshBooks::Category.list.size.should == categorys.size - 1
52
+ end
53
+
54
+ it "should delete category by id" do
55
+ categorys = FreshBooks::Category.list
56
+ FreshBooks::Category.delete(@category.category_id).should be_true
57
+ FreshBooks::Category.list.size.should == categorys.size - 1
58
+ end
59
+
60
+ it "should have many expenses" do
61
+ FreshBooks::Expense.should_receive(:list).with({ 'category_id' => @category.category_id, 'name' => 'value' }).and_return([])
62
+ @category.expenses('name' => 'value').should == []
63
+ end
64
+ end
@@ -0,0 +1,91 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe FreshBooks::Client do
4
+ before(:each) do
5
+ @attributes = {
6
+ :first_name => 'Test',
7
+ :last_name => 'Test',
8
+ :email => 'test@test.com',
9
+ :organization => 'FlatsourcingTest'
10
+ }
11
+ @client = FreshBooks::Client.new(@attributes)
12
+ @client.create
13
+ end
14
+
15
+ after(:each) do
16
+ @client.delete rescue nil
17
+ end
18
+
19
+ it "should list all clients" do
20
+ FreshBooks::Client.list.size.should == 1
21
+ end
22
+
23
+ it "should find client by id" do
24
+ client = FreshBooks::Client.get(@client.client_id)
25
+ client.should_not be_nil
26
+ @attributes.each do |field, value|
27
+ client.send(field).should == @client.send(field)
28
+ end
29
+ end
30
+
31
+ it "should create a new client" do
32
+ clients = FreshBooks::Client.list
33
+
34
+ client = FreshBooks::Client.new(@attributes.update(:email => 'test1@test.com'))
35
+ client.create.should_not be_nil
36
+
37
+ FreshBooks::Client.list.size.should == clients.size + 1
38
+
39
+ client.delete
40
+ end
41
+
42
+ it "should update an existing client" do
43
+ clients = FreshBooks::Client.list
44
+ @client.first_name = 'Client'
45
+ @client.update.should be_true
46
+ FreshBooks::Client.get(@client.client_id).first_name.should == 'Client'
47
+ FreshBooks::Client.list.size.should == clients.size
48
+ end
49
+
50
+ it "should delete client" do
51
+ clients = FreshBooks::Client.list
52
+ @client.delete.should be_true
53
+ FreshBooks::Client.list.size.should == clients.size - 1
54
+ end
55
+
56
+ it "should delete client by id" do
57
+ clients = FreshBooks::Client.list
58
+ FreshBooks::Client.delete(@client.client_id).should be_true
59
+ FreshBooks::Client.list.size.should == clients.size - 1
60
+ end
61
+
62
+ it "should have many expenses" do
63
+ FreshBooks::Expense.should_receive(:list).with({ 'client_id' => @client.client_id, 'name' => 'value' }).and_return([])
64
+ @client.expenses('name' => 'value').should == []
65
+ end
66
+
67
+ it "should have many estimates" do
68
+ FreshBooks::Estimate.should_receive(:list).with({ 'client_id' => @client.client_id, 'name' => 'value' }).and_return([])
69
+ @client.estimates('name' => 'value').should == []
70
+ end
71
+
72
+ it "should have many invoices" do
73
+ FreshBooks::Invoice.should_receive(:list).with({ 'client_id' => @client.client_id, 'name' => 'value' }).and_return([])
74
+ @client.invoices('name' => 'value').should == []
75
+ end
76
+
77
+ it "should have many payments" do
78
+ FreshBooks::Payment.should_receive(:list).with({ 'client_id' => @client.client_id, 'name' => 'value' }).and_return([])
79
+ @client.payments('name' => 'value').should == []
80
+ end
81
+
82
+ it "should have many projects" do
83
+ FreshBooks::Project.should_receive(:list).with({ 'client_id' => @client.client_id, 'name' => 'value' }).and_return([])
84
+ @client.projects('name' => 'value').should == []
85
+ end
86
+
87
+ it "should have many recurrings" do
88
+ FreshBooks::Recurring.should_receive(:list).with({ 'client_id' => @client.client_id, 'name' => 'value' }).and_return([])
89
+ @client.recurrings('name' => 'value').should == []
90
+ end
91
+ end
@@ -0,0 +1,80 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe FreshBooks::Estimate do
4
+ before(:all) do
5
+ @client = FreshBooks::Client.new(
6
+ :first_name => 'Test',
7
+ :last_name => 'Test',
8
+ :email => 'test@test.com',
9
+ :organization => 'FlatsourcingTest'
10
+ )
11
+ @client.create
12
+ end
13
+
14
+ after(:all) do
15
+ @client.delete
16
+ end
17
+
18
+ before(:each) do
19
+ @attributes = {
20
+ :client_id => @client.client_id,
21
+ :first_name => 'Test',
22
+ :last_name => 'Test',
23
+ :organization => 'FlatsourcingTest'
24
+ }
25
+ @estimate = FreshBooks::Estimate.new(@attributes)
26
+ @estimate.create
27
+ end
28
+
29
+ after(:each) do
30
+ @estimate.delete rescue nil
31
+ end
32
+
33
+ it "should list all estimates" do
34
+ FreshBooks::Estimate.list.size.should == 1
35
+ end
36
+
37
+ it "should find estimate by id" do
38
+ estimate = FreshBooks::Estimate.get(@estimate.estimate_id)
39
+ estimate.should_not be_nil
40
+ @attributes.each do |field, value|
41
+ estimate.send(field).should == @estimate.send(field)
42
+ end
43
+ end
44
+
45
+ it "should create a new estimate" do
46
+ estimates = FreshBooks::Estimate.list
47
+
48
+ estimate = FreshBooks::Estimate.new(@attributes)
49
+ estimate.create.should_not be_nil
50
+
51
+ FreshBooks::Estimate.list.size.should == estimates.size + 1
52
+
53
+ estimate.delete
54
+ end
55
+
56
+ it "should update an existing estimate" do
57
+ estimates = FreshBooks::Estimate.list
58
+ @estimate.first_name = 'Estimate'
59
+ @estimate.update.should be_true
60
+ FreshBooks::Estimate.get(@estimate.estimate_id).first_name.should == 'Estimate'
61
+ FreshBooks::Estimate.list.size.should == estimates.size
62
+ end
63
+
64
+ it "should delete estimate" do
65
+ estimates = FreshBooks::Estimate.list
66
+ @estimate.delete.should be_true
67
+ FreshBooks::Estimate.list.size.should == estimates.size - 1
68
+ end
69
+
70
+ it "should delete estimate by id" do
71
+ estimates = FreshBooks::Estimate.list
72
+ FreshBooks::Estimate.delete(@estimate.estimate_id).should be_true
73
+ FreshBooks::Estimate.list.size.should == estimates.size - 1
74
+ end
75
+
76
+ it "should belong to client" do
77
+ FreshBooks::Client.should_receive(:get).with(@estimate.client_id).and_return(@client)
78
+ @estimate.client.should == @client
79
+ end
80
+ end
@@ -0,0 +1,86 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe FreshBooks::Expense do
4
+ before(:all) do
5
+ @client = FreshBooks::Client.new(
6
+ :first_name => 'Test',
7
+ :last_name => 'Test',
8
+ :email => 'test@test.com',
9
+ :organization => 'FlatsourcingTest'
10
+ )
11
+ @client.create
12
+
13
+ @staff = FreshBooks::Staff.list[0]
14
+ end
15
+
16
+ after(:all) do
17
+ @client.delete
18
+ end
19
+
20
+ before(:each) do
21
+ @attributes = {
22
+ :client_id => @client.client_id,
23
+ :staff_id => @staff.staff_id,
24
+ :amount => 100
25
+ }
26
+ @expense = FreshBooks::Expense.new(@attributes)
27
+ @expense.create
28
+ end
29
+
30
+ after(:each) do
31
+ @expense.delete rescue nil
32
+ end
33
+
34
+ it "should list all expenses" do
35
+ FreshBooks::Expense.list.size.should == 1
36
+ end
37
+
38
+ it "should find expense by id" do
39
+ expense = FreshBooks::Expense.get(@expense.expense_id)
40
+ expense.should_not be_nil
41
+ @attributes.each do |field, value|
42
+ expense.send(field).should == @expense.send(field)
43
+ end
44
+ end
45
+
46
+ it "should create a new expense" do
47
+ expenses = FreshBooks::Expense.list
48
+
49
+ expense = FreshBooks::Expense.new(@attributes)
50
+ expense.create.should_not be_nil
51
+
52
+ FreshBooks::Expense.list.size.should == expenses.size + 1
53
+
54
+ expense.delete
55
+ end
56
+
57
+ it "should update an existing expense" do
58
+ expenses = FreshBooks::Expense.list
59
+ @expense.amount = 150
60
+ @expense.update.should be_true
61
+ FreshBooks::Expense.get(@expense.expense_id).amount.should == 150
62
+ FreshBooks::Expense.list.size.should == expenses.size
63
+ end
64
+
65
+ it "should delete expense" do
66
+ expenses = FreshBooks::Expense.list
67
+ @expense.delete.should be_true
68
+ FreshBooks::Expense.list.size.should == expenses.size - 1
69
+ end
70
+
71
+ it "should delete expense by id" do
72
+ expenses = FreshBooks::Expense.list
73
+ FreshBooks::Expense.delete(@expense.expense_id).should be_true
74
+ FreshBooks::Expense.list.size.should == expenses.size - 1
75
+ end
76
+
77
+ it "should belong to client" do
78
+ FreshBooks::Client.should_receive(:get).with(@expense.client_id).and_return(@client)
79
+ @expense.client.should == @client
80
+ end
81
+
82
+ it "should belong to staff member" do
83
+ FreshBooks::Staff.should_receive(:get).with(@expense.staff_id).and_return(@staff)
84
+ @expense.staff.should == @staff
85
+ end
86
+ end
@@ -0,0 +1,89 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe FreshBooks::Invoice do
4
+ before(:all) do
5
+ @client = FreshBooks::Client.new(
6
+ :first_name => 'Test',
7
+ :last_name => 'Test',
8
+ :email => 'test@test.com',
9
+ :organization => 'FlatsourcingTest'
10
+ )
11
+ @client.create
12
+ end
13
+
14
+ after(:all) do
15
+ @client.delete
16
+ end
17
+
18
+ before(:each) do
19
+ @attributes = {
20
+ :client_id => @client.client_id,
21
+ :first_name => 'Test',
22
+ :last_name => 'Test',
23
+ :organization => 'FlatsourcingTest'
24
+ }
25
+ @invoice = FreshBooks::Invoice.new(@attributes)
26
+ @invoice.create
27
+ end
28
+
29
+ after(:each) do
30
+ @invoice.delete rescue nil
31
+ end
32
+
33
+ it "should set up lines array" do
34
+ @invoice.lines.should == []
35
+ end
36
+
37
+ it "should list all invoices" do
38
+ FreshBooks::Invoice.list.size.should > 0
39
+ end
40
+
41
+ it "should find invoice by id" do
42
+ invoice = FreshBooks::Invoice.get(@invoice.invoice_id)
43
+ invoice.should_not be_nil
44
+ @attributes.each do |field, value|
45
+ invoice.send(field).should == @invoice.send(field)
46
+ end
47
+ end
48
+
49
+ it "should create a new invoice" do
50
+ invoices = FreshBooks::Invoice.list
51
+
52
+ invoice = FreshBooks::Invoice.new(@attributes)
53
+ invoice.create.should_not be_nil
54
+
55
+ FreshBooks::Invoice.list.size.should == invoices.size + 1
56
+
57
+ invoice.delete
58
+ end
59
+
60
+ it "should update an existing invoice" do
61
+ invoices = FreshBooks::Invoice.list
62
+ @invoice.first_name = 'Invoice'
63
+ @invoice.update.should be_true
64
+ FreshBooks::Invoice.get(@invoice.invoice_id).first_name.should == 'Invoice'
65
+ FreshBooks::Invoice.list.size.should == invoices.size
66
+ end
67
+
68
+ it "should delete invoice" do
69
+ invoices = FreshBooks::Invoice.list
70
+ @invoice.delete.should be_true
71
+ FreshBooks::Invoice.list.size.should == invoices.size - 1
72
+ end
73
+
74
+ it "should delete invoice by id" do
75
+ invoices = FreshBooks::Invoice.list
76
+ FreshBooks::Invoice.delete(@invoice.invoice_id).should be_true
77
+ FreshBooks::Invoice.list.size.should == invoices.size - 1
78
+ end
79
+
80
+ it "should belong to client" do
81
+ FreshBooks::Client.should_receive(:get).with(@invoice.client_id).and_return(@client)
82
+ @invoice.client.should == @client
83
+ end
84
+
85
+ it "should have many payments" do
86
+ FreshBooks::Payment.should_receive(:list).with({ 'invoice_id' => @invoice.invoice_id, 'name' => 'value' }).and_return([])
87
+ @invoice.payments('name' => 'value').should == []
88
+ end
89
+ end
@@ -0,0 +1,75 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ class Sequence
4
+ def initialize(prefix = 'seq')
5
+ @prefix = prefix
6
+ @index = Time.now.to_i
7
+ end
8
+
9
+ def next
10
+ @index += 1
11
+ "#{@prefix}#{@index}"
12
+ end
13
+ end
14
+
15
+ describe FreshBooks::Item do
16
+ before(:all) do
17
+ @seq = Sequence.new('item')
18
+ end
19
+
20
+ before(:each) do
21
+ @attributes = {
22
+ :name => @seq.next
23
+ }
24
+ @item = FreshBooks::Item.new(@attributes)
25
+ @item.create
26
+ end
27
+
28
+ after(:each) do
29
+ @item.delete rescue nil
30
+ end
31
+
32
+ it "should list all items" do
33
+ FreshBooks::Item.list.size.should > 0
34
+ end
35
+
36
+ it "should find item by id" do
37
+ item = FreshBooks::Item.get(@item.item_id)
38
+ item.should_not be_nil
39
+ @attributes.each do |field, value|
40
+ item.send(field).should == @item.send(field)
41
+ end
42
+ end
43
+
44
+ it "should create a new item" do
45
+ items = FreshBooks::Item.list
46
+
47
+ item = FreshBooks::Item.new(@attributes.update(:name => @seq.next))
48
+ item.create.should_not be_nil
49
+
50
+ FreshBooks::Item.list.size.should == items.size + 1
51
+
52
+ item.delete
53
+ end
54
+
55
+ it "should update an existing item" do
56
+ items = FreshBooks::Item.list
57
+ name = @seq.next
58
+ @item.name = name
59
+ @item.update.should be_true
60
+ FreshBooks::Item.get(@item.item_id).name.should == name
61
+ FreshBooks::Item.list.size.should == items.size
62
+ end
63
+
64
+ it "should delete item" do
65
+ items = FreshBooks::Item.list
66
+ @item.delete.should be_true
67
+ FreshBooks::Item.list.size.should == items.size - 1
68
+ end
69
+
70
+ it "should delete item by id" do
71
+ items = FreshBooks::Item.list
72
+ FreshBooks::Item.delete(@item.item_id).should be_true
73
+ FreshBooks::Item.list.size.should == items.size - 1
74
+ end
75
+ end