cashboard 1.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.
Files changed (62) hide show
  1. data/.autotest +26 -0
  2. data/.gitignore +2 -0
  3. data/LICENSE +19 -0
  4. data/README.textile +58 -0
  5. data/Rakefile +25 -0
  6. data/cashboard.gemspec +129 -0
  7. data/examples/create_account.rb +38 -0
  8. data/examples/list_stuff_in_account.rb +15 -0
  9. data/examples/simple_workflow.rb +35 -0
  10. data/examples/time_tracking.rb +30 -0
  11. data/examples/toggle_timer.rb +0 -0
  12. data/lib/cashboard/account.rb +21 -0
  13. data/lib/cashboard/base.rb +223 -0
  14. data/lib/cashboard/behaviors/base.rb +4 -0
  15. data/lib/cashboard/behaviors/lists_line_items.rb +32 -0
  16. data/lib/cashboard/behaviors/toggleable.rb +18 -0
  17. data/lib/cashboard/client_company.rb +25 -0
  18. data/lib/cashboard/client_contact.rb +32 -0
  19. data/lib/cashboard/company_membership.rb +6 -0
  20. data/lib/cashboard/document_template.rb +10 -0
  21. data/lib/cashboard/employee.rb +29 -0
  22. data/lib/cashboard/errors.rb +48 -0
  23. data/lib/cashboard/estimate.rb +43 -0
  24. data/lib/cashboard/expense.rb +14 -0
  25. data/lib/cashboard/invoice.rb +75 -0
  26. data/lib/cashboard/invoice_line_item.rb +15 -0
  27. data/lib/cashboard/invoice_payment.rb +7 -0
  28. data/lib/cashboard/line_item.rb +27 -0
  29. data/lib/cashboard/payment.rb +22 -0
  30. data/lib/cashboard/project.rb +38 -0
  31. data/lib/cashboard/project_assignment.rb +9 -0
  32. data/lib/cashboard/time_entry.rb +45 -0
  33. data/lib/cashboard/version.rb +3 -0
  34. data/lib/cashboard.rb +75 -0
  35. data/lib/typecasted_open_struct.rb +82 -0
  36. data/test/fixtures/account.xml +50 -0
  37. data/test/fixtures/cashboard_credentials.yml +3 -0
  38. data/test/fixtures/client_companies.xml +41 -0
  39. data/test/fixtures/client_contacts.xml +53 -0
  40. data/test/fixtures/company_memberships.xml +21 -0
  41. data/test/fixtures/document_templates.xml +53 -0
  42. data/test/fixtures/employees.xml +51 -0
  43. data/test/fixtures/estimates.xml +243 -0
  44. data/test/fixtures/expenses.xml +101 -0
  45. data/test/fixtures/invoice_line_items.xml +138 -0
  46. data/test/fixtures/invoice_payments.xml +10 -0
  47. data/test/fixtures/invoices.xml +231 -0
  48. data/test/fixtures/line_items.xml +243 -0
  49. data/test/fixtures/payments.xml +93 -0
  50. data/test/fixtures/project_assignments.xml +30 -0
  51. data/test/fixtures/projects.xml +129 -0
  52. data/test/fixtures/time_entries.xml +213 -0
  53. data/test/full.rb +3 -0
  54. data/test/test_helper.rb +112 -0
  55. data/test/unit/account_test.rb +85 -0
  56. data/test/unit/document_template_test.rb +18 -0
  57. data/test/unit/estimate_test.rb +166 -0
  58. data/test/unit/expense_test.rb +16 -0
  59. data/test/unit/invoice_test.rb +185 -0
  60. data/test/unit/project_test.rb +198 -0
  61. data/test/unit/time_entry_test.rb +225 -0
  62. metadata +220 -0
