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.
- data/History.txt +4 -0
- data/README.rdoc +65 -0
- data/Rakefile +20 -0
- data/lib/freshbooks.rb +41 -0
- data/lib/freshbooks/base.rb +286 -0
- data/lib/freshbooks/category.rb +11 -0
- data/lib/freshbooks/client.rb +32 -0
- data/lib/freshbooks/estimate.rb +30 -0
- data/lib/freshbooks/expense.rb +16 -0
- data/lib/freshbooks/invoice.rb +34 -0
- data/lib/freshbooks/item.rb +12 -0
- data/lib/freshbooks/line.rb +13 -0
- data/lib/freshbooks/payment.rb +22 -0
- data/lib/freshbooks/project.rb +39 -0
- data/lib/freshbooks/recurring.rb +51 -0
- data/lib/freshbooks/response.rb +25 -0
- data/lib/freshbooks/staff.rb +24 -0
- data/lib/freshbooks/task.rb +11 -0
- data/lib/freshbooks/time_entry.rb +13 -0
- data/lib/freshbooks/version.rb +6 -0
- data/spec/lib/freshbooks/base_spec.rb +385 -0
- data/spec/lib/freshbooks/category_spec.rb +64 -0
- data/spec/lib/freshbooks/client_spec.rb +91 -0
- data/spec/lib/freshbooks/estimate_spec.rb +80 -0
- data/spec/lib/freshbooks/expense_spec.rb +86 -0
- data/spec/lib/freshbooks/invoice_spec.rb +89 -0
- data/spec/lib/freshbooks/item_spec.rb +75 -0
- data/spec/lib/freshbooks/payment_spec.rb +77 -0
- data/spec/lib/freshbooks/project_spec.rb +83 -0
- data/spec/lib/freshbooks/recurring_spec.rb +82 -0
- data/spec/lib/freshbooks/staff_spec.rb +21 -0
- data/spec/lib/freshbooks/task_spec.rb +61 -0
- data/spec/lib/freshbooks/time_entry_spec.rb +94 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +11 -0
- data/tasks/rspec.rake +33 -0
- metadata +109 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe FreshBooks::Payment 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
|
+
@invoice = FreshBooks::Invoice.new(
|
14
|
+
:client_id => @client.client_id,
|
15
|
+
:first_name => 'Test',
|
16
|
+
:last_name => 'Test',
|
17
|
+
:email => 'anton+1@flatsourcing.com',
|
18
|
+
:organization => 'FlatsourcingTest'
|
19
|
+
)
|
20
|
+
@invoice.create
|
21
|
+
end
|
22
|
+
|
23
|
+
after(:all) do
|
24
|
+
@invoice.delete
|
25
|
+
@client.delete
|
26
|
+
end
|
27
|
+
|
28
|
+
before(:each) do
|
29
|
+
@attributes = {
|
30
|
+
:client_id => @client.client_id,
|
31
|
+
:invoice_id => @invoice.invoice_id,
|
32
|
+
:amount => 0
|
33
|
+
}
|
34
|
+
@payment = FreshBooks::Payment.new(@attributes)
|
35
|
+
@payment.create
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should list all payments" do
|
39
|
+
FreshBooks::Payment.list.size.should > 0
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should find payment by id" do
|
43
|
+
payment = FreshBooks::Payment.get(@payment.payment_id)
|
44
|
+
payment.should_not be_nil
|
45
|
+
@attributes.each do |field, value|
|
46
|
+
payment.send(field).should == @payment.send(field)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should create a new payment with only client_id" do
|
51
|
+
payment = FreshBooks::Payment.new(@attributes.except(:invoice_id))
|
52
|
+
payment.create.should_not be_nil
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should create a new payment with only invoice_id" do
|
56
|
+
payment = FreshBooks::Payment.new(@attributes.except(:client_id))
|
57
|
+
payment.create.should_not be_nil
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should update an existing payment" do
|
61
|
+
payments = FreshBooks::Payment.list
|
62
|
+
@payment.type = 'VISA'
|
63
|
+
@payment.update.should be_true
|
64
|
+
FreshBooks::Payment.get(@payment.payment_id).type.should == 'VISA'
|
65
|
+
FreshBooks::Payment.list.size.should == payments.size
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should belong to client" do
|
69
|
+
FreshBooks::Client.should_receive(:get).with(@payment.client_id).and_return(@client)
|
70
|
+
@payment.client.should == @client
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should belong to payment" do
|
74
|
+
FreshBooks::Invoice.should_receive(:get).with(@payment.invoice_id).and_return(@client)
|
75
|
+
@payment.invoice.should == @client
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe FreshBooks::Project 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
|
+
:name => 'Test',
|
22
|
+
:bill_method => 'task-rate'
|
23
|
+
}
|
24
|
+
@project = FreshBooks::Project.new(@attributes)
|
25
|
+
@project.create
|
26
|
+
end
|
27
|
+
|
28
|
+
after(:each) do
|
29
|
+
@project.delete rescue nil
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should set up tasks array" do
|
33
|
+
@project.tasks.should == []
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should list all projects" do
|
37
|
+
FreshBooks::Project.list.size.should > 0
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should find project by id" do
|
41
|
+
project = FreshBooks::Project.get(@project.project_id)
|
42
|
+
project.should_not be_nil
|
43
|
+
@attributes.each do |field, value|
|
44
|
+
project.send(field).should == @project.send(field)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should create a new project" do
|
49
|
+
projects = FreshBooks::Project.list
|
50
|
+
|
51
|
+
project = FreshBooks::Project.new(@attributes)
|
52
|
+
project.create.should_not be_nil
|
53
|
+
|
54
|
+
FreshBooks::Project.list.size.should == projects.size + 1
|
55
|
+
|
56
|
+
project.delete
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should update an existing project" do
|
60
|
+
projects = FreshBooks::Project.list
|
61
|
+
@project.name = 'Project'
|
62
|
+
@project.update.should be_true
|
63
|
+
FreshBooks::Project.get(@project.project_id).name.should == 'Project'
|
64
|
+
FreshBooks::Project.list.size.should == projects.size
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should delete project" do
|
68
|
+
projects = FreshBooks::Project.list
|
69
|
+
@project.delete.should be_true
|
70
|
+
FreshBooks::Project.list.size.should == projects.size - 1
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should delete project by id" do
|
74
|
+
projects = FreshBooks::Project.list
|
75
|
+
FreshBooks::Project.delete(@project.project_id).should be_true
|
76
|
+
FreshBooks::Project.list.size.should == projects.size - 1
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should belong to client" do
|
80
|
+
FreshBooks::Client.should_receive(:get).with(@project.client_id).and_return(@client)
|
81
|
+
@project.client.should == @client
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe FreshBooks::Recurring 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
|
+
:occurrences => 10,
|
22
|
+
:first_name => 'Test',
|
23
|
+
:last_name => 'Test',
|
24
|
+
:organization => 'FlatsourcingTest'
|
25
|
+
}
|
26
|
+
|
27
|
+
@recurring = FreshBooks::Recurring.new(@attributes)
|
28
|
+
@recurring.create
|
29
|
+
end
|
30
|
+
|
31
|
+
after(:each) do
|
32
|
+
@recurring.delete rescue nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should list all recurrings" do
|
36
|
+
FreshBooks::Recurring.list.size.should == 1
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should find recurring by id" do
|
40
|
+
recurring = FreshBooks::Recurring.get(@recurring.recurring_id)
|
41
|
+
recurring.should_not be_nil
|
42
|
+
@attributes.each do |field, value|
|
43
|
+
recurring.send(field).should == @recurring.send(field)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should create a new recurring" do
|
48
|
+
recurrings = FreshBooks::Recurring.list
|
49
|
+
|
50
|
+
recurring = FreshBooks::Recurring.new(@attributes)
|
51
|
+
recurring.create.should_not be_nil
|
52
|
+
|
53
|
+
FreshBooks::Recurring.list.size.should == recurrings.size + 1
|
54
|
+
|
55
|
+
recurring.delete
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should update an existing recurring" do
|
59
|
+
recurrings = FreshBooks::Recurring.list
|
60
|
+
@recurring.first_name = 'Recurring'
|
61
|
+
@recurring.update.should be_true
|
62
|
+
FreshBooks::Recurring.get(@recurring.recurring_id).first_name.should == 'Recurring'
|
63
|
+
FreshBooks::Recurring.list.size.should == recurrings.size
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should delete recurring" do
|
67
|
+
recurrings = FreshBooks::Recurring.list
|
68
|
+
@recurring.delete.should be_true
|
69
|
+
FreshBooks::Recurring.list.size.should == recurrings.size - 1
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should delete recurring by id" do
|
73
|
+
recurrings = FreshBooks::Recurring.list
|
74
|
+
FreshBooks::Recurring.delete(@recurring.recurring_id).should be_true
|
75
|
+
FreshBooks::Recurring.list.size.should == recurrings.size - 1
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should belong to client" do
|
79
|
+
FreshBooks::Client.should_receive(:get).with(@recurring.client_id).and_return(@client)
|
80
|
+
@recurring.client.should == @client
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe FreshBooks::Staff do
|
4
|
+
before(:each) do
|
5
|
+
@staff = FreshBooks::Staff.list[0]
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should list all staffs" do
|
9
|
+
FreshBooks::Staff.list.size.should > 0
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should find staff by id" do
|
13
|
+
staff = FreshBooks::Staff.get(@staff.staff_id)
|
14
|
+
staff.should_not be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have many expenses" do
|
18
|
+
FreshBooks::Expense.should_receive(:list).with({ 'staff_id' => @staff.staff_id, 'name' => 'value' }).and_return([])
|
19
|
+
@staff.expenses('name' => 'value').should == []
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe FreshBooks::Task do
|
4
|
+
before(:each) do
|
5
|
+
@attributes = {
|
6
|
+
:name => 'Test'
|
7
|
+
}
|
8
|
+
@task = FreshBooks::Task.new(@attributes)
|
9
|
+
@task.create
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:each) do
|
13
|
+
begin
|
14
|
+
@task.delete
|
15
|
+
rescue FreshBooks::Base::UnknownSystemError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should list all tasks" do
|
20
|
+
FreshBooks::Task.list.size.should > 0
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should find task by id" do
|
24
|
+
task = FreshBooks::Task.get(@task.task_id)
|
25
|
+
task.should_not be_nil
|
26
|
+
@attributes.each do |field, value|
|
27
|
+
task.send(field).should == @task.send(field)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should create a new task" do
|
32
|
+
tasks = FreshBooks::Task.list
|
33
|
+
|
34
|
+
task = FreshBooks::Task.new(@attributes.update(:name => 'Test2'))
|
35
|
+
task.create.should_not be_nil
|
36
|
+
|
37
|
+
FreshBooks::Task.list.size.should == tasks.size + 1
|
38
|
+
|
39
|
+
task.delete
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should update an existing task" do
|
43
|
+
tasks = FreshBooks::Task.list
|
44
|
+
@task.name = 'Test2'
|
45
|
+
@task.update.should be_true
|
46
|
+
FreshBooks::Task.get(@task.task_id).name.should == 'Test2'
|
47
|
+
FreshBooks::Task.list.size.should == tasks.size
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should delete task" do
|
51
|
+
tasks = FreshBooks::Task.list
|
52
|
+
@task.delete.should be_true
|
53
|
+
FreshBooks::Task.list.size.should == tasks.size - 1
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should delete task by id" do
|
57
|
+
tasks = FreshBooks::Task.list
|
58
|
+
FreshBooks::Task.delete(@task.task_id).should be_true
|
59
|
+
FreshBooks::Task.list.size.should == tasks.size - 1
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
# FIXME Project not found error when deleting time entry
|
4
|
+
# FIXME No user specified error when updating time entry
|
5
|
+
|
6
|
+
describe FreshBooks::TimeEntry do
|
7
|
+
before(:all) do
|
8
|
+
@client = FreshBooks::Client.new(
|
9
|
+
:first_name => 'Test',
|
10
|
+
:last_name => 'Test',
|
11
|
+
:email => 'test@test.com',
|
12
|
+
:organization => 'FlatsourcingTest'
|
13
|
+
)
|
14
|
+
@client.create
|
15
|
+
|
16
|
+
@task = FreshBooks::Task.new(
|
17
|
+
:name => 'Test'
|
18
|
+
)
|
19
|
+
@task.create
|
20
|
+
|
21
|
+
@project = FreshBooks::Project.new(
|
22
|
+
:client_id => @client.client_id,
|
23
|
+
:name => 'Test',
|
24
|
+
:bill_method => 'task-rate',
|
25
|
+
:tasks => [@task]
|
26
|
+
)
|
27
|
+
@project.create
|
28
|
+
|
29
|
+
@staff = FreshBooks::Staff.list[0]
|
30
|
+
end
|
31
|
+
|
32
|
+
after(:all) do
|
33
|
+
@task.delete
|
34
|
+
@project.delete
|
35
|
+
@client.delete
|
36
|
+
end
|
37
|
+
|
38
|
+
before(:each) do
|
39
|
+
@attributes = {
|
40
|
+
:project_id => @project.project_id,
|
41
|
+
:task_id => @task.task_id,
|
42
|
+
:hours => 1
|
43
|
+
}
|
44
|
+
@time_entry = FreshBooks::TimeEntry.new(@attributes)
|
45
|
+
@time_entry.create
|
46
|
+
end
|
47
|
+
|
48
|
+
after(:each) do
|
49
|
+
@time_entry.delete rescue nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should list all time_entries" do
|
53
|
+
FreshBooks::TimeEntry.list.size.should > 0
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should find time_entry by id" do
|
57
|
+
time_entry = FreshBooks::TimeEntry.get(@time_entry.time_entry_id)
|
58
|
+
time_entry.should_not be_nil
|
59
|
+
@attributes.each do |field, value|
|
60
|
+
time_entry.send(field).should == @time_entry.send(field)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should create a new time_entry" do
|
65
|
+
time_entries = FreshBooks::TimeEntry.list
|
66
|
+
|
67
|
+
time_entry = FreshBooks::TimeEntry.new(@attributes)
|
68
|
+
time_entry.create.should_not be_nil
|
69
|
+
|
70
|
+
FreshBooks::TimeEntry.list.size.should == time_entries.size + 1
|
71
|
+
|
72
|
+
time_entry.delete rescue nil
|
73
|
+
end
|
74
|
+
|
75
|
+
# it "should update an existing time_entry" do
|
76
|
+
# time_entries = FreshBooks::TimeEntry.list
|
77
|
+
# @time_entry.hours = 2
|
78
|
+
# @time_entry.update rescue nil
|
79
|
+
# FreshBooks::TimeEntry.get(@time_entry.time_entry_id).hours.should == 2
|
80
|
+
# FreshBooks::TimeEntry.list.size.should == time_entries.size
|
81
|
+
# end
|
82
|
+
|
83
|
+
it "should delete time_entry" do
|
84
|
+
time_entries = FreshBooks::TimeEntry.list
|
85
|
+
@time_entry.delete rescue nil
|
86
|
+
FreshBooks::TimeEntry.list.size.should == time_entries.size - 1
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should delete time_entry by id" do
|
90
|
+
time_entries = FreshBooks::TimeEntry.list
|
91
|
+
FreshBooks::TimeEntry.delete(@time_entry.time_entry_id) rescue nil
|
92
|
+
FreshBooks::TimeEntry.list.size.should == time_entries.size - 1
|
93
|
+
end
|
94
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
gem 'rspec'
|
6
|
+
require 'spec'
|
7
|
+
end
|
8
|
+
|
9
|
+
require File.dirname(__FILE__) + '/../lib/freshbooks.rb'
|
10
|
+
|
11
|
+
FreshBooks::Base.setup('flatsourcingtest.freshbooks.com', 'dd4d8a3c9a8541161e6409df207fad84')
|
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
+
end
|
22
|
+
|
23
|
+
namespace :spec do
|
24
|
+
desc "Run all specs in spec directory with RCov (excluding plugin specs)"
|
25
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
26
|
+
t.spec_opts = ['--options', '"spec/spec.opts"']
|
27
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
28
|
+
t.rcov = true
|
29
|
+
t.rcov_opts = lambda do
|
30
|
+
IO.readlines('spec/rcov.opts').map {|l| l.chomp.split " "}.flatten
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|