Module: Dynflow::Testing::Factories

Includes:
Algebrick::TypeCheck
Included in:
Dynflow::Testing
Defined in:
lib/dynflow/testing/factories.rb

Instance Method Summary collapse

Instance Method Details

#create_action(action_class, trigger = nil) ⇒ Action::PlanPhase

Returns:

  • (Action::PlanPhase)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dynflow/testing/factories.rb', line 7

def create_action(action_class, trigger = nil)
  execution_plan = DummyExecutionPlan.new
  step           = DummyStep.new
  action_class.new(
      { step:              DummyStep.new,
        execution_plan_id: execution_plan.id,
        id:                Testing.get_id,
        phase:             Action::Plan,
        plan_step_id:      step.id,
        run_step_id:       nil,
        finalize_step_id:  nil },
      execution_plan.world).tap do |action|
    action.set_plan_context(execution_plan, trigger, false)
  end
end

#create_action_presentation(action_class) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dynflow/testing/factories.rb', line 23

def create_action_presentation(action_class)
  execution_plan = DummyExecutionPlan.new
  action_class.new(
      { execution_plan:    execution_plan,
        execution_plan_id: execution_plan.id,
        id:                Testing.get_id,
        phase:             Action::Present,
        plan_step_id:      1,
        run_step_id:       nil,
        finalize_step_id:  nil,
        input:             nil },
      execution_plan.world)
end

#create_and_plan_action(action_class, *args, &block) ⇒ Object



46
47
48
# File 'lib/dynflow/testing/factories.rb', line 46

def create_and_plan_action(action_class, *args, &block)
  plan_action create_action(action_class), *args, &block
end

#finalize_action(run_action, &stubbing) ⇒ Action::FinalizePhase

Returns:

  • (Action::FinalizePhase)


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/dynflow/testing/factories.rb', line 79

def finalize_action(run_action, &stubbing)
  Match! run_action.phase, Action::Plan, Action::Run
  step            = DummyStep.new
  finalize_action = run_action.class.new(
      { step:              step,
        execution_plan_id: run_action.execution_plan_id,
        id:                run_action.id,
        plan_step_id:      run_action.plan_step_id,
        run_step_id:       run_action.run_step_id,
        finalize_step_id:  step.id,
        phase:             Action::Finalize,
        input:             run_action.input },
      run_action.world)

  stubbing.call finalize_action if stubbing
  finalize_action.execute
  finalize_action
end

#plan_action(plan_action, *args, &block) ⇒ Action::PlanPhase

Returns:

  • (Action::PlanPhase)


38
39
40
41
42
43
44
# File 'lib/dynflow/testing/factories.rb', line 38

def plan_action(plan_action, *args, &block)
  Match! plan_action.phase, Action::Plan

  plan_action.execute *args, &block
  raise plan_action.error if plan_action.error
  plan_action
end

#progress_action_time(action) ⇒ Object



98
99
100
101
102
# File 'lib/dynflow/testing/factories.rb', line 98

def progress_action_time action
  Match! action.phase, Action::Run
  action.world.clock.progress
  action.world.executor.progress
end

#run_action(plan_action, event = nil, &stubbing) ⇒ Action::RunPhase

Returns:

  • (Action::RunPhase)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/dynflow/testing/factories.rb', line 51

def run_action(plan_action, event = nil, &stubbing)
  Match! plan_action.phase, Action::Plan, Action::Run
  step       = DummyStep.new
  run_action = if plan_action.phase == Action::Plan
                 plan_action.class.new(
                     { step:              step,
                       execution_plan_id: plan_action.execution_plan_id,
                       id:                plan_action.id,
                       plan_step_id:      plan_action.plan_step_id,
                       run_step_id:       step.id,
                       finalize_step_id:  nil,
                       phase:             Action::Run,
                       input:             plan_action.input },
                     plan_action.world)

               else
                 plan_action
               end

  run_action.world.action ||= run_action
  run_action.world.clock.clear
  stubbing.call run_action if stubbing
  run_action.execute event
  raise run_action.error if run_action.error
  run_action
end