freeagent 0.1.0
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/.gitignore +19 -0
- data/.rspec +1 -0
- data/CHANGELOG.rdoc +6 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +50 -0
- data/LICENSE +22 -0
- data/README.rdoc +27 -0
- data/Rakefile +28 -0
- data/freeagent.gemspec +27 -0
- data/lib/free_agent.rb +64 -0
- data/lib/free_agent/attachment.rb +21 -0
- data/lib/free_agent/bank_account.rb +7 -0
- data/lib/free_agent/base.rb +6 -0
- data/lib/free_agent/bill.rb +15 -0
- data/lib/free_agent/contact.rb +7 -0
- data/lib/free_agent/invoice.rb +7 -0
- data/lib/free_agent/invoice_item.rb +10 -0
- data/lib/free_agent/project.rb +7 -0
- data/lib/free_agent/version.rb +16 -0
- data/lib/freeagent.rb +1 -0
- data/spec/fixtures/attachments/all.xml +23 -0
- data/spec/fixtures/attachments/single.xml +11 -0
- data/spec/fixtures/bank_accounts/all.xml +35 -0
- data/spec/fixtures/bank_accounts/single.xml +15 -0
- data/spec/fixtures/bills/all.xml +37 -0
- data/spec/fixtures/bills/single.xml +18 -0
- data/spec/fixtures/contacts/all.xml +47 -0
- data/spec/fixtures/contacts/single.xml +23 -0
- data/spec/fixtures/invoice_items/all.xml +15 -0
- data/spec/fixtures/invoice_items/single.xml +13 -0
- data/spec/fixtures/invoices/all.xml +75 -0
- data/spec/fixtures/invoices/single.xml +37 -0
- data/spec/fixtures/projects/all.xml +25 -0
- data/spec/fixtures/projects/single.xml +23 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/support/helper.rb +18 -0
- data/spec/support/mimic.rb +47 -0
- data/spec/unit/attachment_spec.rb +56 -0
- data/spec/unit/bank_account_spec.rb +56 -0
- data/spec/unit/base_spec.rb +9 -0
- data/spec/unit/bill_spec.rb +66 -0
- data/spec/unit/contact_spec.rb +56 -0
- data/spec/unit/freeagent_spec.rb +54 -0
- data/spec/unit/invoice_item_spec.rb +77 -0
- data/spec/unit/invoice_spec.rb +56 -0
- data/spec/unit/project_spec.rb +56 -0
- metadata +169 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FreeAgent::Attachment do
|
4
|
+
|
5
|
+
it "extends FreeAgent::Base" do
|
6
|
+
klass.superclass.should == FreeAgent::Base
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "paths" do
|
10
|
+
it "has correct collection path" do
|
11
|
+
FreeAgent::Attachment.collection_path.should == '/attachments.xml'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has correct element path" do
|
15
|
+
FreeAgent::Attachment.element_path(:first).should == '/attachments/first.xml'
|
16
|
+
FreeAgent::Attachment.element_path(100000).should == '/attachments/100000.xml'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
describe ".all" do
|
22
|
+
before(:each) do
|
23
|
+
@attachments = FreeAgent::Attachment.all
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns an array" do
|
27
|
+
@attachments.should be_a(Array)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns the attachments" do
|
31
|
+
@attachments.should have(2).records
|
32
|
+
@attachments.first.should be_a(FreeAgent::Attachment)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".find(id)" do
|
37
|
+
context "when the record exists" do
|
38
|
+
before(:each) do
|
39
|
+
@attachment = FreeAgent::Attachment.find(2)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns an attachment" do
|
43
|
+
@attachment.should be_a(FreeAgent::Attachment)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when the record does not exist" do
|
48
|
+
it "raises a ResourceNotFound error" do
|
49
|
+
lambda do
|
50
|
+
FreeAgent::Attachment.find(1)
|
51
|
+
end.should raise_error(ActiveResource::ResourceNotFound)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FreeAgent::BankAccount do
|
4
|
+
|
5
|
+
it "extends FreeAgent::Base" do
|
6
|
+
klass.superclass.should == FreeAgent::Base
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "paths" do
|
10
|
+
it "has correct collection path" do
|
11
|
+
FreeAgent::BankAccount.collection_path.should == '/bank_accounts.xml'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has correct element path" do
|
15
|
+
FreeAgent::BankAccount.element_path(:first).should == '/bank_accounts/first.xml'
|
16
|
+
FreeAgent::BankAccount.element_path(100000).should == '/bank_accounts/100000.xml'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
describe ".all" do
|
22
|
+
before(:each) do
|
23
|
+
@bank_accounts = FreeAgent::BankAccount.all
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns an array" do
|
27
|
+
@bank_accounts.should be_a(Array)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns the bank accounts" do
|
31
|
+
@bank_accounts.should have(3).records
|
32
|
+
@bank_accounts.first.should be_a(FreeAgent::BankAccount)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".find(id)" do
|
37
|
+
context "when the record exists" do
|
38
|
+
before(:each) do
|
39
|
+
@bank_account = FreeAgent::BankAccount.find(2)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns a bank account" do
|
43
|
+
@bank_account.should be_a(FreeAgent::BankAccount)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when the record does not exist" do
|
48
|
+
it "raises a ResourceNotFound error" do
|
49
|
+
lambda do
|
50
|
+
FreeAgent::BankAccount.find(1)
|
51
|
+
end.should raise_error(ActiveResource::ResourceNotFound)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FreeAgent::Bill do
|
4
|
+
|
5
|
+
it "extends FreeAgent::Base" do
|
6
|
+
klass.superclass.should == FreeAgent::Base
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "paths" do
|
10
|
+
it "has correct collection path" do
|
11
|
+
FreeAgent::Bill.collection_path.should == '/bills.xml'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has correct element path" do
|
15
|
+
FreeAgent::Bill.element_path(:first).should == '/bills/first.xml'
|
16
|
+
FreeAgent::Bill.element_path(100000).should == '/bills/100000.xml'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
describe ".all" do
|
22
|
+
context "without period parameter" do
|
23
|
+
it "raises a BadRequest error" do
|
24
|
+
lambda do
|
25
|
+
FreeAgent::Bill.all
|
26
|
+
end.should raise_error(ActiveResource::BadRequest)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "with period parameter" do
|
31
|
+
before(:each) do
|
32
|
+
@bills = FreeAgent::Bill.all(:params => { :period => '2011-01-01_2011-12-31' })
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns an array" do
|
36
|
+
@bills.should be_a(Array)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns the bills" do
|
40
|
+
@bills.should have(2).records
|
41
|
+
@bills.first.should be_a(FreeAgent::Bill)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe ".find(id)" do
|
47
|
+
context "when the record exists" do
|
48
|
+
before(:each) do
|
49
|
+
@bill = FreeAgent::Bill.find(2)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns a bill" do
|
53
|
+
@bill.should be_a(FreeAgent::Bill)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when the record does not exist" do
|
58
|
+
it "raises a ResourceNotFound error" do
|
59
|
+
lambda do
|
60
|
+
FreeAgent::Bill.find(1)
|
61
|
+
end.should raise_error(ActiveResource::ResourceNotFound)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FreeAgent::Contact do
|
4
|
+
|
5
|
+
it "extends FreeAgent::Base" do
|
6
|
+
klass.superclass.should == FreeAgent::Base
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "paths" do
|
10
|
+
it "has correct collection path" do
|
11
|
+
FreeAgent::Contact.collection_path.should == '/contacts.xml'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has correct element path" do
|
15
|
+
FreeAgent::Contact.element_path(:first).should == '/contacts/first.xml'
|
16
|
+
FreeAgent::Contact.element_path(100000).should == '/contacts/100000.xml'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
describe ".all" do
|
22
|
+
before(:each) do
|
23
|
+
@contacts = FreeAgent::Contact.all
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns an array" do
|
27
|
+
@contacts.should be_a(Array)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns the contacts" do
|
31
|
+
@contacts.should have(2).records
|
32
|
+
@contacts.first.should be_a(FreeAgent::Contact)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".find(id)" do
|
37
|
+
context "when the record exists" do
|
38
|
+
before(:each) do
|
39
|
+
@contacts = FreeAgent::Contact.find(2)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns a contact" do
|
43
|
+
@contacts.should be_a(FreeAgent::Contact)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when the record does not exist" do
|
48
|
+
it "raises a ResourceNotFound error" do
|
49
|
+
lambda do
|
50
|
+
FreeAgent::Contact.find(1)
|
51
|
+
end.should raise_error(ActiveResource::ResourceNotFound)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FreeAgent do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
FreeAgent::Base.tap do |base|
|
7
|
+
base.site = base.user = base.password = nil
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ".configured?" do
|
12
|
+
it "returns true when Base.user, Base.password, Base.site are configured" do
|
13
|
+
klass.configured?.should be_false
|
14
|
+
|
15
|
+
klass.username = "email@example.com"
|
16
|
+
klass.configured?.should be_false
|
17
|
+
|
18
|
+
klass.password = "letmein"
|
19
|
+
klass.configured?.should be_false
|
20
|
+
|
21
|
+
klass.subdomain = "example"
|
22
|
+
klass.configured?.should be_true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe ".configure" do
|
27
|
+
context "without block" do
|
28
|
+
it "raises LocalJumpError" do
|
29
|
+
lambda do
|
30
|
+
klass.configure
|
31
|
+
end.should raise_error(LocalJumpError)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with block" do
|
36
|
+
it "yields self" do
|
37
|
+
klass.configure do |config|
|
38
|
+
config.should be(klass)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "implements the configuration pattern" do
|
43
|
+
klass.configured?.should be_false
|
44
|
+
klass.configure do |config|
|
45
|
+
config.username = "email@example.com"
|
46
|
+
config.password = "letmein"
|
47
|
+
config.subdomain = "example"
|
48
|
+
end
|
49
|
+
klass.configured?.should be_true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FreeAgent::InvoiceItem do
|
4
|
+
|
5
|
+
it "extends FreeAgent::Base" do
|
6
|
+
klass.superclass.should == FreeAgent::Base
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "paths" do
|
10
|
+
it "has correct collection path" do
|
11
|
+
FreeAgent::InvoiceItem.collection_path(:invoice_id => 1).should == '/invoices/1/invoice_items.xml'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has correct element path" do
|
15
|
+
FreeAgent::InvoiceItem.element_path(:first, :invoice_id => 1).should == '/invoices/1/invoice_items/first.xml'
|
16
|
+
FreeAgent::InvoiceItem.element_path(100000, :invoice_id => 1).should == '/invoices/1/invoice_items/100000.xml'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
context "when the invoice exists" do
|
22
|
+
describe ".all" do
|
23
|
+
before(:each) do
|
24
|
+
@invoice_items = FreeAgent::InvoiceItem.all(:params => { :invoice_id => 2 })
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns an array" do
|
28
|
+
@invoice_items.should be_a(Array)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns the invoice items" do
|
32
|
+
@invoice_items.should have(1).records
|
33
|
+
@invoice_items.first.should be_a(FreeAgent::InvoiceItem)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe ".find(id)" do
|
38
|
+
context "when the record exists" do
|
39
|
+
before(:each) do
|
40
|
+
@invoice_item = FreeAgent::InvoiceItem.find(2, :params => { :invoice_id => 2 })
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns an invoice" do
|
44
|
+
@invoice_item.should be_a(FreeAgent::InvoiceItem)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when the record does not exist" do
|
49
|
+
it "raises a ResourceNotFound error" do
|
50
|
+
lambda do
|
51
|
+
FreeAgent::InvoiceItem.find(1, :params => { :invoice_id => 2 })
|
52
|
+
end.should raise_error(ActiveResource::ResourceNotFound)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when the invoice does not exist" do
|
59
|
+
describe ".all" do
|
60
|
+
it "raises a ResourceNotFound error" do
|
61
|
+
pending 'ActiveResource returns nil'
|
62
|
+
lambda do
|
63
|
+
FreeAgent::InvoiceItem.all(:params => { :invoice_id => 1 })
|
64
|
+
end.should raise_error(ActiveResource::ResourceNotFound)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe ".find(id)" do
|
69
|
+
it "raises a ResourceNotFound error" do
|
70
|
+
lambda do
|
71
|
+
FreeAgent::InvoiceItem.find(1, :params => { :invoice_id => 1 })
|
72
|
+
end.should raise_error(ActiveResource::ResourceNotFound)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FreeAgent::Invoice do
|
4
|
+
|
5
|
+
it "extends FreeAgent::Base" do
|
6
|
+
klass.superclass.should == FreeAgent::Base
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "paths" do
|
10
|
+
it "has correct collection path" do
|
11
|
+
FreeAgent::Invoice.collection_path.should == '/invoices.xml'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has correct element path" do
|
15
|
+
FreeAgent::Invoice.element_path(:first).should == '/invoices/first.xml'
|
16
|
+
FreeAgent::Invoice.element_path(100000).should == '/invoices/100000.xml'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
describe ".all" do
|
22
|
+
before(:each) do
|
23
|
+
@invoices = FreeAgent::Invoice.all
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns an array" do
|
27
|
+
@invoices.should be_a(Array)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns the invoices" do
|
31
|
+
@invoices.should have(2).records
|
32
|
+
@invoices.first.should be_a(FreeAgent::Invoice)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".find(id)" do
|
37
|
+
context "when the record exists" do
|
38
|
+
before(:each) do
|
39
|
+
@invoice = FreeAgent::Invoice.find(2)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns an invoice" do
|
43
|
+
@invoice.should be_a(FreeAgent::Invoice)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when the record does not exist" do
|
48
|
+
it "raises a ResourceNotFound error" do
|
49
|
+
lambda do
|
50
|
+
FreeAgent::Invoice.find(1)
|
51
|
+
end.should raise_error(ActiveResource::ResourceNotFound)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FreeAgent::Project do
|
4
|
+
|
5
|
+
it "extends FreeAgent::Base" do
|
6
|
+
klass.superclass.should == FreeAgent::Base
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "paths" do
|
10
|
+
it "has correct collection path" do
|
11
|
+
FreeAgent::Project.collection_path.should == '/projects.xml'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has correct element path" do
|
15
|
+
FreeAgent::Project.element_path(:first).should == '/projects/first.xml'
|
16
|
+
FreeAgent::Project.element_path(100000).should == '/projects/100000.xml'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
describe ".all" do
|
22
|
+
before(:each) do
|
23
|
+
@projects = FreeAgent::Project.all
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns an array" do
|
27
|
+
@projects.should be_a(Array)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns the projects" do
|
31
|
+
@projects.should have(1).records
|
32
|
+
@projects.first.should be_a(FreeAgent::Project)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".find(id)" do
|
37
|
+
context "when the record exists" do
|
38
|
+
before(:each) do
|
39
|
+
@project = FreeAgent::Project.find(2)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns a project" do
|
43
|
+
@project.should be_a(FreeAgent::Project)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when the record does not exist" do
|
48
|
+
it "raises a ResourceNotFound error" do
|
49
|
+
lambda do
|
50
|
+
FreeAgent::Project.find(1)
|
51
|
+
end.should raise_error(ActiveResource::ResourceNotFound)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|