bumbleworks 0.0.22 → 0.0.23
Sign up to get free protection for your applications and to get access to all the features.
data/lib/bumbleworks/version.rb
CHANGED
@@ -2,13 +2,14 @@ module Bumbleworks
|
|
2
2
|
module WorkitemEntityStorage
|
3
3
|
class EntityNotFound < StandardError; end
|
4
4
|
|
5
|
-
def entity
|
6
|
-
if
|
5
|
+
def entity(options = {})
|
6
|
+
@entity = nil if options[:reload] == true
|
7
|
+
@entity ||= if has_entity_fields?
|
7
8
|
klass = Bumbleworks::Support.constantize(workitem.fields['entity_type'])
|
8
9
|
entity = klass.first_by_identifier(workitem.fields['entity_id'])
|
9
10
|
end
|
10
|
-
raise EntityNotFound unless entity
|
11
|
-
entity
|
11
|
+
raise EntityNotFound unless @entity
|
12
|
+
@entity
|
12
13
|
end
|
13
14
|
|
14
15
|
def has_entity?
|
@@ -39,13 +39,24 @@ describe Bumbleworks::WorkitemEntityStorage do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
describe '#entity' do
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
before :all do
|
43
|
+
class LovelyEntity
|
44
|
+
attr_accessor :identifier
|
45
|
+
def initialize(identifier)
|
46
|
+
@identifier = identifier
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.first_by_identifier(identifier)
|
50
|
+
return nil unless identifier
|
51
|
+
new(identifier)
|
52
|
+
end
|
46
53
|
end
|
47
54
|
end
|
48
55
|
|
56
|
+
after :all do
|
57
|
+
Object.send(:remove_const, :LovelyEntity)
|
58
|
+
end
|
59
|
+
|
49
60
|
let(:entitied_workflow_item) {
|
50
61
|
Ruote::Workitem.new('fields' => {
|
51
62
|
'entity_id' => '15',
|
@@ -56,7 +67,7 @@ describe Bumbleworks::WorkitemEntityStorage do
|
|
56
67
|
|
57
68
|
it 'attempts to instantiate business entity from _id and _type fields' do
|
58
69
|
feh = FakeEntityHolder.new('entity_id' => '15', 'entity_type' => 'LovelyEntity')
|
59
|
-
feh.entity.should == '
|
70
|
+
feh.entity.identifier.should == '15'
|
60
71
|
end
|
61
72
|
|
62
73
|
it 'throw exception if entity fields not present' do
|
@@ -72,5 +83,17 @@ describe Bumbleworks::WorkitemEntityStorage do
|
|
72
83
|
feh.entity
|
73
84
|
}.to raise_error Bumbleworks::WorkitemEntityStorage::EntityNotFound
|
74
85
|
end
|
86
|
+
|
87
|
+
it 'returns same instance when called twice' do
|
88
|
+
feh = FakeEntityHolder.new('entity_id' => '15', 'entity_type' => 'LovelyEntity')
|
89
|
+
feh.entity.identifier = 'pickles'
|
90
|
+
feh.entity.identifier.should == 'pickles'
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'reloads instance when called with reload option' do
|
94
|
+
feh = FakeEntityHolder.new('entity_id' => '15', 'entity_type' => 'LovelyEntity')
|
95
|
+
feh.entity.identifier = 'pickles'
|
96
|
+
feh.entity(:reload => true).identifier.should == '15'
|
97
|
+
end
|
75
98
|
end
|
76
99
|
end
|
@@ -119,13 +119,19 @@ describe Bumbleworks do
|
|
119
119
|
end
|
120
120
|
|
121
121
|
describe '.launch!' do
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
122
|
+
before :all do
|
123
|
+
class LovelyEntity
|
124
|
+
attr_accessor :id
|
125
|
+
def initialize(id)
|
126
|
+
@id = id
|
127
|
+
end
|
126
128
|
end
|
127
129
|
end
|
128
130
|
|
131
|
+
after :all do
|
132
|
+
Object.send(:remove_const, :LovelyEntity)
|
133
|
+
end
|
134
|
+
|
129
135
|
it 'delegates to Bumbleworks::Ruote.launch' do
|
130
136
|
Bumbleworks::Ruote.should_receive(:launch).with(:amazing_process, :hugs => :love)
|
131
137
|
Bumbleworks.launch!(:amazing_process, :hugs => :love)
|