bumbleworks 0.0.87 → 0.0.88

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ddb99ff7e81ef79f450c5888713b862a3dd85673
4
- data.tar.gz: 5b3de42cac468a392998375432725b33d1bbf501
3
+ metadata.gz: 8e7f5891aaff2d00d0129acf222c6a1ee06c74e2
4
+ data.tar.gz: 59288f755a48cd12069cbbe898037fde62cbfb2e
5
5
  SHA512:
6
- metadata.gz: b91712d329d034b868e3aa1579d7b2a84ec4eab9bea15aea43e72ff1c9187ee3546d3c1e36d53d3f12c7095d246b8d592c3903126f9ca2b9b49057f0f3147f09
7
- data.tar.gz: ff019980495f03d0c3622329cc8d3e9f3d7e516758b329ef49ac8ac287d2b3d462887179d39ccc59dc6003f2fc4afb06f6b89eb92ef2941c7816bb7f7f9efc12
6
+ metadata.gz: 3ec00ab19a09a29fe07dcf810282c0ad40ab83e0bfb876d491c7b9fb6f01c32022d39c0924bca8b9d49b3b674b67e6e2e1fca678a2b1e7eaad751f8410541673
7
+ data.tar.gz: 4c889ebea8ed536c90c16f0660030837c7f29c4c70b62a75d70762f9e12ac61979537dcb14730150e894c16356d62a0af0709ac6122620931bfff696f20a1b3b
@@ -2,6 +2,7 @@ require "forwardable"
2
2
  require "bumbleworks/version"
3
3
  require "bumbleworks/configuration"
4
4
  require "bumbleworks/support"
5
+ require "bumbleworks/support/wrapper_comparison"
5
6
  require "bumbleworks/process_definition"
6
7
  require "bumbleworks/process"
7
8
  require "bumbleworks/expression"
@@ -1,6 +1,9 @@
1
1
  module Bumbleworks
2
2
  class Expression
3
+ include Support::WrapperComparison
4
+
3
5
  attr_reader :expid, :fei
6
+ alias_method :id, :expid
4
7
 
5
8
  class << self
6
9
  def from_fei(fei)
@@ -15,11 +18,6 @@ module Bumbleworks
15
18
  @expid = @fei.expid
16
19
  end
17
20
 
18
- def ==(other)
19
- return false unless other.is_a?(self.class)
20
- @fei == other.fei
21
- end
22
-
23
21
  # Returns a Bumbleworks::Process instance for the expression's
24
22
  # wfid; effectively, the process instance this expression is
25
23
  # a part of.
@@ -6,6 +6,7 @@ module Bumbleworks
6
6
  class EntityConflict < StandardError; end
7
7
 
8
8
  include WorkitemEntityStorage
9
+ include Support::WrapperComparison
9
10
 
10
11
  attr_reader :id
11
12
 
@@ -53,11 +54,6 @@ module Bumbleworks
53
54
  wfid <=> other.wfid
54
55
  end
55
56
 
56
- def ==(other)
57
- return false unless other.is_a?(self.class)
58
- wfid == other.wfid
59
- end
60
-
61
57
  def entity_workitem
62
58
  @entity_workitem ||= if workitems.map(&:entity_fields).uniq.length <= 1
63
59
  workitems.first
@@ -1,6 +1,7 @@
1
1
  module Bumbleworks
2
2
  class Schedule
3
3
  attr_reader :id, :original_hash
4
+ include Support::WrapperComparison
4
5
 
5
6
  class << self
6
7
  def all
@@ -19,11 +20,6 @@ module Bumbleworks
19
20
  @id = @original_hash['_id']
20
21
  end
21
22
 
22
- def ==(other)
23
- return false unless other.is_a?(self.class)
24
- @id == other.id
25
- end
26
-
27
23
  def wfid
28
24
  @original_hash['wfid']
29
25
  end