@@ -0,0 +1,85 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class AccountTest < Test::Unit::TestCase
4
+
5
+ def test_create_success
6
+ FakeWeb.register_uri(
7
+ :post,
8
+ url_with_auth("/#{Cashboard::Account.resource_name}"),
9
+ :status => ["201", "Created"],
10
+ :body => get_xml_for_fixture('account')
11
+ ) if MOCK_WEB_CONNECTIONS
12
+
13
+ acct = Cashboard::Account.create({
14
+ :subdomain => generate_random_string,
15
+ :currency_type => 'USD',
16
+ :date_format => 'mm_dd_yyyy',
17
+ :owner => {
18
+ :email_address => 'rza@wutang.com',
19
+ :first_name => 'The',
20
+ :last_name => 'Rza',
21
+ :password => '36chambers'
22
+ },
23
+ :company => {
24
+ :name => 'Wu Tang',
25
+ :address => '1 Shogun Way',
26
+ :city => 'Shaolin',
27
+ :state => 'NY'
28
+ }
29
+ })
30
+
31
+ assert_kind_of Cashboard::Struct, acct.owner
32
+ assert_kind_of Cashboard::Struct, acct.company
33
+
34
+ assert !acct.owner.api_key.blank?
35
+ end
36
+
37
+ def test_create_fail
38
+ FakeWeb.register_uri(
39
+ :post,
40
+ url_with_auth("/#{Cashboard::Account.resource_name}"),
41
+ :status => ["400", "Bad Request"],
42
+ :body => GENERIC_ERROR_XML
43
+ ) if MOCK_WEB_CONNECTIONS
44
+
45
+ assert_raises Cashboard::BadRequest do
46
+ Cashboard::Account.create()
47
+ end
48
+ end
49
+
50
+ def test_update_success
51
+ acct = Cashboard::Account.new_from_url('/account')
52
+
53
+ FakeWeb.register_uri(
54
+ :put,
55
+ url_with_auth("/#{Cashboard::Account.resource_name}"),
56
+ :status => ["200", "Ok"],
57
+ :body => get_xml_for_fixture('account')
58
+ ) if MOCK_WEB_CONNECTIONS
59
+
60
+ acct.date_format = 'yyyy_mm_dd'
61
+ assert acct.update, "Account didn't save properly"
62
+ end
63
+
64
+ def test_update_fail
65
+ acct = Cashboard::Account.new_from_url('/account')
66
+
67
+ FakeWeb.register_uri(
68
+ :put,
69
+ url_with_auth("/#{Cashboard::Account.resource_name}"),
70
+ :status => ["400", "Bad Request"],
71
+ :body => GENERIC_ERROR_XML
72
+ ) if MOCK_WEB_CONNECTIONS
73
+
74
+ acct.subdomain = ''
75
+ assert !acct.update, "Account shouldn't have saved with blank subdomain"
76
+ end
77
+
78
+ def test_new_from_url
79
+ acct = Cashboard::Account.new_from_url('/account')
80
+ assert_kind_of Cashboard::Account, acct
81
+ assert_kind_of Cashboard::Struct, acct.owner
82
+ assert_kind_of Cashboard::Struct, acct.company
83
+ end
84
+
85
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class DocumentTemplateTest < Test::Unit::TestCase
4
+
5
+ def test_list
6
+ templates = Cashboard::DocumentTemplate.list
7
+ assert templates.size > 0
8
+ templates.each do |dt|
9
+ assert_kind_of Cashboard::DocumentTemplate, dt
10
+ end
11
+ end
12
+
13
+ def test_href
14
+ tmpl = Cashboard::DocumentTemplate.list[0]
15
+ assert_kind_of String, tmpl.href
16
+ end
17
+
18
+ end
@@ -0,0 +1,166 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class EstimateTest < Test::Unit::TestCase
4
+
5
+ # CUSTOM ASSERTIONS ---------------------------------------------------------
6
+
7
+ def assert_list_type(method, type)
8
+ mock_sub_resource(
9
+ Cashboard::Estimate.resource_name,
10
+ 'line_items',
11
+ 'line_items'
12
+ ) if MOCK_WEB_CONNECTIONS
13
+
14
+ est = Cashboard::Estimate.list[0]
15
+ collection = est.send(method)
16
+ assert collection.size > 0
17
+ collection.each do |item|
18
+ assert_kind_of Cashboard::LineItem, item
19
+ assert_equal Cashboard::LineItem::TYPE_CODES[type], item.type_code.to_i
20
+ end
21
+ end
22
+
23
+
24
+ # TESTS ---------------------------------------------------------------------
25
+
26
+ def test_list
27
+ estimates = Cashboard::Estimate.list
28
+ assert estimates.size > 0
29
+ estimates.each do |est|
30
+ assert_kind_of Cashboard::Estimate, est
31
+ end
32
+ end
33
+
34
+ def test_create
35
+ FakeWeb.register_uri(
36
+ :post,
37
+ url_with_auth("/#{Cashboard::Estimate.resource_name}"),
38
+ :status => ["201", "Created"],
39
+ :body => Cashboard::Estimate.list[0].to_xml
40
+ ) if MOCK_WEB_CONNECTIONS
41
+
42
+ client = Cashboard::ClientCompany.list[0]
43
+
44
+ # Create random estimate name so even if not destroyed on
45
+ # a live connection we don't run into duplicate name validation errors.
46
+ est_name = "Test estimate - " + generate_random_string
47
+ assert_nothing_raised do
48
+ estimate = Cashboard::Estimate.create(
49
+ :name => est_name,
50
+ :client_id => client.id,
51
+ :client_type => 'Company'
52
+ )
53
+ end
54
+ end
55
+
56
+ def test_update_success
57
+ est = Cashboard::Estimate.list[0]
58
+
59
+ FakeWeb.register_uri(
60
+ :put,
61
+ url_with_auth(est.href),
62
+ :status => ["200", "Ok"],
63
+ :body => est.to_xml
64
+ ) if MOCK_WEB_CONNECTIONS
65
+
66
+ est.name = 'Some new name'
67
+ assert est.update, "Estimate didn't save properly"
68
+ end
69
+
70
+ def test_update_fail
71
+ est = Cashboard::Estimate.list[0]
72
+
73
+ FakeWeb.register_uri(
74
+ :put,
75
+ url_with_auth(est.href),
76
+ :status => ["400", "Bad Request"],
77
+ :body => GENERIC_ERROR_XML
78
+ ) if MOCK_WEB_CONNECTIONS
79
+
80
+ est.name = 'Some new name'
81
+ assert !est.update, "Estimate saved when it shouldn't have"
82
+ end
83
+
84
+ def test_delete_success
85
+ est = Cashboard::Estimate.list[0]
86
+
87
+ FakeWeb.register_uri(
88
+ :delete,
89
+ url_with_auth(est.href),
90
+ :status => ["200", "Ok"]
91
+ ) if MOCK_WEB_CONNECTIONS
92
+
93
+ assert est.delete, "Estimate wasn't deleted."
94
+ end
95
+
96
+ def test_delete_fail
97
+ est = Cashboard::Estimate.list[0]
98
+
99
+ FakeWeb.register_uri(
100
+ :delete,
101
+ url_with_auth(est.href),
102
+ :status => ["404", "Not found"]
103
+ ) if MOCK_WEB_CONNECTIONS
104
+
105
+ assert !est.delete, "Estimate was deleted when it shouldn't have been."
106
+ end
107
+
108
+ def test_toggle_status_success
109
+ est = Cashboard::Estimate.list[0]
110
+ assert_equal false, est.is_active
111
+
112
+ FakeWeb.register_uri(
113
+ :put,
114
+ url_with_auth(est.links[:toggle_status]),
115
+ :status => ["200", "Ok"]
116
+ ) if MOCK_WEB_CONNECTIONS
117
+
118
+ initial_status = est.is_active
119
+
120
+ assert est.toggle_status
121
+ assert true, est.is_active
122
+ end
123
+
124
+ def test_toggle_status_failure
125
+ est = Cashboard::Estimate.list[0]
126
+
127
+ FakeWeb.register_uri(
128
+ :put,
129
+ url_with_auth(est.links[:toggle_status]),
130
+ :status => ["401", "Unauthorized"]
131
+ ) if MOCK_WEB_CONNECTIONS
132
+
133
+ initial_status = est.is_active
134
+
135
+ assert !est.toggle_status
136
+ assert est.is_active == initial_status
137
+ end
138
+
139
+ def test_line_items
140
+ mock_sub_resource(
141
+ Cashboard::Project.resource_name,
142
+ 'line_items',
143
+ 'line_items'
144
+ ) if MOCK_WEB_CONNECTIONS
145
+
146
+ est = Cashboard::Estimate.list[0]
147
+ line_items = est.line_items
148
+ assert line_items.size > 0
149
+ line_items.each do |li|
150
+ assert_kind_of Cashboard::LineItem, li
151
+ end
152
+ end
153
+
154
+ def test_tasks
155
+ assert_list_type :tasks, :task
156
+ end
157
+
158
+ def test_products
159
+ assert_list_type :products, :product
160
+ end
161
+
162
+ def test_custom_items
163
+ assert_list_type :custom_items, :custom
164
+ end
165
+
166
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class ExpenseTest < Test::Unit::TestCase
4
+
5
+ def test_list
6
+ expenses = Cashboard::Expense.list
7
+ assert expenses.size > 0
8
+ expenses.each do |exp|
9
+ assert_kind_of Cashboard::Expense, exp
10
+ assert_kind_of DateTime, exp.created_on
11
+ assert_kind_of Float, exp.amount
12
+ assert exp.is_billable.class == TrueClass || exp.is_billable.class == FalseClass
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,185 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class InvoiceTest < Test::Unit::TestCase
4
+
5
+ def test_list
6
+ invoices = Cashboard::Invoice.list
7
+ assert invoices.size > 0
8
+ invoices.each do |inv|
9
+ assert_kind_of Cashboard::Invoice, inv
10
+ end
11
+ end
12
+
13
+ def test_create_success
14
+ FakeWeb.register_uri(
15
+ :post,
16
+ url_with_auth("/#{Cashboard::Invoice.resource_name}"),
17
+ :status => ["201", "Created"],
18
+ :body => Cashboard::Invoice.list[0].to_xml
19
+ ) if MOCK_WEB_CONNECTIONS
20
+
21
+ client = Cashboard::ClientCompany.list[0]
22
+
23
+ assert_nothing_raised do
24
+ inv = Cashboard::Invoice.create(
25
+ :client_id => client.id,
26
+ :client_type => 'Company'
27
+ )
28
+ assert_kind_of Cashboard::Invoice, inv
29
+ end
30
+ end
31
+
32
+ def test_create_fail
33
+ FakeWeb.register_uri(
34
+ :post,
35
+ url_with_auth("/#{Cashboard::Project.resource_name}"),
36
+ :status => ["400", "Bad Request"],
37
+ :body => GENERIC_ERROR_XML
38
+ ) if MOCK_WEB_CONNECTIONS
39
+
40
+ assert_raise Cashboard::BadRequest do
41
+ prj = Cashboard::Project.create()
42
+ end
43
+ end
44
+
45
+ def test_update_success
46
+ inv = Cashboard::Invoice.list[0]
47
+
48
+ FakeWeb.register_uri(
49
+ :put,
50
+ url_with_auth(inv.href),
51
+ :status => ["200", "Ok"],
52
+ :body => inv.to_xml
53
+ ) if MOCK_WEB_CONNECTIONS
54
+
55
+ inv.created_on = Date.today
56
+ inv.due_date = Date.today + 1.week
57
+ assert inv.update, "Invoice didn't save properly"
58
+ end
59
+
60
+ def test_update_fail
61
+ inv = Cashboard::Invoice.list[0]
62
+
63
+ FakeWeb.register_uri(
64
+ :put,
65
+ url_with_auth(inv.href),
66
+ :status => ["400", "Bad Request"],
67
+ :body => GENERIC_ERROR_XML
68
+ ) if MOCK_WEB_CONNECTIONS
69
+
70
+ inv.client_id = nil
71
+ assert !inv.update, "Invoice saved when it shouldn't have"
72
+ end
73
+
74
+ def test_delete_success
75
+ inv = Cashboard::Invoice.list[0]
76
+
77
+ FakeWeb.register_uri(
78
+ :delete,
79
+ url_with_auth(inv.href),
80
+ :status => ["200", "Ok"]
81
+ ) if MOCK_WEB_CONNECTIONS
82
+
83
+ assert inv.delete, "Invoice wasn't deleted."
84
+ end
85
+
86
+ def test_delete_fail
87
+ inv = Cashboard::Invoice.list[0]
88
+
89
+ FakeWeb.register_uri(
90
+ :delete,
91
+ url_with_auth(inv.href),
92
+ :status => ["404", "Not found"]
93
+ ) if MOCK_WEB_CONNECTIONS
94
+
95
+ assert !inv.delete, "Invoice was deleted when it shouldn't have been."
96
+ end
97
+
98
+ def test_line_items
99
+ mock_sub_resource(
100
+ Cashboard::Invoice.resource_name,
101
+ 'line_items',
102
+ 'invoice_line_items'
103
+ ) if MOCK_WEB_CONNECTIONS
104
+
105
+ inv = Cashboard::Invoice.list[0]
106
+
107
+ line_items = inv.line_items
108
+ assert line_items.size > 0
109
+
110
+ line_items.each do |li|
111
+ assert_kind_of Cashboard::InvoiceLineItem, li
112
+ end
113
+ end
114
+
115
+ def mock_import_items_response
116
+ FakeWeb.register_uri(
117
+ :put,
118
+ get_sub_url_regexp(Cashboard::Invoice.resource_name, 'import_uninvoiced_items'),
119
+ :body => get_xml_for_fixture('invoice_line_items'),
120
+ :status => ['200', 'OK']
121
+ ) if MOCK_WEB_CONNECTIONS
122
+ end
123
+
124
+ def test_import_uninvoiced_items_no_options
125
+ mock_import_items_response
126
+ inv = Cashboard::Invoice.list[0]
127
+
128
+ assert_nothing_raised do
129
+ items = inv.import_uninvoiced_items
130
+ assert items.size > 0
131
+ items.each do |li|
132
+ assert_kind_of Cashboard::InvoiceLineItem, li
133
+ end
134
+ end
135
+ end
136
+
137
+ def test_import_uninvoiced_items_with_projects
138
+ mock_import_items_response
139
+ inv = Cashboard::Invoice.list[0]
140
+
141
+ inv.expects(:get_import_xml_options).with([12345], nil, nil)
142
+
143
+ inv.import_uninvoiced_items([12345])
144
+ end
145
+
146
+ def test_get_import_xml_options_project_id
147
+ xml_options = %Q\
148
+ <?xml version="1.0" encoding="UTF-8"?>
149
+ <projects>
150
+ <id>12345</id>
151
+ </projects>
152
+ <start_date></start_date>
153
+ <end_date></end_date>
154
+ \
155
+ inv = Cashboard::Invoice.list[0]
156
+
157
+ opts = inv.get_import_xml_options([12345], nil, nil)
158
+
159
+ assert_equal(
160
+ xml_options.gsub(/\s/, ''),
161
+ opts.gsub(/\s/, '')
162
+ )
163
+ end
164
+
165
+ def test_get_import_xml_options_start_end_date
166
+ d1 = Date.today-1.week
167
+ d2 = Date.today
168
+ xml_options = %Q\
169
+ <?xml version="1.0" encoding="UTF-8"?>
170
+ <projects>
171
+ </projects>
172
+ <start_date>#{d1.to_s}</start_date>
173
+ <end_date>#{d2.to_s}</end_date>
174
+ \
175
+ inv = Cashboard::Invoice.list[0]
176
+
177
+ opts = inv.get_import_xml_options(nil, d1, d2)
178
+
179
+ assert_equal(
180
+ xml_options.gsub(/\s/, ''),
181
+ opts.gsub(/\s/, '')
182
+ )
183
+ end
184
+
185
+ end
@@ -0,0 +1,198 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class ProjectTest < Test::Unit::TestCase
4
+
5
+ # CUSTOM ASSERTIONS ---------------------------------------------------------
6
+
7
+ def assert_list_type(method, type)
8
+ mock_sub_resource(
9
+ Cashboard::Project.resource_name,
10
+ 'line_items',
11
+ 'line_items'
12
+ ) if MOCK_WEB_CONNECTIONS
13
+
14
+ prj = Cashboard::Project.list[0]
15
+ collection = prj.send(method)
16
+ assert collection.size > 0
17
+ collection.each do |item|
18
+ assert_kind_of Cashboard::LineItem, item
19
+ assert_equal Cashboard::LineItem::TYPE_CODES[type], item.type_code.to_i
20
+ end
21
+ end
22
+
23
+
24
+ # TESTS ---------------------------------------------------------------------
25
+
26
+ def test_list
27
+ projects = Cashboard::Project.list
28
+ assert projects.size > 0
29
+ projects.each do |prj|
30
+ assert_kind_of Cashboard::Project, prj
31
+ end
32
+ end
33
+
34
+ def test_create_success
35
+ FakeWeb.register_uri(
36
+ :post,
37
+ url_with_auth("/#{Cashboard::Project.resource_name}"),
38
+ :status => ["201", "Created"],
39
+ :body => Cashboard::Project.list[0].to_xml
40
+ ) if MOCK_WEB_CONNECTIONS
41
+
42
+ client = Cashboard::ClientCompany.list[0]
43
+ # Create random project name so even if not destroyed on
44
+ # a live connection we don't run into duplicate name validation errors.
45
+ project_name = "Test project - " + generate_random_string
46
+ assert_nothing_raised do
47
+ project = Cashboard::Project.create(
48
+ :name => project_name,
49
+ :client_id => client.id,
50
+ :client_type => 'Company'
51
+ )
52
+ assert_kind_of Cashboard::Project, project
53
+ end
54
+ end
55
+
56
+ def test_create_fail
57
+ FakeWeb.register_uri(
58
+ :post,
59
+ url_with_auth("/#{Cashboard::Project.resource_name}"),
60
+ :status => ["400", "Bad Request"],
61
+ :body => GENERIC_ERROR_XML
62
+ ) if MOCK_WEB_CONNECTIONS
63
+
64
+ assert_raise Cashboard::BadRequest do
65
+ prj = Cashboard::Project.create()
66
+ end
67
+ end
68
+
69
+ def test_update_success
70
+ prj = Cashboard::Project.list[0]
71
+
72
+ FakeWeb.register_uri(
73
+ :put,
74
+ url_with_auth(prj.href),
75
+ :status => ["200", "Ok"],
76
+ :body => prj.to_xml
77
+ ) if MOCK_WEB_CONNECTIONS
78
+
79
+ prj.name = 'Some new name'
80
+ assert prj.update, "Project didn't save properly"
81
+ end
82
+
83
+ def test_update_fail
84
+ prj = Cashboard::Project.list[0]
85
+
86
+ FakeWeb.register_uri(
87
+ :put,
88
+ url_with_auth(prj.href),
89
+ :status => ["400", "Bad Request"],
90
+ :body => GENERIC_ERROR_XML
91
+ ) if MOCK_WEB_CONNECTIONS
92
+
93
+ prj.name = 'Some new name'
94
+ assert !prj.update, "Project saved when it shouldn't have"
95
+ end
96
+
97
+ def test_delete_success
98
+ prj = Cashboard::Project.list[0]
99
+
100
+ FakeWeb.register_uri(
101
+ :delete,
102
+ url_with_auth(prj.href),
103
+ :status => ["200", "Ok"]
104
+ ) if MOCK_WEB_CONNECTIONS
105
+
106
+ assert prj.delete, "Project wasn't deleted."
107
+ end
108
+
109
+ def test_delete_fail
110
+ prj = Cashboard::Project.list[0]
111
+
112
+ FakeWeb.register_uri(
113
+ :delete,
114
+ url_with_auth(prj.href),
115
+ :status => ["404", "Not found"]
116
+ ) if MOCK_WEB_CONNECTIONS
117
+
118
+ assert !prj.delete, "Project was deleted when it shouldn't have been."
119
+ end
120
+
121
+ def test_toggle_status_success
122
+ prj = Cashboard::Project.list[0]
123
+ assert_equal false, prj.is_active
124
+
125
+ FakeWeb.register_uri(
126
+ :put,
127
+ url_with_auth(prj.links[:toggle_status]),
128
+ :status => ["200", "Ok"]
129
+ ) if MOCK_WEB_CONNECTIONS
130
+
131
+ initial_status = prj.is_active
132
+
133
+ assert prj.toggle_status
134
+ assert true, prj.is_active
135
+ end
136
+
137
+ def test_toggle_status_failure
138
+ prj = Cashboard::Project.list[0]
139
+
140
+ FakeWeb.register_uri(
141
+ :put,
142
+ url_with_auth(prj.links[:toggle_status]),
143
+ :status => ["401", "Unauthorized"]
144
+ ) if MOCK_WEB_CONNECTIONS
145
+
146
+ initial_status = prj.is_active
147
+
148
+ assert !prj.toggle_status
149
+ assert prj.is_active == initial_status
150
+ end
151
+
152
+ def test_employee_project_assignments
153
+ mock_sub_resource(
154
+ Cashboard::Project.resource_name,
155
+ 'assigned_employees',
156
+ 'project_assignments'
157
+ ) if MOCK_WEB_CONNECTIONS
158
+
159
+ prj = Cashboard::Project.list[0]
160
+ assignments = prj.employee_project_assignments
161
+ assert assignments.size > 0
162
+ assignments.each do |assn|
163
+ assert_kind_of Cashboard::ProjectAssignment, assn
164
+ end
165
+ end
166
+
167
+ def test_line_items
168
+ mock_sub_resource(
169
+ Cashboard::Project.resource_name,
170
+ 'line_items',
171
+ 'line_items'
172
+ ) if MOCK_WEB_CONNECTIONS
173
+
174
+ prj = Cashboard::Project.list[0]
175
+ line_items = prj.line_items
176
+ assert line_items.size > 0
177
+ line_items.each do |li|
178
+ assert_kind_of Cashboard::LineItem, li
179
+ end
180
+ end
181
+
182
+ def test_tasks
183
+ assert_list_type :tasks, :task
184
+ end
185
+
186
+ def test_products
187
+ assert_list_type :products, :product
188
+ end
189
+
190
+ def test_custom_items
191
+ assert_list_type :custom_items, :custom
192
+ end
193
+
194
+ def test_href
195
+ assert Cashboard::Project.list[0].href.include?(Cashboard::Base.api_url)
196
+ end
197
+
198
+ end