seam 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
data/lib/seam/flow.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  module Seam
2
2
  class Flow
3
3
 
4
+ attr_accessor :stamp_data_history
5
+
4
6
  def initialize
5
7
  @steps = []
8
+ @stamp_data_history = false
6
9
  end
7
10
 
8
11
  def method_missing(meth, *args, &blk)
@@ -23,7 +26,10 @@ module Seam
23
26
  end
24
27
 
25
28
  def to_hash
26
- { steps: self.steps.map { |x| x.to_hash } }
29
+ {
30
+ steps: self.steps.map { |x| x.to_hash },
31
+ stamp_data_history: @stamp_data_history
32
+ }
27
33
  end
28
34
 
29
35
  def steps
data/lib/seam/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Seam
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  end
data/lib/seam/worker.rb CHANGED
@@ -98,7 +98,7 @@ module Seam
98
98
  run = {
99
99
  started_at: Time.now,
100
100
  step: step,
101
- data_before: effort.data.clone
101
+ data_before: stamping_the_history? ? effort.data.clone : nil
102
102
  }
103
103
  @current_run = HashWithIndifferentAccess.new run
104
104
  end
@@ -120,12 +120,19 @@ module Seam
120
120
 
121
121
  def stamp_the_new_history_record
122
122
  history[:result] = @operation_to_execute
123
- history[:data_after] = effort.data.clone
124
123
  history[:stopped_at] = Time.now
125
124
 
125
+ if stamping_the_history?
126
+ history[:data_after] = effort.data.clone
127
+ end
128
+
126
129
  effort.history << history
127
130
  end
128
131
 
132
+ def stamping_the_history?
133
+ effort.flow['stamp_data_history']
134
+ end
135
+
129
136
  def save_the_effort
130
137
  effort.save
131
138
  end
@@ -129,4 +129,36 @@ describe "flow" do
129
129
  end
130
130
  end
131
131
  end
132
+
133
+ describe "stamping history" do
134
+ describe "default" do
135
+ it "should should be false" do
136
+ flow = Seam::Flow.new
137
+ flow.stamp_data_history.must_equal false
138
+ end
139
+ end
140
+
141
+ describe "setting it to true" do
142
+ it "allow to be set to true" do
143
+ flow = Seam::Flow.new
144
+ flow.stamp_data_history = true
145
+ flow.stamp_data_history.must_equal true
146
+ end
147
+ end
148
+
149
+ describe "carrying the value through the serialization" do
150
+
151
+ it "should be able to persist false" do
152
+ flow = Seam::Flow.new
153
+ flow.stamp_data_history = false
154
+ flow.to_hash[:stamp_data_history].must_equal false
155
+ end
156
+
157
+ it "should be able to persist true" do
158
+ flow = Seam::Flow.new
159
+ flow.stamp_data_history = true
160
+ flow.to_hash[:stamp_data_history].must_equal true
161
+ end
162
+ end
163
+ end
132
164
  end
@@ -4,6 +4,7 @@ describe "worker" do
4
4
 
5
5
  before do
6
6
  Seam::Persistence.destroy
7
+ @stamp_data_history = true
7
8
  end
8
9
 
9
10
  after do
@@ -260,6 +261,7 @@ describe "worker" do
260
261
  let(:effort_creator) do
261
262
  ->() do
262
263
  e = flow.start
264
+ flow.stamp_data_history = @stamp_data_history
263
265
  Seam::Effort.find(e.id)
264
266
  end
265
267
  end
@@ -550,8 +552,6 @@ describe "worker" do
550
552
  "started_at"=> Time.now,
551
553
  "step"=>"wait_for_attempting_contact_stage",
552
554
  "stopped_at" => Time.now,
553
- "data_before" => { "first_name" => "DARREN" } ,
554
- "data_after" => { "first_name" => "DARREN", "hit 1" => 1 }
555
555
  } )
556
556
 
557
557
  send_postcard_if_necessary_worker.execute_all
@@ -735,6 +735,85 @@ describe "worker" do
735
735
  orange_worker.execute_all
736
736
  end
737
737
  end
738
+
739
+ describe "data history" do
740
+ describe "stamping the history" do
741
+ let(:effort) do
742
+ flow = Seam::Flow.new
743
+ flow.stamp_data_history = true
744
+ flow.apple
745
+
746
+ e = flow.start( { first_name: 'John' } )
747
+ Seam::Effort.find(e.id)
748
+ end
749
+
750
+ before do
751
+ Timecop.freeze Time.parse('3/4/2013')
752
+ effort.next_step.must_equal "apple"
753
+
754
+ apple_worker = Seam::Worker.new
755
+ apple_worker.handles(:apple)
756
+ def apple_worker.process
757
+ effort.data['something'] = 'else'
758
+ end
759
+
760
+ apple_worker.execute effort
761
+ end
762
+
763
+ it "should not update the next step" do
764
+ fresh_effort = Seam::Effort.find(effort.id)
765
+ fresh_effort.history.count.must_equal 1
766
+ end
767
+
768
+ it "should set the data_before history" do
769
+ fresh_effort = Seam::Effort.find(effort.id)
770
+ fresh_effort.history.first["data_before"].must_equal( { "first_name" => 'John' } )
771
+ end
772
+
773
+ it "should set the data_after history" do
774
+ fresh_effort = Seam::Effort.find(effort.id)
775
+ fresh_effort.history.first["data_after"].must_equal( { "first_name" => 'John', "something" => 'else' } )
776
+ end
777
+ end
778
+
779
+ describe "not stamping the history" do
780
+ let(:effort) do
781
+ flow = Seam::Flow.new
782
+ flow.stamp_data_history = false
783
+ flow.apple
784
+
785
+ e = flow.start( { first_name: 'John' } )
786
+ Seam::Effort.find(e.id)
787
+ end
788
+
789
+ before do
790
+ Timecop.freeze Time.parse('3/4/2013')
791
+
792
+ apple_worker = Seam::Worker.new
793
+ apple_worker.handles(:apple)
794
+ def apple_worker.process
795
+ effort.data['something'] = 'else'
796
+ end
797
+
798
+ apple_worker.execute effort
799
+ end
800
+
801
+ it "should not update the next step" do
802
+ fresh_effort = Seam::Effort.find(effort.id)
803
+ fresh_effort.history.count.must_equal 1
804
+ end
805
+
806
+ it "should set the data_before history" do
807
+ fresh_effort = Seam::Effort.find(effort.id)
808
+ fresh_effort.history.first["data_before"].nil?.must_equal true
809
+ end
810
+
811
+ it "should set the data_after history" do
812
+ fresh_effort = Seam::Effort.find(effort.id)
813
+ fresh_effort.history.first["data_after"].nil?.must_equal true
814
+ end
815
+ end
816
+ end
738
817
  end
739
818
 
740
819
  class IWillNotCallHandlesWorker < Seam::Worker
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-29 00:00:00.000000000 Z
12
+ date: 2013-09-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -228,7 +228,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
228
228
  version: '0'
229
229
  segments:
230
230
  - 0
231
- hash: 2234950607663767066
231
+ hash: -3794428632218759846
232
232
  required_rubygems_version: !ruby/object:Gem::Requirement
233
233
  none: false
234
234
  requirements:
@@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
237
  version: '0'
238
238
  segments:
239
239
  - 0
240
- hash: 2234950607663767066
240
+ hash: -3794428632218759846
241
241
  requirements: []
242
242
  rubyforge_project:
243
243
  rubygems_version: 1.8.25