subledger 0.7.7
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 +9 -0
- data/LICENSE.txt +12 -0
- data/README.md +136 -0
- data/Rakefile +5 -0
- data/bin/subledger +6 -0
- data/lib/subledger/actor.rb +32 -0
- data/lib/subledger/collection_name.rb +25 -0
- data/lib/subledger/domain/account.rb +168 -0
- data/lib/subledger/domain/balance.rb +102 -0
- data/lib/subledger/domain/book.rb +111 -0
- data/lib/subledger/domain/category.rb +157 -0
- data/lib/subledger/domain/control.rb +180 -0
- data/lib/subledger/domain/formatters.rb +31 -0
- data/lib/subledger/domain/identity.rb +159 -0
- data/lib/subledger/domain/journal_entry.rb +293 -0
- data/lib/subledger/domain/key.rb +113 -0
- data/lib/subledger/domain/line.rb +272 -0
- data/lib/subledger/domain/org.rb +110 -0
- data/lib/subledger/domain/report.rb +247 -0
- data/lib/subledger/domain/report_rendering.rb +233 -0
- data/lib/subledger/domain/roles/activatable.rb +11 -0
- data/lib/subledger/domain/roles/archivable.rb +11 -0
- data/lib/subledger/domain/roles/attributable.rb +14 -0
- data/lib/subledger/domain/roles/collectable.rb +175 -0
- data/lib/subledger/domain/roles/creatable.rb +58 -0
- data/lib/subledger/domain/roles/describable.rb +33 -0
- data/lib/subledger/domain/roles/describable_report_rendering.rb +50 -0
- data/lib/subledger/domain/roles/identifiable.rb +15 -0
- data/lib/subledger/domain/roles/postable.rb +54 -0
- data/lib/subledger/domain/roles/progressable.rb +11 -0
- data/lib/subledger/domain/roles/readable.rb +34 -0
- data/lib/subledger/domain/roles/restable.rb +69 -0
- data/lib/subledger/domain/roles/storable.rb +30 -0
- data/lib/subledger/domain/roles/timeable.rb +18 -0
- data/lib/subledger/domain/roles/updatable.rb +35 -0
- data/lib/subledger/domain/roles/versionable.rb +35 -0
- data/lib/subledger/domain/roles.rb +16 -0
- data/lib/subledger/domain/value/credit.rb +16 -0
- data/lib/subledger/domain/value/debit.rb +16 -0
- data/lib/subledger/domain/value/zero.rb +24 -0
- data/lib/subledger/domain/value.rb +111 -0
- data/lib/subledger/domain.rb +95 -0
- data/lib/subledger/exception_handler.rb +65 -0
- data/lib/subledger/interface/client.rb +295 -0
- data/lib/subledger/interface/dispatcher.rb +20 -0
- data/lib/subledger/interface.rb +2 -0
- data/lib/subledger/path.rb +106 -0
- data/lib/subledger/rest.rb +128 -0
- data/lib/subledger/server.rb +3 -0
- data/lib/subledger/store/api/errors.rb +95 -0
- data/lib/subledger/store/api/roles/activate.rb +21 -0
- data/lib/subledger/store/api/roles/archive.rb +21 -0
- data/lib/subledger/store/api/roles/balance.rb +39 -0
- data/lib/subledger/store/api/roles/categories.rb +51 -0
- data/lib/subledger/store/api/roles/collect.rb +58 -0
- data/lib/subledger/store/api/roles/create.rb +26 -0
- data/lib/subledger/store/api/roles/create_and_post.rb +35 -0
- data/lib/subledger/store/api/roles/create_identity.rb +39 -0
- data/lib/subledger/store/api/roles/create_line.rb +24 -0
- data/lib/subledger/store/api/roles/first_and_last_line.rb +31 -0
- data/lib/subledger/store/api/roles/post.rb +25 -0
- data/lib/subledger/store/api/roles/progress.rb +21 -0
- data/lib/subledger/store/api/roles/read.rb +19 -0
- data/lib/subledger/store/api/roles/reports.rb +77 -0
- data/lib/subledger/store/api/roles/update.rb +24 -0
- data/lib/subledger/store/api/store.rb +103 -0
- data/lib/subledger/store/api.rb +20 -0
- data/lib/subledger/store.rb +236 -0
- data/lib/subledger/supervisor.rb +21 -0
- data/lib/subledger/uuid.rb +52 -0
- data/lib/subledger/version.rb +4 -0
- data/lib/subledger.rb +234 -0
- data/spec/spec_helper.rb +77 -0
- data/spec/subledger_account_spec.rb +354 -0
- data/spec/subledger_book_spec.rb +130 -0
- data/spec/subledger_category_spec.rb +203 -0
- data/spec/subledger_control_spec.rb +43 -0
- data/spec/subledger_identity_spec.rb +47 -0
- data/spec/subledger_journal_entry_spec.rb +417 -0
- data/spec/subledger_key_spec.rb +43 -0
- data/spec/subledger_org_spec.rb +68 -0
- data/spec/subledger_report_spec.rb +295 -0
- data/spec/subledger_spec.rb +101 -0
- data/subledger.gemspec +52 -0
- metadata +205 -0
@@ -0,0 +1,417 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
Test 'Subledger' do
|
4
|
+
|
5
|
+
let(:factory ) { Subledger::Factory.create }
|
6
|
+
|
7
|
+
Instance do
|
8
|
+
subject { factory.client }
|
9
|
+
|
10
|
+
Test 'JournalEntry' do
|
11
|
+
|
12
|
+
# POST /books/:book_id/journal_entries
|
13
|
+
RespondsTo 'journal_entry.create' do
|
14
|
+
ByReturning 'an instance of Subledger::Domain::ActiveJournalEntry' do
|
15
|
+
subject.journal_entry.create( factory.journal_entry_args ).
|
16
|
+
must_be_instance_of Subledger::Domain::ActiveJournalEntry
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# GET /books/:book_id/journal_entries/:id
|
21
|
+
[ :archived, :active, :posting, :posted ].each do |state|
|
22
|
+
RespondsTo 'journal_entry.read' do
|
23
|
+
let(:journal_entry) { factory.create_journal_entry state }
|
24
|
+
|
25
|
+
ByReturning "an instance of #{state} journal entry" do
|
26
|
+
subject.journal_entry.read( :id => journal_entry.id ).
|
27
|
+
must_be_instance_of journal_entry.class
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# PATCH /books/:book_id/journal_entries/:id
|
33
|
+
[ :archived, :active ].each do |state|
|
34
|
+
RespondsTo 'journal_entries.update' do
|
35
|
+
let(:je ) { factory.create_journal_entry state }
|
36
|
+
let(:args ) { je.attributes }
|
37
|
+
let(:description) { 'updated description' }
|
38
|
+
let(:update_args) { args.merge :description => description,
|
39
|
+
:version => 2 }
|
40
|
+
|
41
|
+
ByReturning "an instance of #{state} journal entry" do
|
42
|
+
patched = subject.journal_entries.update update_args
|
43
|
+
|
44
|
+
patched.must_be_instance_of je.class
|
45
|
+
patched.description.must_equal description
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# POST /books/:book_id/journal_entries/create_and_post
|
51
|
+
RespondsTo 'journal_entry.create_and_post' do
|
52
|
+
ByReturning 'a Subledger::Domain::PostingJournalEntry' do
|
53
|
+
posting_je = subject.journal_entry.
|
54
|
+
create_and_post( factory.create_and_post_args )
|
55
|
+
posting_je.must_be_instance_of Subledger::Domain::PostingJournalEntry
|
56
|
+
end
|
57
|
+
|
58
|
+
When 'lines are out-of-balance' do
|
59
|
+
ByReturning 'a Subledger::Domain::ActiveJournalEntry w/ reason' do
|
60
|
+
aje = subject.journal_entry.
|
61
|
+
create_and_post factory.oob_create_and_post_args
|
62
|
+
aje.must_be_instance_of Subledger::Domain::ActiveJournalEntry
|
63
|
+
|
64
|
+
aje.reason.wont_be_nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
When 'it has no lines' do
|
69
|
+
ByReturning 'a Subledger::Domain::ActiveJournalEntry w/ reason' do
|
70
|
+
aje = subject.journal_entry.
|
71
|
+
create_and_post factory.no_lines_create_and_post_args
|
72
|
+
aje.must_be_instance_of Subledger::Domain::ActiveJournalEntry
|
73
|
+
|
74
|
+
aje.reason.wont_be_nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
When 'lines have no account' do
|
79
|
+
ByRaising 'an error' do
|
80
|
+
|
81
|
+
insane_args = factory.create_and_post_args
|
82
|
+
|
83
|
+
insane_args[:lines].first.delete :account
|
84
|
+
|
85
|
+
lambda { subject.journal_entry.create_and_post insane_args }.
|
86
|
+
must_raise Subledger::Domain::JournalEntryError
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# GET /books/:book_id/journal_entries ? before = :effective_at & limit = :limit & state = :state
|
92
|
+
# ending
|
93
|
+
# starting
|
94
|
+
# after
|
95
|
+
[ :active, :archived, :posting, :posted ].each do |state|
|
96
|
+
Subledger.scenarios_order.each do |scenario|
|
97
|
+
action = scenario.keys.first
|
98
|
+
expectations = scenario[action]
|
99
|
+
|
100
|
+
RespondsTo "journal_entries.collect action => #{action}, state => #{state}" do
|
101
|
+
let(:journal_entries) { factory.create_journal_entry_collection state }
|
102
|
+
let(:journal_entry ) { journal_entries[2] }
|
103
|
+
let(:limit ) { 2 }
|
104
|
+
let(:klass ) { journal_entry.class }
|
105
|
+
let(:collection ) { subject.journal_entries.collect args }
|
106
|
+
|
107
|
+
# TODO Does factory.now work here?
|
108
|
+
let(:effective_at) { journal_entry.effective_at }
|
109
|
+
|
110
|
+
let(:args) { { :action => action,
|
111
|
+
:effective_at => effective_at,
|
112
|
+
:state => state,
|
113
|
+
:limit => limit } }
|
114
|
+
|
115
|
+
When 'not given a block' do
|
116
|
+
ByReturning "a list of #{state} journal entries" do
|
117
|
+
collection.length.must_equal expectations.length
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
When 'given a block' do
|
122
|
+
ByYielding "a list of #{state} journal entries" do
|
123
|
+
count = 0
|
124
|
+
|
125
|
+
collection.each do |aje|
|
126
|
+
expectation = expectations[count]
|
127
|
+
|
128
|
+
aje.description.must_equal expectation
|
129
|
+
|
130
|
+
aje.must_be_instance_of klass
|
131
|
+
|
132
|
+
count += 1
|
133
|
+
end
|
134
|
+
|
135
|
+
count.must_equal expectations.length
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# GET /books/:book_id/journal_entries ? preceding = :je_id & limit = :limit & state = :state
|
143
|
+
# following
|
144
|
+
[ :archived, :active, :posting, :posted ].each do |state|
|
145
|
+
Subledger.scenarios_id.each do |scenario|
|
146
|
+
action = scenario.keys.first
|
147
|
+
expectations = scenario[action]
|
148
|
+
|
149
|
+
RespondsTo "journal_entries.collect action => #{action}, state => #{state}" do
|
150
|
+
let(:journal_entries) { factory.create_journal_entry_collection state }
|
151
|
+
|
152
|
+
let(:journal_entry) { journal_entries[2] }
|
153
|
+
let(:limit ) { 2 }
|
154
|
+
let(:collection ) { subject.journal_entries.collect args }
|
155
|
+
let(:klass ) { journal_entry.class }
|
156
|
+
|
157
|
+
let(:args) { { :action => action,
|
158
|
+
:id => journal_entry.id,
|
159
|
+
:state => state,
|
160
|
+
:limit => limit } }
|
161
|
+
|
162
|
+
When 'not given a block' do
|
163
|
+
ByReturning "a list of #{state} journal entries" do
|
164
|
+
collection.length.must_equal expectations.length
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
When 'given a block' do
|
169
|
+
ByYielding "a list of #{state} journal entries" do
|
170
|
+
count = 0
|
171
|
+
|
172
|
+
collection.each do |aje|
|
173
|
+
expectation = expectations[count]
|
174
|
+
|
175
|
+
aje.send( :description ).must_equal expectation
|
176
|
+
|
177
|
+
aje.must_be_instance_of klass
|
178
|
+
|
179
|
+
count += 1
|
180
|
+
end
|
181
|
+
|
182
|
+
count.must_equal expectations.length
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
# POST /books/:book_id/active_journal_entries/:id/archive
|
190
|
+
RespondsTo 'active_journal_entry_instance.archive' do
|
191
|
+
ByReturning 'an instance of Subledger::Domain::ArchivedJournalEntry' do
|
192
|
+
factory.create_journal_entry(:active).archive.
|
193
|
+
must_be_instance_of Subledger::Domain::ArchivedJournalEntry
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
# POST /books/:book_id/archived_journal_entries/:id/activate
|
198
|
+
RespondsTo 'archived_journal_entry_instance.activate' do
|
199
|
+
ByReturning 'an instance of Subledger::Domain::ActiveJournalEntry' do
|
200
|
+
factory.create_journal_entry(:archived).activate.
|
201
|
+
must_be_instance_of Subledger::Domain::ActiveJournalEntry
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
# POST /books/:book_id/journal_entries/:je_id/create_line
|
206
|
+
RespondsTo 'active_journal_entry_instance.create_line' do
|
207
|
+
let(:dje ) { factory.create_journal_entry :active }
|
208
|
+
let(:line_args) { factory.journal_entry_line_args }
|
209
|
+
|
210
|
+
ByReturning 'an instance of Subledger::Domain::ActiveLine' do
|
211
|
+
dje.create_line(line_args).
|
212
|
+
must_be_instance_of Subledger::Domain::ActiveLine
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
# GET /books/:book_id/journal_entries/:je_id/lines ? state = :state & action = before & order = :order & limit = :limit
|
217
|
+
# ending
|
218
|
+
# starting
|
219
|
+
# after
|
220
|
+
[ :active, :archived, :posted ].each do |state|
|
221
|
+
Subledger.scenarios_order.each do |scenario|
|
222
|
+
action = scenario.keys.first
|
223
|
+
expectations = scenario[action]
|
224
|
+
|
225
|
+
RespondsTo "journal_entry_instance.lines action => #{action}, state => #{state}" do
|
226
|
+
let(:aje ) { factory.create_journal_entry :active }
|
227
|
+
let(:lines ) { factory.create_line_collection aje, state }
|
228
|
+
let(:line ) { lines[2] }
|
229
|
+
let(:order ) { line.order }
|
230
|
+
let(:limit ) { 2 }
|
231
|
+
let(:klass ) { line.class }
|
232
|
+
let(:collection) { aje.lines args }
|
233
|
+
|
234
|
+
let(:args) { { :action => action,
|
235
|
+
:order => order,
|
236
|
+
:state => state,
|
237
|
+
:limit => limit } }
|
238
|
+
|
239
|
+
When 'not given a block' do
|
240
|
+
ByReturning "a list of #{state} journal entry lines" do
|
241
|
+
collection.length.must_equal expectations.length
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
When 'given a block' do
|
246
|
+
ByYielding "a list of #{state} journal entry lines" do
|
247
|
+
count = 0
|
248
|
+
|
249
|
+
collection.each do |line|
|
250
|
+
expectation = expectations[count]
|
251
|
+
|
252
|
+
line.description.must_equal expectation
|
253
|
+
|
254
|
+
line.must_be_instance_of klass
|
255
|
+
|
256
|
+
if state == :posted
|
257
|
+
line.effective_at.wont_be_nil
|
258
|
+
line.posted_at.wont_be_nil
|
259
|
+
end
|
260
|
+
|
261
|
+
count += 1
|
262
|
+
end
|
263
|
+
|
264
|
+
count.must_equal expectations.length
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
# GET /books/:book_id/journal_entries/:je_id/lines ? preceding = :line_id & limit = :limit & state = :state
|
272
|
+
# following
|
273
|
+
[ :preceding, :following ].each do |action|
|
274
|
+
RespondsTo "active_journal_entry.lines action => #{action}" do
|
275
|
+
let(:debit_account ) { factory.create_account :active, factory.client.debit }
|
276
|
+
let(:credit_account) { factory.create_account :active, factory.client.credit }
|
277
|
+
let(:journal_entry ) { factory.create_journal_entry :active }
|
278
|
+
|
279
|
+
let(:order) do
|
280
|
+
if action == :preceding
|
281
|
+
'102'
|
282
|
+
else
|
283
|
+
'1'
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
let(:line) { journal_entry.create_line :account => debit_account,
|
288
|
+
:description => 'description',
|
289
|
+
:value => factory.client.zero( 0 ),
|
290
|
+
:order => order }
|
291
|
+
|
292
|
+
let(:args) { { :action => action,
|
293
|
+
:id => line.id,
|
294
|
+
:state => :active,
|
295
|
+
:limit => 100 } }
|
296
|
+
|
297
|
+
before do
|
298
|
+
line
|
299
|
+
|
300
|
+
2.upto 51 do |number|
|
301
|
+
journal_entry.create_line :account => debit_account,
|
302
|
+
:description => 'description',
|
303
|
+
:value => factory.client.debit( 1 ),
|
304
|
+
:order => number.to_s
|
305
|
+
end
|
306
|
+
|
307
|
+
52.upto 101 do |number|
|
308
|
+
journal_entry.create_line :account => credit_account,
|
309
|
+
:description => 'description',
|
310
|
+
:value => factory.client.credit( 1 ),
|
311
|
+
:order => number.to_s
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
let(:collection) { journal_entry.lines args }
|
316
|
+
|
317
|
+
ByReturning "a list of active journal entry lines" do
|
318
|
+
journal_entry.lines( args ).length.must_equal 100
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
# GET /books/:book_id/journal_entries/:je_id/lines/:id
|
324
|
+
RespondsTo 'journal_entry.line.read' do
|
325
|
+
let(:dje ) { factory.create_journal_entry :active }
|
326
|
+
let(:line ) { factory.create_line dje, :active }
|
327
|
+
|
328
|
+
ByReturning 'a Subledger::Domain::ActiveLine' do
|
329
|
+
dje.line( :id => line.id ).
|
330
|
+
read.
|
331
|
+
must_be_instance_of Subledger::Domain::ActiveLine
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
# PATCH /books/:book_id/journal_entry/:je_id/lines/:id
|
336
|
+
RespondsTo 'active_lines.update' do
|
337
|
+
let(:journal_entry) { factory.create_journal_entry :active }
|
338
|
+
let(:line ) { factory.create_line journal_entry, :active }
|
339
|
+
let(:description ) { 'updated description' }
|
340
|
+
|
341
|
+
ByReturning 'an instance of Subledger::Domain::ActiveLine' do
|
342
|
+
args = line.attributes
|
343
|
+
args.merge! :description => description,
|
344
|
+
:version => 2
|
345
|
+
|
346
|
+
patched = subject.active_lines.update args
|
347
|
+
|
348
|
+
patched.must_be_instance_of Subledger::Domain::ActiveLine
|
349
|
+
patched.send( :description ).must_equal description
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
# POST /books/:book_id/journal_entries/:je_id/lines/:id/archive
|
354
|
+
RespondsTo 'journal_entry_line_instance.archive' do
|
355
|
+
let(:journal_entry) { factory.create_journal_entry :active }
|
356
|
+
|
357
|
+
ByReturning 'an instance of Subledger::Domain::ArchivedLine' do
|
358
|
+
factory.create_line( journal_entry, :active ).
|
359
|
+
archive.
|
360
|
+
must_be_instance_of Subledger::Domain::ArchivedLine
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
364
|
+
# POST /books/:book_id/journal_entries/:je_id/lines/:id/activate
|
365
|
+
RespondsTo 'journal_entry_line_instance.activate' do
|
366
|
+
let(:journal_entry) { factory.create_journal_entry :active }
|
367
|
+
|
368
|
+
ByReturning 'an instance of Subledger::Domain::ActiveLine' do
|
369
|
+
factory.create_line( journal_entry, :archived ).
|
370
|
+
activate.
|
371
|
+
must_be_instance_of Subledger::Domain::ActiveLine
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
375
|
+
# Accounting post!
|
376
|
+
# POST /books/:book_id/journal_entries/:id
|
377
|
+
[ :active, :posting, :posted ].each do |state|
|
378
|
+
klass = if state == :posted
|
379
|
+
Subledger::Domain::PostedJournalEntry
|
380
|
+
else
|
381
|
+
Subledger::Domain::PostingJournalEntry
|
382
|
+
end
|
383
|
+
|
384
|
+
RespondsTo 'journal_entry_instance.post successfully' do
|
385
|
+
When "state is #{state}" do
|
386
|
+
let(:journal_entry) { factory.create_journal_entry state, :lines }
|
387
|
+
|
388
|
+
ByReturning "an instance #{klass}" do
|
389
|
+
journal_entry.post.must_be_instance_of klass
|
390
|
+
end
|
391
|
+
end
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
RespondsTo 'journal_entry_instance.post unsuccessfully' do
|
396
|
+
When 'state is archived' do
|
397
|
+
let(:journal_entry) { factory.create_journal_entry( :active, :lines ).archive }
|
398
|
+
|
399
|
+
ByRaising 'a NoMethodError' do
|
400
|
+
lambda { journal_entry.post }.must_raise NoMethodError
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
# GET /books/:book_id/journal_entries/:id/progress
|
406
|
+
[ :archived, :active, :posting, :posted ].each do |state|
|
407
|
+
RespondsTo 'journal_entry_instance.progress' do
|
408
|
+
let(:journal_entry) { factory.create_journal_entry state }
|
409
|
+
|
410
|
+
ByReturning 'an integer from 0-100' do
|
411
|
+
journal_entry.progress.must_be_instance_of Fixnum
|
412
|
+
end
|
413
|
+
end
|
414
|
+
end
|
415
|
+
end
|
416
|
+
end
|
417
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
Test 'Subledger' do
|
4
|
+
|
5
|
+
let(:factory) { Subledger::Factory.create }
|
6
|
+
let(:identity) { factory.identity }
|
7
|
+
|
8
|
+
Instance do
|
9
|
+
subject { factory.client }
|
10
|
+
|
11
|
+
Test 'Key' do
|
12
|
+
# POST /identities/:identity_id/keys
|
13
|
+
RespondsTo 'keys.create' do
|
14
|
+
ByReturning 'an instance of Subledger::Domain::ActiveKey' do
|
15
|
+
subject.keys.create( factory.key_args( identity ) ).
|
16
|
+
must_be_instance_of Subledger::Domain::ActiveKey
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# POST /identities/:identity_id/keys/:key_id/archive
|
21
|
+
[ :archived, :active ].each do |state|
|
22
|
+
RespondsTo "#{state}_key_instance.archive" do
|
23
|
+
let(:key) { factory.create_key state, identity }
|
24
|
+
|
25
|
+
ByReturning 'an instance of Subledger::Domain::ArchivedKey' do
|
26
|
+
key.archive.must_be_instance_of Subledger::Domain::ArchivedKey
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# POST /identities/:identity_id/keys/:key_id/activate
|
32
|
+
[ :archived, :active ].each do |state|
|
33
|
+
RespondsTo "#{state}_key_instance.activate" do
|
34
|
+
let(:key) { factory.create_key state, identity }
|
35
|
+
|
36
|
+
ByReturning 'an instance of Subledger::Domain::ActiveKey' do
|
37
|
+
key.activate.must_be_instance_of Subledger::Domain::ActiveKey
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
Test 'Subledger' do
|
4
|
+
|
5
|
+
let(:factory) { Subledger::Factory.create }
|
6
|
+
|
7
|
+
Instance do
|
8
|
+
subject { factory.client }
|
9
|
+
|
10
|
+
Test 'Org' do
|
11
|
+
# POST /orgs
|
12
|
+
RespondsTo 'orgs.create' do
|
13
|
+
ByReturning 'an instance of Subledger::Domain::ActiveOrg' do
|
14
|
+
subject.orgs.create( factory.org_args ).
|
15
|
+
must_be_instance_of Subledger::Domain::ActiveOrg
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# GET /orgs/:id
|
20
|
+
RespondsTo 'orgs.read' do
|
21
|
+
let(:org) { factory.create_org :active }
|
22
|
+
|
23
|
+
ByReturning 'a kind of Subledger::Domain::ActiveOrg' do
|
24
|
+
subject.orgs.read( :id => org.id ).
|
25
|
+
must_be_instance_of Subledger::Domain::ActiveOrg
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# PATCH /orgs/:id
|
30
|
+
RespondsTo 'orgs.update' do
|
31
|
+
let(:org ) { factory.create_org :active }
|
32
|
+
let(:description) { 'updated description' }
|
33
|
+
let(:args ) { org.attributes }
|
34
|
+
let(:update_args) { args.merge :description => description,
|
35
|
+
:version => 2 }
|
36
|
+
|
37
|
+
ByReturning 'an updated kind of Subledger::Domain::ActiveOrg' do
|
38
|
+
patched = subject.orgs.update update_args
|
39
|
+
|
40
|
+
patched.must_be_instance_of Subledger::Domain::ActiveOrg
|
41
|
+
patched.description.must_equal description
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# POST /orgs/:id/archive
|
46
|
+
[ :archived, :active ].each do |state|
|
47
|
+
RespondsTo "#{state}_org_instance.archive" do
|
48
|
+
let(:org) { factory.create_org state }
|
49
|
+
|
50
|
+
ByReturning 'an instance of Subledger::Domain::ArchivedOrg' do
|
51
|
+
org.archive.must_be_instance_of Subledger::Domain::ArchivedOrg
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# POST /orgs/:id/activate
|
57
|
+
[ :archived, :active ].each do |state|
|
58
|
+
RespondsTo "#{state}_org_instance.activate" do
|
59
|
+
let(:org) { factory.create_org state }
|
60
|
+
|
61
|
+
ByReturning 'an instance of Subledger::Domain::ActiveOrg' do
|
62
|
+
org.activate.must_be_instance_of Subledger::Domain::ActiveOrg
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|