bumbleworks 0.0.21 → 0.0.22
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/lib/bumbleworks.rb +1 -0
- data/lib/bumbleworks/local_participant.rb +9 -0
- data/lib/bumbleworks/task.rb +8 -21
- data/lib/bumbleworks/tasks/base.rb +4 -0
- data/lib/bumbleworks/version.rb +1 -1
- data/lib/bumbleworks/workitem_entity_storage.rb +24 -0
- data/spec/lib/bumbleworks/local_participant_spec.rb +9 -0
- data/spec/lib/bumbleworks/task_spec.rb +14 -66
- data/spec/lib/bumbleworks/workitem_entity_storage_spec.rb +76 -0
- metadata +7 -1
data/lib/bumbleworks.rb
CHANGED
data/lib/bumbleworks/task.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require "bumbleworks/tasks/base"
|
2
|
+
require "bumbleworks/workitem_entity_storage"
|
2
3
|
|
3
4
|
module Bumbleworks
|
4
5
|
class Task
|
6
|
+
include WorkitemEntityStorage
|
7
|
+
|
5
8
|
class AlreadyClaimed < StandardError; end
|
6
9
|
class MissingWorkitem < StandardError; end
|
7
|
-
class EntityNotFound < StandardError; end
|
8
10
|
class NotCompletable < StandardError; end
|
9
11
|
|
10
12
|
extend Forwardable
|
@@ -80,25 +82,6 @@ module Bumbleworks
|
|
80
82
|
self
|
81
83
|
end
|
82
84
|
|
83
|
-
def entity
|
84
|
-
if has_entity_fields?
|
85
|
-
klass = Bumbleworks::Support.constantize(fields['entity_type'])
|
86
|
-
entity = klass.first_by_identifier(fields['entity_id'])
|
87
|
-
end
|
88
|
-
raise EntityNotFound unless entity
|
89
|
-
entity
|
90
|
-
end
|
91
|
-
|
92
|
-
def has_entity?
|
93
|
-
!entity.nil?
|
94
|
-
rescue EntityNotFound
|
95
|
-
false
|
96
|
-
end
|
97
|
-
|
98
|
-
def has_entity_fields?
|
99
|
-
fields['entity_id'] && fields['entity_type']
|
100
|
-
end
|
101
|
-
|
102
85
|
# alias for fields[] (fields delegated to workitem)
|
103
86
|
def [](key)
|
104
87
|
fields[key]
|
@@ -135,7 +118,7 @@ module Bumbleworks
|
|
135
118
|
|
136
119
|
# proceed workitem (saving changes to fields)
|
137
120
|
def complete(metadata = {})
|
138
|
-
raise NotCompletable unless completable?
|
121
|
+
raise NotCompletable.new(not_completable_error_message) unless completable?
|
139
122
|
before_update(metadata)
|
140
123
|
before_complete(metadata)
|
141
124
|
proceed_workitem
|
@@ -188,6 +171,10 @@ module Bumbleworks
|
|
188
171
|
|
189
172
|
private
|
190
173
|
|
174
|
+
def workitem
|
175
|
+
@workitem
|
176
|
+
end
|
177
|
+
|
191
178
|
def storage_participant
|
192
179
|
self.class.storage_participant
|
193
180
|
end
|
data/lib/bumbleworks/version.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Bumbleworks
|
2
|
+
module WorkitemEntityStorage
|
3
|
+
class EntityNotFound < StandardError; end
|
4
|
+
|
5
|
+
def entity
|
6
|
+
if has_entity_fields?
|
7
|
+
klass = Bumbleworks::Support.constantize(workitem.fields['entity_type'])
|
8
|
+
entity = klass.first_by_identifier(workitem.fields['entity_id'])
|
9
|
+
end
|
10
|
+
raise EntityNotFound unless entity
|
11
|
+
entity
|
12
|
+
end
|
13
|
+
|
14
|
+
def has_entity?
|
15
|
+
!entity.nil?
|
16
|
+
rescue EntityNotFound
|
17
|
+
false
|
18
|
+
end
|
19
|
+
|
20
|
+
def has_entity_fields?
|
21
|
+
workitem.fields['entity_id'] && workitem.fields['entity_type']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
describe Bumbleworks::LocalParticipant do
|
2
|
+
it 'includes Ruote::LocalParticipant' do
|
3
|
+
described_class.included_modules.should include(Ruote::LocalParticipant)
|
4
|
+
end
|
5
|
+
|
6
|
+
it 'includes WorkitemEntityStorage' do
|
7
|
+
described_class.included_modules.should include(Bumbleworks::WorkitemEntityStorage)
|
8
|
+
end
|
9
|
+
end
|
@@ -8,6 +8,18 @@ describe Bumbleworks::Task do
|
|
8
8
|
Bumbleworks.start_worker!
|
9
9
|
end
|
10
10
|
|
11
|
+
it 'includes WorkitemEntityStorage' do
|
12
|
+
described_class.included_modules.should include(Bumbleworks::WorkitemEntityStorage)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#not_completable_error_message' do
|
16
|
+
it 'defaults to generic message' do
|
17
|
+
task = described_class.new(workflow_item)
|
18
|
+
task.not_completable_error_message.should ==
|
19
|
+
"This task is not currently completable."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
11
23
|
describe '.autoload_all' do
|
12
24
|
it 'autoloads all task modules in directory' do
|
13
25
|
Bumbleworks.root = File.join(fixtures_path, 'apps', 'with_default_directories')
|
@@ -460,6 +472,7 @@ describe Bumbleworks::Task do
|
|
460
472
|
event = Bumbleworks.dashboard.wait_for :dog_mouth
|
461
473
|
task = described_class.for_role('dog_mouth').first
|
462
474
|
task.stub(:completable?).and_return(false)
|
475
|
+
task.stub(:not_completable_error_message).and_return('hogwash!')
|
463
476
|
task.should_receive(:before_update).never
|
464
477
|
task.should_receive(:before_complete).never
|
465
478
|
task.should_receive(:proceed_workitem).never
|
@@ -467,7 +480,7 @@ describe Bumbleworks::Task do
|
|
467
480
|
task.should_receive(:after_update).never
|
468
481
|
expect {
|
469
482
|
task.complete
|
470
|
-
}.to raise_error(Bumbleworks::Task::NotCompletable)
|
483
|
+
}.to raise_error(Bumbleworks::Task::NotCompletable, "hogwash!")
|
471
484
|
described_class.for_role('dog_mouth').should_not be_empty
|
472
485
|
end
|
473
486
|
|
@@ -501,70 +514,5 @@ describe Bumbleworks::Task do
|
|
501
514
|
}
|
502
515
|
end
|
503
516
|
end
|
504
|
-
|
505
|
-
describe '#has_entity_fields?' do
|
506
|
-
it 'returns true if workitem fields include entity fields' do
|
507
|
-
task = described_class.new(workflow_item)
|
508
|
-
task['entity_id'] = '1'
|
509
|
-
task['entity_type'] = 'SomeEntity'
|
510
|
-
task.should have_entity_fields
|
511
|
-
end
|
512
|
-
|
513
|
-
it 'returns false if workitem fields do not include entity fields' do
|
514
|
-
task = described_class.new(workflow_item)
|
515
|
-
task.should_not have_entity_fields
|
516
|
-
end
|
517
|
-
end
|
518
|
-
|
519
|
-
describe '#has_entity?' do
|
520
|
-
it 'returns true if entity is not nil' do
|
521
|
-
task = described_class.new(workflow_item)
|
522
|
-
task.stub(:entity).and_return(:a_real_boy_not_a_puppet)
|
523
|
-
task.has_entity?.should be_true
|
524
|
-
end
|
525
|
-
|
526
|
-
it 'returns false if EntityNotFound' do
|
527
|
-
task = described_class.new(workflow_item)
|
528
|
-
task.stub(:entity).and_raise(Bumbleworks::Task::EntityNotFound)
|
529
|
-
task.has_entity?.should be_false
|
530
|
-
end
|
531
|
-
end
|
532
|
-
|
533
|
-
describe '#entity' do
|
534
|
-
class LovelyEntity
|
535
|
-
def self.first_by_identifier(identifier)
|
536
|
-
return nil unless identifier
|
537
|
-
"Object #{identifier}"
|
538
|
-
end
|
539
|
-
end
|
540
|
-
|
541
|
-
let(:entitied_workflow_item) {
|
542
|
-
Ruote::Workitem.new('fields' => {
|
543
|
-
'entity_id' => '15',
|
544
|
-
'entity_type' => 'LovelyEntity',
|
545
|
-
'params' => {'task' => 'go_to_work'}
|
546
|
-
})
|
547
|
-
}
|
548
|
-
|
549
|
-
it 'attempts to instantiate business entity from _id and _type fields' do
|
550
|
-
task = described_class.new(entitied_workflow_item)
|
551
|
-
task.entity.should == 'Object 15'
|
552
|
-
end
|
553
|
-
|
554
|
-
it 'throw exception if entity fields not present' do
|
555
|
-
task = described_class.new(workflow_item)
|
556
|
-
expect {
|
557
|
-
task.entity
|
558
|
-
}.to raise_error Bumbleworks::Task::EntityNotFound
|
559
|
-
end
|
560
|
-
|
561
|
-
it 'throw exception if entity returns nil' do
|
562
|
-
task = described_class.new(entitied_workflow_item)
|
563
|
-
task['entity_id'] = nil
|
564
|
-
expect {
|
565
|
-
task.entity
|
566
|
-
}.to raise_error Bumbleworks::Task::EntityNotFound
|
567
|
-
end
|
568
|
-
end
|
569
517
|
end
|
570
518
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "bumbleworks/workitem_entity_storage"
|
2
|
+
|
3
|
+
describe Bumbleworks::WorkitemEntityStorage do
|
4
|
+
class FakeEntityHolder
|
5
|
+
include Bumbleworks::WorkitemEntityStorage
|
6
|
+
def initialize(fields = {})
|
7
|
+
@fields = fields
|
8
|
+
end
|
9
|
+
|
10
|
+
def workitem
|
11
|
+
OpenStruct.new(:fields => @fields)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#has_entity_fields?' do
|
16
|
+
it 'returns true if workitem fields include entity fields' do
|
17
|
+
feh = FakeEntityHolder.new('entity_id' => '1', 'entity_type' => 'SomeEntity')
|
18
|
+
feh.should have_entity_fields
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns false if workitem fields do not include entity fields' do
|
22
|
+
feh = FakeEntityHolder.new
|
23
|
+
feh.should_not have_entity_fields
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#has_entity?' do
|
28
|
+
it 'returns true if entity is not nil' do
|
29
|
+
feh = FakeEntityHolder.new
|
30
|
+
feh.stub(:entity).and_return(:a_real_boy_not_a_puppet)
|
31
|
+
feh.has_entity?.should be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns false if EntityNotFound' do
|
35
|
+
feh = FakeEntityHolder.new
|
36
|
+
feh.stub(:entity).and_raise(Bumbleworks::WorkitemEntityStorage::EntityNotFound)
|
37
|
+
feh.has_entity?.should be_false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#entity' do
|
42
|
+
class LovelyEntity
|
43
|
+
def self.first_by_identifier(identifier)
|
44
|
+
return nil unless identifier
|
45
|
+
"Object #{identifier}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
let(:entitied_workflow_item) {
|
50
|
+
Ruote::Workitem.new('fields' => {
|
51
|
+
'entity_id' => '15',
|
52
|
+
'entity_type' => 'LovelyEntity',
|
53
|
+
'params' => {'task' => 'go_to_work'}
|
54
|
+
})
|
55
|
+
}
|
56
|
+
|
57
|
+
it 'attempts to instantiate business entity from _id and _type fields' do
|
58
|
+
feh = FakeEntityHolder.new('entity_id' => '15', 'entity_type' => 'LovelyEntity')
|
59
|
+
feh.entity.should == 'Object 15'
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'throw exception if entity fields not present' do
|
63
|
+
feh = FakeEntityHolder.new
|
64
|
+
expect {
|
65
|
+
feh.entity
|
66
|
+
}.to raise_error Bumbleworks::WorkitemEntityStorage::EntityNotFound
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'throw exception if entity returns nil' do
|
70
|
+
feh = FakeEntityHolder.new('entity_id' => nil, 'entity_type' => 'LovelyEntity')
|
71
|
+
expect {
|
72
|
+
feh.entity
|
73
|
+
}.to raise_error Bumbleworks::WorkitemEntityStorage::EntityNotFound
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bumbleworks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.22
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -168,6 +168,7 @@ files:
|
|
168
168
|
- lib/bumbleworks.rb
|
169
169
|
- lib/bumbleworks/configuration.rb
|
170
170
|
- lib/bumbleworks/hash_storage.rb
|
171
|
+
- lib/bumbleworks/local_participant.rb
|
171
172
|
- lib/bumbleworks/participant_registration.rb
|
172
173
|
- lib/bumbleworks/process_definition.rb
|
173
174
|
- lib/bumbleworks/rake_tasks.rb
|
@@ -180,6 +181,7 @@ files:
|
|
180
181
|
- lib/bumbleworks/tasks/base.rb
|
181
182
|
- lib/bumbleworks/tree_builder.rb
|
182
183
|
- lib/bumbleworks/version.rb
|
184
|
+
- lib/bumbleworks/workitem_entity_storage.rb
|
183
185
|
- lib/tasks/bumbleworks.rake
|
184
186
|
- spec/fixtures/apps/with_default_directories/config_initializer.rb
|
185
187
|
- spec/fixtures/apps/with_default_directories/full_initializer.rb
|
@@ -199,6 +201,7 @@ files:
|
|
199
201
|
- spec/integration/configuration_spec.rb
|
200
202
|
- spec/integration/sample_application_spec.rb
|
201
203
|
- spec/lib/bumbleworks/configuration_spec.rb
|
204
|
+
- spec/lib/bumbleworks/local_participant_spec.rb
|
202
205
|
- spec/lib/bumbleworks/participant_registration_spec.rb
|
203
206
|
- spec/lib/bumbleworks/process_definition_spec.rb
|
204
207
|
- spec/lib/bumbleworks/ruote_spec.rb
|
@@ -207,6 +210,7 @@ files:
|
|
207
210
|
- spec/lib/bumbleworks/support_spec.rb
|
208
211
|
- spec/lib/bumbleworks/task_spec.rb
|
209
212
|
- spec/lib/bumbleworks/tree_builder_spec.rb
|
213
|
+
- spec/lib/bumbleworks/workitem_entity_storage_spec.rb
|
210
214
|
- spec/lib/bumbleworks_spec.rb
|
211
215
|
- spec/spec_helper.rb
|
212
216
|
- spec/support/path_helpers.rb
|
@@ -254,6 +258,7 @@ test_files:
|
|
254
258
|
- spec/integration/configuration_spec.rb
|
255
259
|
- spec/integration/sample_application_spec.rb
|
256
260
|
- spec/lib/bumbleworks/configuration_spec.rb
|
261
|
+
- spec/lib/bumbleworks/local_participant_spec.rb
|
257
262
|
- spec/lib/bumbleworks/participant_registration_spec.rb
|
258
263
|
- spec/lib/bumbleworks/process_definition_spec.rb
|
259
264
|
- spec/lib/bumbleworks/ruote_spec.rb
|
@@ -262,6 +267,7 @@ test_files:
|
|
262
267
|
- spec/lib/bumbleworks/support_spec.rb
|
263
268
|
- spec/lib/bumbleworks/task_spec.rb
|
264
269
|
- spec/lib/bumbleworks/tree_builder_spec.rb
|
270
|
+
- spec/lib/bumbleworks/workitem_entity_storage_spec.rb
|
265
271
|
- spec/lib/bumbleworks_spec.rb
|
266
272
|
- spec/spec_helper.rb
|
267
273
|
- spec/support/path_helpers.rb
|