bumbleworks 0.0.56 → 0.0.57

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 CHANGED
@@ -183,12 +183,12 @@ module Bumbleworks
183
183
  def extract_entity_from_fields!(fields)
184
184
  begin
185
185
  if entity = fields.delete(:entity)
186
- fields[:entity_id] = entity.respond_to?(:identifier) ? entity.identifier : entity.id
186
+ fields[:entity_id] = entity.identifier
187
187
  fields[:entity_type] = entity.class.name
188
- raise InvalidEntity, "Entity#id must be non-null" unless fields[:entity_id]
188
+ raise InvalidEntity, "Entity#identifier must be non-null" unless fields[:entity_id]
189
189
  end
190
190
  rescue NoMethodError => e
191
- raise InvalidEntity, "Entity must respond to #identifier (or #id) and #class.name"
191
+ raise InvalidEntity, "Entity must respond to #identifier and #class.name"
192
192
  end
193
193
  end
194
194
  end
@@ -4,6 +4,14 @@ module Bumbleworks
4
4
  klass.extend ClassMethods
5
5
  end
6
6
 
7
+ def identifier
8
+ id
9
+ end
10
+
11
+ def to_s
12
+ "#{Bumbleworks::Support.titleize(self.class.name)} #{identifier}"
13
+ end
14
+
7
15
  def launch_process(process_name, options = {})
8
16
  identifier_attribute = attribute_for_process_name(process_name.to_sym)
9
17
  if (options[:force] == true || (process_identifier = self.send(identifier_attribute)).nil?)
@@ -76,10 +76,9 @@ module Bumbleworks
76
76
  end
77
77
 
78
78
  def for_entity(entity)
79
- entity_id = entity.respond_to?(:identifier) ? entity.identifier : entity.id
80
79
  @queries << proc { |wi|
81
80
  (wi['fields'][:entity_type] || wi['fields']['entity_type']) == entity.class.name &&
82
- (wi['fields'][:entity_id] || wi['fields']['entity_id']) == entity_id
81
+ (wi['fields'][:entity_id] || wi['fields']['entity_id']) == entity.identifier
83
82
  }
84
83
  self
85
84
  end
@@ -1,3 +1,3 @@
1
1
  module Bumbleworks
2
- VERSION = "0.0.56"
2
+ VERSION = "0.0.57"
3
3
  end
@@ -1,6 +1,23 @@
1
1
  describe Bumbleworks::Entity do
2
2
  let(:entity_class) { Class.new { include Bumbleworks::Entity } }
3
3
 
4
+ describe '#identifier' do
5
+ it 'returns id by default' do
6
+ entity = entity_class.new
7
+ entity.stub(:id => 'berf')
8
+ entity.identifier.should == 'berf'
9
+ end
10
+ end
11
+
12
+ describe '#to_s' do
13
+ it 'returns string with titleized class name and identifier' do
14
+ entity_class.stub(:name => 'GiantAngryPlum')
15
+ entity = entity_class.new
16
+ entity.stub(:identifier => 1490)
17
+ entity.to_s.should == 'Giant Angry Plum 1490'
18
+ end
19
+ end
20
+
4
21
  describe '#processes_by_name' do
5
22
  it 'returns hash of process names and process instances' do
6
23
  [:zoom, :foof, :nook].each do |pname|
@@ -552,20 +552,6 @@ describe Bumbleworks::Task do
552
552
  tasks = described_class.for_entity(fake_sandwich)
553
553
  tasks.should have(2).items
554
554
  end
555
-
556
- it 'queries for id if entity does not respond to identifier' do
557
- fake_mauvebelt = OpenStruct.new(:id => 'television_hat')
558
- Bumbleworks.define_process 'tautological_mauvebelt' do
559
- concurrence do
560
- mauvebelt :task => 'wear_oneself'
561
- mauvebelt :task => 'be_worn_by_oneself'
562
- end
563
- end
564
- Bumbleworks.launch!('tautological_mauvebelt', :entity => fake_mauvebelt)
565
- Bumbleworks.dashboard.wait_for(:mauvebelt)
566
- tasks = described_class.for_entity(fake_mauvebelt)
567
- tasks.should have(2).items
568
- end
569
555
  end
570
556
 
571
557
  context '.by_nickname' do
@@ -193,9 +193,9 @@ describe Bumbleworks do
193
193
  describe '.launch!' do
194
194
  before :all do
195
195
  class LovelyEntity
196
- attr_accessor :id
197
- def initialize(id)
198
- @id = id
196
+ attr_accessor :identifier
197
+ def initialize(identifier)
198
+ @identifier = identifier
199
199
  end
200
200
  end
201
201
  end
@@ -219,13 +219,6 @@ describe Bumbleworks do
219
219
  Bumbleworks.launch!(:amazing_process, { :entity => LovelyEntity.new(:wiley_e_coyote) }, :et_cetera)
220
220
  end
221
221
 
222
- it 'uses "identifier" method instead of id, if entity has one' do
223
- entity = LovelyEntity.new(5)
224
- entity.stub(:identifier).and_return(:five)
225
- Bumbleworks::Ruote.should_receive(:launch).with(:amazing_process, :entity_id => :five, :entity_type => 'LovelyEntity')
226
- Bumbleworks.launch!(:amazing_process, :entity => entity)
227
- end
228
-
229
222
  it 'returns a Bumbleworks::Process instance with the wfid of the launched process' do
230
223
  Bumbleworks::Ruote.stub(:launch).with(:amazing_process).and_return('18181818')
231
224
  bp = Bumbleworks.launch!(:amazing_process)
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.56
4
+ version: 0.0.57
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-01-21 00:00:00.000000000 Z
15
+ date: 2014-01-22 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: ruote
@@ -262,7 +262,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
262
262
  version: '0'
263
263
  segments:
264
264
  - 0
265
- hash: 1303608967349520599
265
+ hash: 855634540597559898
266
266
  required_rubygems_version: !ruby/object:Gem::Requirement
267
267
  none: false
268
268
  requirements:
@@ -271,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
271
271
  version: '0'
272
272
  segments:
273
273
  - 0
274
- hash: 1303608967349520599
274
+ hash: 855634540597559898
275
275
  requirements: []
276
276
  rubyforge_project:
277
277
  rubygems_version: 1.8.23