spec/seam/worker_spec.rb in seam-0.0.15 vs spec/seam/worker_spec.rb in seam-0.0.16
- old
+ new
@@ -18,29 +18,85 @@
worker.step.must_equal "darren"
end
end
describe "move_to_next_step" do
- it "should work" do
- flow = Seam::Flow.new
- flow.apple
- flow.orange
- effort = flow.start( { first_name: 'John' } )
- effort = Seam::Effort.find(effort.id)
+ [:date].to_objects {[
+ ['1/1/2011'],
+ ['3/4/2015']
+ ]}.each do |test|
+
+ describe "move immediately" do
- effort.next_step.must_equal "apple"
+ before { Timecop.freeze Time.parse(test.date) }
+ after { Timecop.return }
- apple_worker = Seam::Worker.new
- apple_worker.handles(:apple)
- def apple_worker.process
- move_to_next_step
+ it "should move to the next step and set the date to now" do
+ flow = Seam::Flow.new
+ flow.apple
+ flow.orange
+
+ effort = flow.start( { first_name: 'John' } )
+ effort = Seam::Effort.find(effort.id)
+
+ effort.next_step.must_equal "apple"
+
+ apple_worker = Seam::Worker.new
+ apple_worker.handles(:apple)
+ def apple_worker.process
+ move_to_next_step
+ end
+
+ apple_worker.execute effort
+
+ effort = Seam::Effort.find(effort.id)
+ effort.next_step.must_equal "orange"
+ effort.next_execute_at.must_equal Time.parse(test.date)
+ end
+
end
- apple_worker.execute effort
+ end
- effort = Seam::Effort.find(effort.id)
- effort.next_step.must_equal "orange"
+ [:date, :next_date].to_objects {[
+ ['1/1/2011', '2/1/2011'],
+ ['1/1/2011', '2/2/2011'],
+ ['3/4/2015', '4/5/2016']
+ ]}.each do |test|
+
+ describe "move to some point in the future" do
+
+ before { Timecop.freeze Time.parse(test.date) }
+ after { Timecop.return }
+
+ it "should move to the next step and set the date to now" do
+ flow = Seam::Flow.new
+ flow.apple
+ flow.orange
+
+ effort = flow.start( { first_name: 'John' } )
+ effort = Seam::Effort.find(effort.id)
+
+ effort.next_step.must_equal "apple"
+
+ apple_worker = Seam::Worker.new
+ apple_worker.handles(:apple)
+ eval("
+ def apple_worker.process
+ move_to_next_step( { on: Time.parse('#{test.next_date}') } )
+ end
+ ")
+
+ apple_worker.execute effort
+
+ effort = Seam::Effort.find(effort.id)
+ effort.next_step.must_equal "orange"
+ effort.next_execute_at.must_equal Time.parse(test.next_date)
+ end
+
+ end
+
end
end
describe "move_to_next_step as a default" do
it "should go to move_to_next_step by default" do