@@ -0,0 +1,23 @@
1
+ module Bumbleworks
2
+ module Support
3
+ module WrapperComparison
4
+ def identifier_for_comparison
5
+ id
6
+ end
7
+
8
+ def hash
9
+ identifier_for_comparison.hash
10
+ end
11
+
12
+ def ==(other)
13
+ other.is_a?(self.class) &&
14
+ identifier_for_comparison &&
15
+ identifier_for_comparison == other.identifier_for_comparison
16
+ end
17
+
18
+ def eql?(other)
19
+ self == other
20
+ end
21
+ end
22
+ end
23
+ end
@@ -5,6 +5,7 @@ require "bumbleworks/task/finder"
5
5
  module Bumbleworks
6
6
  class Task
7
7
  include WorkitemEntityStorage
8
+ include Support::WrapperComparison
8
9
 
9
10
  class AlreadyClaimed < StandardError; end
10
11
  class MissingWorkitem < StandardError; end
@@ -1,6 +1,7 @@
1
1
  module Bumbleworks
2
2
  class Tracker
3
3
  attr_reader :id, :original_hash
4
+ include Support::WrapperComparison
4
5
 
5
6
  class << self
6
7
  def all
@@ -1,3 +1,3 @@
1
1
  module Bumbleworks
2
- VERSION = "0.0.87"
2
+ VERSION = "0.0.88"
3
3
  end
@@ -1,14 +1,17 @@
1
1
  module Bumbleworks
2
2
  class Workitem
3
+ include Support::WrapperComparison
4
+
3
5
  attr_reader :raw_workitem
4
6
 
7
+ extend Forwardable
8
+
5
9
  def initialize(raw_workitem)
6
10
  @raw_workitem = raw_workitem
7
11
  end
8
12
 
9
- def ==(other)
10
- return false unless other.is_a?(self.class)
11
- raw_workitem == other.raw_workitem
13
+ def identifier_for_comparison
14
+ raw_workitem
12
15
  end
13
16
 
14
17
  def entity(options = {})
@@ -11,24 +11,9 @@ describe Bumbleworks::Expression do
11
11
  end
12
12
  end
13
13
 
14
- describe '#==' do
15
- it 'returns true if other object has same flow expression id' do
16
- exp1 = described_class.new(fexp)
17
- exp2 = described_class.new(double('FlowExpression', :fei => fei))
18
- expect(exp1).to eq(exp2)
19
- end
20
-
21
- it 'returns false if other object has different flow expression id' do
22
- exp1 = described_class.new(fexp)
23
- exp2 = described_class.new(double('FlowExpression', :fei => double(:expid => '4')))
24
- expect(exp1).not_to eq(exp2)
25
- end
26
-
27
- it 'returns false if other object has is not an expression' do
28
- exp1 = described_class.new(fexp)
29
- exp2 = double('not an expression')
30
- expect(exp1).not_to eq(exp2)
31
- end
14
+ it_behaves_like "comparable" do
15
+ subject { described_class.new(fexp) }
16
+ let(:other) { described_class.new(fexp) }
32
17
  end
33
18
 
34
19
  describe '#expid' do
@@ -36,6 +36,11 @@ describe Bumbleworks::Process do
36
36
  end
37
37
  end
38
38
 
39
+ it_behaves_like "comparable" do
40
+ subject { described_class.new('watchful_egret') }
41
+ let(:other) { described_class.new('lets_dance_yo') }
42
+ end
43
+
39
44
  describe '.all' do
40
45
  it 'returns sorted and filtered array of instances for all processes' do
41
46
  expect(described_class).to receive(:ids).with(:some_options).and_return([:a, :b, :c])
@@ -8,6 +8,11 @@ describe Bumbleworks::Schedule do
8
8
  allow(Bumbleworks.dashboard).to receive_messages(:schedules => fake_schedules)
9
9
  end
10
10
 
11
+ it_behaves_like "comparable" do
12
+ subject { described_class.new({ '_id' => 'fooz'}) }
13
+ let(:other) { described_class.new({ '_id' => 'barn'}) }
14
+ end
15
+
11
16
  describe '.all' do
