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.
- data/.autotest +26 -0
- data/.gitignore +2 -0
- data/LICENSE +19 -0
- data/README.textile +58 -0
- data/Rakefile +25 -0
- data/cashboard.gemspec +129 -0
- data/examples/create_account.rb +38 -0
- data/examples/list_stuff_in_account.rb +15 -0
- data/examples/simple_workflow.rb +35 -0
- data/examples/time_tracking.rb +30 -0
- data/examples/toggle_timer.rb +0 -0
- data/lib/cashboard/account.rb +21 -0
- data/lib/cashboard/base.rb +223 -0
- data/lib/cashboard/behaviors/base.rb +4 -0
- data/lib/cashboard/behaviors/lists_line_items.rb +32 -0
- data/lib/cashboard/behaviors/toggleable.rb +18 -0
- data/lib/cashboard/client_company.rb +25 -0
- data/lib/cashboard/client_contact.rb +32 -0
- data/lib/cashboard/company_membership.rb +6 -0
- data/lib/cashboard/document_template.rb +10 -0
- data/lib/cashboard/employee.rb +29 -0
- data/lib/cashboard/errors.rb +48 -0
- data/lib/cashboard/estimate.rb +43 -0
- data/lib/cashboard/expense.rb +14 -0
- data/lib/cashboard/invoice.rb +75 -0
- data/lib/cashboard/invoice_line_item.rb +15 -0
- data/lib/cashboard/invoice_payment.rb +7 -0
- data/lib/cashboard/line_item.rb +27 -0
- data/lib/cashboard/payment.rb +22 -0
- data/lib/cashboard/project.rb +38 -0
- data/lib/cashboard/project_assignment.rb +9 -0
- data/lib/cashboard/time_entry.rb +45 -0
- data/lib/cashboard/version.rb +3 -0
- data/lib/cashboard.rb +75 -0
- data/lib/typecasted_open_struct.rb +82 -0
- data/test/fixtures/account.xml +50 -0
- data/test/fixtures/cashboard_credentials.yml +3 -0
- data/test/fixtures/client_companies.xml +41 -0
- data/test/fixtures/client_contacts.xml +53 -0
- data/test/fixtures/company_memberships.xml +21 -0
- data/test/fixtures/document_templates.xml +53 -0
- data/test/fixtures/employees.xml +51 -0
- data/test/fixtures/estimates.xml +243 -0
- data/test/fixtures/expenses.xml +101 -0
- data/test/fixtures/invoice_line_items.xml +138 -0
- data/test/fixtures/invoice_payments.xml +10 -0
- data/test/fixtures/invoices.xml +231 -0
- data/test/fixtures/line_items.xml +243 -0
- data/test/fixtures/payments.xml +93 -0
- data/test/fixtures/project_assignments.xml +30 -0
- data/test/fixtures/projects.xml +129 -0
- data/test/fixtures/time_entries.xml +213 -0
- data/test/full.rb +3 -0
- data/test/test_helper.rb +112 -0
- data/test/unit/account_test.rb +85 -0
- data/test/unit/document_template_test.rb +18 -0
- data/test/unit/estimate_test.rb +166 -0
- data/test/unit/expense_test.rb +16 -0
- data/test/unit/invoice_test.rb +185 -0
- data/test/unit/project_test.rb +198 -0
- data/test/unit/time_entry_test.rb +225 -0
- metadata +220 -0
@@ -0,0 +1,225 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
class TimeEntryTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def find_uninvoiced_entry
|
6
|
+
entries = Cashboard::TimeEntry.list
|
7
|
+
@te = entries.find {|e| e.has_been_invoiced? == false }
|
8
|
+
end
|
9
|
+
|
10
|
+
# TESTS ---------------------------------------------------------------------
|
11
|
+
|
12
|
+
def test_list
|
13
|
+
time_entries = Cashboard::TimeEntry.list
|
14
|
+
assert time_entries.size > 0
|
15
|
+
time_entries.each do |te|
|
16
|
+
assert_kind_of Cashboard::TimeEntry, te
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_create_success
|
21
|
+
FakeWeb.register_uri(
|
22
|
+
:post,
|
23
|
+
url_with_auth("/#{Cashboard::TimeEntry.resource_name}"),
|
24
|
+
:status => ["201", "Created"],
|
25
|
+
:body => Cashboard::TimeEntry.list[0].to_xml
|
26
|
+
) if MOCK_WEB_CONNECTIONS
|
27
|
+
|
28
|
+
# Fake line item list
|
29
|
+
mock_sub_resource(
|
30
|
+
Cashboard::Project.resource_name,
|
31
|
+
'line_items',
|
32
|
+
'line_items'
|
33
|
+
) if MOCK_WEB_CONNECTIONS
|
34
|
+
|
35
|
+
task = Cashboard::Project.list[0].tasks[0]
|
36
|
+
|
37
|
+
assert_nothing_raised do
|
38
|
+
@entry = Cashboard::TimeEntry.create(
|
39
|
+
:description => "Testing time entries from API wrapper",
|
40
|
+
:line_item_id => task.id
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_create_fail
|
46
|
+
FakeWeb.register_uri(
|
47
|
+
:post,
|
48
|
+
url_with_auth("/#{Cashboard::TimeEntry.resource_name}"),
|
49
|
+
:status => ["400", "Bad Request"],
|
50
|
+
:body => Cashboard::TimeEntry.list[0].to_xml
|
51
|
+
) if MOCK_WEB_CONNECTIONS
|
52
|
+
|
53
|
+
assert_raise Cashboard::BadRequest do
|
54
|
+
@entry = Cashboard::TimeEntry.create(
|
55
|
+
:description => "No line item specified will make the API puke"
|
56
|
+
)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_update_success
|
61
|
+
find_uninvoiced_entry
|
62
|
+
|
63
|
+
FakeWeb.register_uri(
|
64
|
+
:put,
|
65
|
+
url_with_auth(@te.href),
|
66
|
+
:status => ["200", "Ok"],
|
67
|
+
:body => @te.to_xml
|
68
|
+
) if MOCK_WEB_CONNECTIONS
|
69
|
+
|
70
|
+
@te.description = 'Twkin'
|
71
|
+
assert @te.update, "Entry didn't save properly"
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_update_fail
|
75
|
+
find_uninvoiced_entry
|
76
|
+
|
77
|
+
FakeWeb.register_uri(
|
78
|
+
:put,
|
79
|
+
url_with_auth(@te.href),
|
80
|
+
:status => ["400", "Bad Request"],
|
81
|
+
:body => GENERIC_ERROR_XML
|
82
|
+
) if MOCK_WEB_CONNECTIONS
|
83
|
+
|
84
|
+
|
85
|
+
@te.line_item_id = nil
|
86
|
+
assert !@te.update, "Entry saved when it shouldn't have"
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_delete_success
|
90
|
+
find_uninvoiced_entry
|
91
|
+
|
92
|
+
FakeWeb.register_uri(
|
93
|
+
:delete,
|
94
|
+
url_with_auth(@te.href),
|
95
|
+
:status => ["200", "Ok"]
|
96
|
+
) if MOCK_WEB_CONNECTIONS
|
97
|
+
|
98
|
+
assert @te.delete, "Time entry wasn't deleted."
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_delete_fail
|
102
|
+
find_uninvoiced_entry
|
103
|
+
|
104
|
+
@te.href = "http://#{Cashboard::Base.api_url}/time_entries/12345"
|
105
|
+
|
106
|
+
FakeWeb.register_uri(
|
107
|
+
:delete,
|
108
|
+
url_with_auth(@te.href),
|
109
|
+
:status => ["404", "Not found"]
|
110
|
+
) if MOCK_WEB_CONNECTIONS
|
111
|
+
|
112
|
+
assert !@te.delete, "Entry shouldn't have been found"
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_has_been_invoiced
|
116
|
+
entries = Cashboard::TimeEntry.list
|
117
|
+
|
118
|
+
te = entries.find{|e| e.description == "Not billed yet." }
|
119
|
+
assert_kind_of Cashboard::TimeEntry, te
|
120
|
+
|
121
|
+
assert te.invoice_line_item_id.blank?, "Invoice line item wasn't blank when should have been"
|
122
|
+
assert !te.has_been_invoiced?
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_toggle_timer_success_with_stopped_timer
|
126
|
+
find_uninvoiced_entry
|
127
|
+
assert_equal false, @te.is_running
|
128
|
+
assert_nil @te.timer_started_at
|
129
|
+
|
130
|
+
# Mocks a "toggled" timer from stop to start.
|
131
|
+
# Also includes a faked "stopped" timer that was returned with the data,
|
132
|
+
# as the API would do.
|
133
|
+
toggled_timer_xml = %Q\
|
134
|
+
<time_entry>
|
135
|
+
<link rel="toggle_timer" href="http://apicashboard.i/time_entries/800720104/toggle_timer"/>
|
136
|
+
<link rel="self" href="http://apicashboard.i/time_entries/800720104"/>
|
137
|
+
<id>800720104</id>
|
138
|
+
<created_on>2007-04-05 01:26:43</created_on>
|
139
|
+
<description>Not billed yet.</description>
|
140
|
+
<invoice_line_item_id read_only="true"></invoice_line_item_id>
|
141
|
+
<is_billable>false</is_billable>
|
142
|
+
<line_item_id>5568311</line_item_id>
|
143
|
+
<minutes>30</minutes>
|
144
|
+
<minutes_with_timer read_only="true">30</minutes_with_timer>
|
145
|
+
<person_id>215816037</person_id>
|
146
|
+
|
147
|
+
<is_running read_only="true">true</is_running>
|
148
|
+
<timer_started_at read_only="true">2010-01-01 05:55:55</timer_started_at>
|
149
|
+
<stopped_timer>
|
150
|
+
<href>http://url_of_stopped_entry</href>
|
151
|
+
<id>123456</id>
|
152
|
+
<minutes>30</minutes>
|
153
|
+
</stopped_timer>
|
154
|
+
|
155
|
+
</time_entry>
|
156
|
+
\
|
157
|
+
|
158
|
+
FakeWeb.register_uri(
|
159
|
+
:put,
|
160
|
+
url_with_auth(@te.links[:toggle_timer]),
|
161
|
+
:status => ["200", "Ok"],
|
162
|
+
:body => toggled_timer_xml
|
163
|
+
) if MOCK_WEB_CONNECTIONS
|
164
|
+
|
165
|
+
stopped_timer = @te.toggle_timer
|
166
|
+
assert true, @te.is_running
|
167
|
+
assert_kind_of DateTime, @te.timer_started_at
|
168
|
+
assert_kind_of Cashboard::Struct, stopped_timer
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_toggle_timer_success_without_stopped_timer
|
172
|
+
find_uninvoiced_entry
|
173
|
+
assert_equal false, @te.is_running
|
174
|
+
assert_nil @te.timer_started_at
|
175
|
+
|
176
|
+
# Mocks a "toggled" timer from stop to start.
|
177
|
+
# Also includes a faked "stopped" timer that was returned with the data,
|
178
|
+
# as the API would do.
|
179
|
+
toggled_timer_xml = %Q\
|
180
|
+
<time_entry>
|
181
|
+
<link rel="toggle_timer" href="http://apicashboard.i/time_entries/800720104/toggle_timer"/>
|
182
|
+
<link rel="self" href="http://apicashboard.i/time_entries/800720104"/>
|
183
|
+
<id>800720104</id>
|
184
|
+
<created_on>2007-04-05 01:26:43</created_on>
|
185
|
+
<description>Not billed yet.</description>
|
186
|
+
<invoice_line_item_id read_only="true"></invoice_line_item_id>
|
187
|
+
<is_billable>false</is_billable>
|
188
|
+
<line_item_id>5568311</line_item_id>
|
189
|
+
<minutes>30</minutes>
|
190
|
+
<minutes_with_timer read_only="true">30</minutes_with_timer>
|
191
|
+
<person_id>215816037</person_id>
|
192
|
+
|
193
|
+
<is_running read_only="true">true</is_running>
|
194
|
+
<timer_started_at read_only="true">2010-01-01 05:55:55</timer_started_at>
|
195
|
+
</time_entry>
|
196
|
+
\
|
197
|
+
|
198
|
+
FakeWeb.register_uri(
|
199
|
+
:put,
|
200
|
+
url_with_auth(@te.links[:toggle_timer]),
|
201
|
+
:status => ["200", "Ok"],
|
202
|
+
:body => toggled_timer_xml
|
203
|
+
) if MOCK_WEB_CONNECTIONS
|
204
|
+
|
205
|
+
stopped_timer = @te.toggle_timer
|
206
|
+
assert true, @te.is_running
|
207
|
+
assert_kind_of DateTime, @te.timer_started_at
|
208
|
+
assert_nil stopped_timer
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_toggle_status_failure
|
212
|
+
find_uninvoiced_entry
|
213
|
+
|
214
|
+
FakeWeb.register_uri(
|
215
|
+
:put,
|
216
|
+
url_with_auth(@te.links[:toggle_timer]),
|
217
|
+
:status => ["403", "Forbidden"]
|
218
|
+
) if MOCK_WEB_CONNECTIONS
|
219
|
+
|
220
|
+
assert_raises Cashboard::Forbidden do
|
221
|
+
@te.toggle_timer
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
end
|
metadata
ADDED
@@ -0,0 +1,220 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cashboard
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Subimage LLC
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-07-29 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: mocha
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 43
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 9
|
33
|
+
- 8
|
34
|
+
version: 0.9.8
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: fakeweb
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 15
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 2
|
49
|
+
- 8
|
50
|
+
version: 1.2.8
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: activesupport
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 9
|
62
|
+
segments:
|
63
|
+
- 2
|
64
|
+
- 3
|
65
|
+
- 5
|
66
|
+
version: 2.3.5
|
67
|
+
type: :runtime
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: httparty
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 5
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
- 6
|
81
|
+
- 1
|
82
|
+
version: 0.6.1
|
83
|
+
type: :runtime
|
84
|
+
version_requirements: *id004
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: xml-simple
|
87
|
+
prerelease: false
|
88
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 15
|
94
|
+
segments:
|
95
|
+
- 1
|
96
|
+
- 0
|
97
|
+
- 12
|
98
|
+
version: 1.0.12
|
99
|
+
type: :runtime
|
100
|
+
version_requirements: *id005
|
101
|
+
description: For more information see the homepage. Support and discussion can be found on the Cashboard forum (http://forum.getcashboard.com/)
|
102
|
+
email: support@getcashboard.com
|
103
|
+
executables: []
|
104
|
+
|
105
|
+
extensions: []
|
106
|
+
|
107
|
+
extra_rdoc_files:
|
108
|
+
- LICENSE
|
109
|
+
- README.textile
|
110
|
+
files:
|
111
|
+
- .autotest
|
112
|
+
- .gitignore
|
113
|
+
- LICENSE
|
114
|
+
- README.textile
|
115
|
+
- Rakefile
|
116
|
+
- cashboard.gemspec
|
117
|
+
- examples/create_account.rb
|
118
|
+
- examples/list_stuff_in_account.rb
|
119
|
+
- examples/simple_workflow.rb
|
120
|
+
- examples/time_tracking.rb
|
121
|
+
- examples/toggle_timer.rb
|
122
|
+
- lib/cashboard.rb
|
123
|
+
- lib/cashboard/account.rb
|
124
|
+
- lib/cashboard/base.rb
|
125
|
+
- lib/cashboard/behaviors/base.rb
|
126
|
+
- lib/cashboard/behaviors/lists_line_items.rb
|
127
|
+
- lib/cashboard/behaviors/toggleable.rb
|
128
|
+
- lib/cashboard/client_company.rb
|
129
|
+
- lib/cashboard/client_contact.rb
|
130
|
+
- lib/cashboard/company_membership.rb
|
131
|
+
- lib/cashboard/document_template.rb
|
132
|
+
- lib/cashboard/employee.rb
|
133
|
+
- lib/cashboard/errors.rb
|
134
|
+
- lib/cashboard/estimate.rb
|
135
|
+
- lib/cashboard/expense.rb
|
136
|
+
- lib/cashboard/invoice.rb
|
137
|
+
- lib/cashboard/invoice_line_item.rb
|
138
|
+
- lib/cashboard/invoice_payment.rb
|
139
|
+
- lib/cashboard/line_item.rb
|
140
|
+
- lib/cashboard/payment.rb
|
141
|
+
- lib/cashboard/project.rb
|
142
|
+
- lib/cashboard/project_assignment.rb
|
143
|
+
- lib/cashboard/time_entry.rb
|
144
|
+
- lib/cashboard/version.rb
|
145
|
+
- lib/typecasted_open_struct.rb
|
146
|
+
- test/fixtures/account.xml
|
147
|
+
- test/fixtures/cashboard_credentials.yml
|
148
|
+
- test/fixtures/client_companies.xml
|
149
|
+
- test/fixtures/client_contacts.xml
|
150
|
+
- test/fixtures/company_memberships.xml
|
151
|
+
- test/fixtures/document_templates.xml
|
152
|
+
- test/fixtures/employees.xml
|
153
|
+
- test/fixtures/estimates.xml
|
154
|
+
- test/fixtures/expenses.xml
|
155
|
+
- test/fixtures/invoice_line_items.xml
|
156
|
+
- test/fixtures/invoice_payments.xml
|
157
|
+
- test/fixtures/invoices.xml
|
158
|
+
- test/fixtures/line_items.xml
|
159
|
+
- test/fixtures/payments.xml
|
160
|
+
- test/fixtures/project_assignments.xml
|
161
|
+
- test/fixtures/projects.xml
|
162
|
+
- test/fixtures/time_entries.xml
|
163
|
+
- test/full.rb
|
164
|
+
- test/test_helper.rb
|
165
|
+
- test/unit/account_test.rb
|
166
|
+
- test/unit/document_template_test.rb
|
167
|
+
- test/unit/estimate_test.rb
|
168
|
+
- test/unit/expense_test.rb
|
169
|
+
- test/unit/invoice_test.rb
|
170
|
+
- test/unit/project_test.rb
|
171
|
+
- test/unit/time_entry_test.rb
|
172
|
+
has_rdoc: true
|
173
|
+
homepage: http://github.com/subimage/cashboard-rb
|
174
|
+
licenses: []
|
175
|
+
|
176
|
+
post_install_message:
|
177
|
+
rdoc_options:
|
178
|
+
- --charset=UTF-8
|
179
|
+
require_paths:
|
180
|
+
- lib
|
181
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
182
|
+
none: false
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
hash: 3
|
187
|
+
segments:
|
188
|
+
- 0
|
189
|
+
version: "0"
|
190
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
|
+
none: false
|
192
|
+
requirements:
|
193
|
+
- - ">="
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
hash: 3
|
196
|
+
segments:
|
197
|
+
- 0
|
198
|
+
version: "0"
|
199
|
+
requirements: []
|
200
|
+
|
201
|
+
rubyforge_project:
|
202
|
+
rubygems_version: 1.3.7
|
203
|
+
signing_key:
|
204
|
+
specification_version: 3
|
205
|
+
summary: Ruby wrapper library for the Cashboard API
|
206
|
+
test_files:
|
207
|
+
- test/full.rb
|
208
|
+
- test/test_helper.rb
|
209
|
+
- test/unit/account_test.rb
|
210
|
+
- test/unit/document_template_test.rb
|
211
|
+
- test/unit/estimate_test.rb
|
212
|
+
- test/unit/expense_test.rb
|
213
|
+
- test/unit/invoice_test.rb
|
214
|
+
- test/unit/project_test.rb
|
215
|
+
- test/unit/time_entry_test.rb
|
216
|
+
- examples/create_account.rb
|
217
|
+
- examples/list_stuff_in_account.rb
|
218
|
+
- examples/simple_workflow.rb
|
219
|
+
- examples/time_tracking.rb
|
220
|
+
- examples/toggle_timer.rb
|