12
17
  it 'returns instances for each schedule in system' do
13
18
  schedules = described_class.all
@@ -33,26 +38,6 @@ describe Bumbleworks::Schedule do
33
38
  end
34
39
  end
35
40
 
36
- describe '#==' do
37
- it 'returns true if other object has same original hash _id' do
38
- schedule1 = described_class.new({ '_id' => 'snaggletooth', 'who' => 'cares' })
39
- schedule2 = described_class.new({ '_id' => 'snaggletooth', 'yeah' => 'whatevs' })
40
- expect(schedule1).to eq(schedule2)
41
- end
42
-
43
- it 'returns false if other object has different original hash _id' do
44
- schedule1 = described_class.new({ '_id' => 'snaggletooth', 'who' => 'cares' })
45
- schedule2 = described_class.new({ '_id' => 'snooglebunk', 'yeah' => 'whatevs' })
46
- expect(schedule1).not_to eq(schedule2)
47
- end
48
-
49
- it 'returns false if other object is not a schedule' do
50
- schedule1 = described_class.new({ '_id' => 'snaggletooth', 'who' => 'cares' })
51
- schedule2 = double('not a schedule')
52
- expect(schedule1).not_to eq(schedule2)
53
- end
54
- end
55
-
56
41
  describe '#wfid' do
57
42
  it 'returns wfid from original hash' do
58
43
  expect(subject.wfid).to eq(fake_schedule['wfid'])
@@ -18,6 +18,14 @@ describe Bumbleworks::Task do
18
18
  let(:storage_workitem) { Bumbleworks::Workitem.new(workflow_item) }
19
19
  end
20
20
 
21
+ it_behaves_like "comparable" do
22
+ subject { described_class.new(workflow_item) }
23
+ let(:other) { described_class.new(workflow_item) }
24
+ before(:each) do
25
+ allow(workflow_item).to receive(:sid).and_return('blah-123-blah')
26
+ end
27
+ end
28
+
21
29
  describe '#not_completable_error_message' do
22
30
  it 'defaults to generic message' do
23
31
  task = described_class.new(workflow_item)
@@ -5,6 +5,11 @@ describe Bumbleworks::Tracker do
5
5
  allow(Bumbleworks.dashboard).to receive_messages(:get_trackers => fake_trackers)
6
6
  end
7
7
 
8
+ it_behaves_like "comparable" do
9
+ subject { described_class.new('a_tracker') }
10
+ let(:other) { described_class.new('another_tracker') }
11
+ end
12
+
8
13
  describe '.all' do
9
14
  it 'returns instances for each tracker in system' do
10
15
  trackers = described_class.all
@@ -2,118 +2,109 @@ require File.expand_path(File.join(fixtures_path, 'entities', 'rainbow_loom'))
2
2
 
3
3
  describe Bumbleworks::Workitem do
4
4
  let(:ruote_workitem) { Ruote::Workitem.new('fields' => {'entity_id' => '123', 'entity_type' => 'RainbowLoom'} ) }
5
- let(:workitem) { Bumbleworks::Workitem.new(ruote_workitem)}
5
+ subject { described_class.new(ruote_workitem) }
6
6
 
7
- describe '#==' do
8
- it 'returns true if other object has same raw workitem' do
9
- bw1 = described_class.new('in_da_sky')
10
- bw2 = described_class.new('in_da_sky')
11
- expect(bw1).to eq(bw2)
12
- end
13
-
14
- it 'returns false if other object is not a workitem' do
15
- bw1 = described_class.new('in_da_sky')
16
- bw2 = double('not a workitem')
17
- expect(bw1).not_to eq(bw2)
18
- end
7
+ it_behaves_like "comparable" do
8
+ subject { described_class.new(ruote_workitem) }
9
+ let(:other) { described_class.new(ruote_workitem) }
19
10
  end
20
11
 
21
12
  describe '#has_entity_fields?' do
22
13
  it 'returns true if workitem fields include entity fields' do
23
- expect(workitem).to have_entity_fields
14
+ expect(subject).to have_entity_fields
24
15
  end
25
16
 
26
17
  it 'returns true if workitem fields include symbolized version of entity fields' do
27
18
  ruote_workitem.fields = { :entity_id => '123', :entity_type => 'RainbowLoom' }
28
- expect(workitem).to have_entity_fields
19
+ expect(subject).to have_entity_fields
29
20
  end
30
21
 
31
22
  it 'returns false if workitem fields do not include entity fields' do
32
23
  ruote_workitem.fields = {}
33
- expect(workitem).not_to have_entity_fields
24
+ expect(subject).not_to have_entity_fields
34
25
  end
35
26
  end
36
27
 
37
28
  describe '#has_entity?' do
38
29
  it 'returns true if entity is not nil' do
39
- allow(workitem).to receive(:entity).and_return(:a_real_boy_not_a_puppet)
40
- expect(workitem.has_entity?).to be_truthy
30
+ allow(subject).to receive(:entity).and_return(:a_real_boy_not_a_puppet)
31
+ expect(subject.has_entity?).to be_truthy
41
32
  end
42
33
 
43
34
  it 'returns false if EntityNotFound' do
44
- allow(workitem).to receive(:entity).and_raise(Bumbleworks::EntityNotFound)
45
- expect(workitem.has_entity?).to be_falsy
35
+ allow(subject).to receive(:entity).and_raise(Bumbleworks::EntityNotFound)
36
+ expect(subject.has_entity?).to be_falsy
46
37
  end
47
38
  end
48
39
 
49
40
  describe '#entity' do
50
41
  it 'attempts to instantiate business entity from _id and _type fields' do
51
- expect(workitem.entity.identifier).to eq('123')
42
+ expect(subject.entity.identifier).to eq('123')
52
43
  end
53
44
 
54
45
  it 'works with symbolized _id and _type fields' do
55
46
  ruote_workitem.fields = { :entity_id => '125', :entity_type => 'RainbowLoom' }
56
- expect(workitem.entity.identifier).to eq('125')
47
+ expect(subject.entity.identifier).to eq('125')
57
48
  end
58
49
 
59
50
  it 'throw exception if entity fields not present' do
60
51
  ruote_workitem.fields = {}
61
52
  expect {
62
- workitem.entity
53
+ subject.entity
63
54
  }.to raise_error Bumbleworks::EntityNotFound
64
55
  end
65
56
 
66
57
  it 'throw exception if entity returns nil' do
67
58
  ruote_workitem.fields['entity_id'] = nil
68
59
  expect {
69
- workitem.entity
60
+ subject.entity
70
61
  }.to raise_error Bumbleworks::EntityNotFound, '{:entity_id=>nil, :entity_type=>"RainbowLoom"}'
71
62
  end
72
63
 
73
64
  it 'returns same instance when called twice' do
74
- workitem.entity.identifier = 'nerfus'
75
- expect(workitem.entity.identifier).to eq('nerfus')
65
+ subject.entity.identifier = 'nerfus'
66
+ expect(subject.entity.identifier).to eq('nerfus')
76
67
  end
77
68
 
78
69
  it 'reloads instance when called with reload option' do
79
- workitem.entity.identifier = 'pickles'
80
- expect(workitem.entity(:reload => true).identifier).to eq('123')
70
+ subject.entity.identifier = 'pickles'
71
+ expect(subject.entity(:reload => true).identifier).to eq('123')
81
72
  end
82
73
  end
83
74
 
84
75
  describe '#tokenized_entity_type' do
85
76
  it 'returns tokenized entity type' do
86
- expect(workitem.tokenized_entity_type).to eq('rainbow_loom')
77
+ expect(subject.tokenized_entity_type).to eq('rainbow_loom')
87
78
  end
88
79
 
89
80
  it 'returns nil if no entity type' do
90
- allow(workitem).to receive(:entity_type).and_return(nil)
91
- expect(workitem.tokenized_entity_type).to be_nil
81
+ allow(subject).to receive(:entity_type).and_return(nil)
82
+ expect(subject.tokenized_entity_type).to be_nil
92
83
  end
93
84
  end
94
85
 
95
86
  describe "#entity_fields" do
96
87
  it 'returns empty hash if no entity' do
97
88
  ruote_workitem.fields = {}
98
- expect(workitem.entity_fields).to eq({})
89
+ expect(subject.entity_fields).to eq({})
99
90
  end
100
91
 
101
92
  it 'returns class name and identifier by default' do
102
- expect(workitem.entity_fields).to eq({ :type => 'RainbowLoom', :identifier => '123' })
93
+ expect(subject.entity_fields).to eq({ :type => 'RainbowLoom', :identifier => '123' })
103
94
  end
104
95
 
105
96
  it 'humanizes class name when requested' do
106
- expect(workitem.entity_fields(:humanize => true)).to eq({ :type => 'Rainbow loom', :identifier => '123' })
97
+ expect(subject.entity_fields(:humanize => true)).to eq({ :type => 'Rainbow loom', :identifier => '123' })
107
98
  end
108
99
 
109
100
  it 'titleizes class name when requested' do
110
- expect(workitem.entity_fields(:titleize => true)).to eq({ :type => 'Rainbow Loom', :identifier => '123' })
101
+ expect(subject.entity_fields(:titleize => true)).to eq({ :type => 'Rainbow Loom', :identifier => '123' })
111
102
  end
112
103
  end
113
104
 
114
105
  describe "#entity_name" do
115
106
  it 'returns entity fields in displayable string' do
116
- expect(workitem.entity_name).to eq('Rainbow Loom 123')
107
+ expect(subject.entity_name).to eq('Rainbow Loom 123')
117
108
  end
118
109
  end
119
110
  end
@@ -13,4 +13,38 @@ shared_examples "an entity holder" do
13
13
  expect(holder.entity_storage_workitem).to eq(storage_workitem)
14
14
  end
15
15
  end
16
- end
16
+ end
17
+
18
+ shared_examples "comparable" do
19
+ describe "#hash" do
20
+ it 'returns hash of identifier_for_comparison' do
21
+ expect(subject.hash).to eq(subject.identifier_for_comparison.hash)
22
+ end
23
+ end
24
+
25
+ describe '#==' do
26
+ it 'returns true if identifier_for_comparison values are equal' do
27
+ allow(other).to receive(:identifier_for_comparison).
28
+ and_return(subject.identifier_for_comparison)
29
+ expect(subject).to be == other
30
+ end
31
+
32
+ it 'returns false if other is different class' do
33
+ different_classed_instance = double('whatever', :identifier_for_comparison => subject.identifier_for_comparison)
34
+ expect(subject).not_to be == different_classed_instance
35
+ end
36
+
37
+ it 'returns false if identifier_for_comparison is nil' do
38
+ allow(other).to receive(:identifier_for_comparison).and_return(nil)
39
+ allow(subject).to receive(:identifier_for_comparison).and_return(nil)
40
+ expect(subject).not_to be == other
41
+ end
42
+ end
43
+
44
+ describe '#eql?' do
45
+ it 'aliases to ==' do
46
+ expect(subject).to receive(:==).with(other)
47
+ subject.eql?(other)
48
+ end
49
+ end
50
+ 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.87
4
+ version: 0.0.88
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maher Hawash
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-09-26 00:00:00.000000000 Z
14
+ date: 2014-09-30 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: ruote
@@ -174,6 +174,7 @@ files:
174
174
  - lib/bumbleworks/storage_adapter.rb
175
175
  - lib/bumbleworks/support.rb
176
176
  - lib/bumbleworks/support/flow_expression.rb
177
+ - lib/bumbleworks/support/wrapper_comparison.rb
177
178
  - lib/bumbleworks/task.rb
178
179
  - lib/bumbleworks/task/base.rb
179
180
  - lib/bumbleworks/task/finder.rb