Module: Stepped::TestHelper
- Defined in:
- lib/stepped/test_helper.rb
Instance Method Summary collapse
- #assert_no_stepped_actions ⇒ Object
- #assert_stepped_action_job(name, actor = nil) ⇒ Object
- #complete_stepped_outbound_performances ⇒ Object
- #handle_stepped_action_exceptions(only: [ StandardError ]) ⇒ Object
- #perform_enqueued_jobs_recursively(only: nil) ⇒ Object
- #perform_stepped_actions(only: stepped_job_classes) ⇒ Object
- #stepped_job_classes ⇒ Object
Instance Method Details
#assert_no_stepped_actions ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/stepped/test_helper.rb', line 34 def assert_no_stepped_actions jobs_before = enqueued_jobs + performed_jobs yield jobs = (enqueued_jobs + performed_jobs) - jobs_before found = false all_actions = [] jobs.each do |job| next unless job["job_class"] == "Stepped::ActionJob" found = true job_actor, job_action_name = ActiveJob::Arguments.deserialize job["arguments"] all_actions << [ job_actor.class.name, job_action_name ].join("#") end assert_not found, <<~MESSAGE Stepped action jobs enqueued or performed: #{all_actions.join(", ")} MESSAGE end |
#assert_stepped_action_job(name, actor = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/stepped/test_helper.rb', line 9 def assert_stepped_action_job(name, actor = nil) jobs_before = enqueued_jobs + performed_jobs yield jobs = (enqueued_jobs + performed_jobs) - jobs_before found = false all_actions = [] jobs.each do |job| next unless job["job_class"] == "Stepped::ActionJob" job_actor, job_action_name = ActiveJob::Arguments.deserialize job["arguments"] all_actions << [ job_actor.to_global_id, job_action_name ].join("#") next if found found = job_action_name == name if found && actor.present? actor = eval(actor) if actor.is_a?(String) found = job_actor == actor end end assert found, <<~MESSAGE Stepped action job for '#{name}' was not enqueued or performed#{actor.respond_to?(:to_debug_id) ? " on #{actor.to_debug_id}" : nil}. Actions that were: #{all_actions.join(", ")} MESSAGE end |
#complete_stepped_outbound_performances ⇒ Object
73 74 75 |
# File 'lib/stepped/test_helper.rb', line 73 def complete_stepped_outbound_performances # Consuming app can redefine end |
#handle_stepped_action_exceptions(only: [ StandardError ]) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/stepped/test_helper.rb', line 51 def handle_stepped_action_exceptions(only: [ StandardError ]) was = Stepped::Engine.config.stepped_actions.handle_exceptions Stepped::Engine.config.stepped_actions.handle_exceptions = Array(only) yield ensure Stepped::Engine.config.stepped_actions.handle_exceptions = was end |
#perform_enqueued_jobs_recursively(only: nil) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/stepped/test_helper.rb', line 59 def perform_enqueued_jobs_recursively(only: nil) total = 0 loop do batch = perform_enqueued_jobs(only:) break if batch == 0 total += batch end total end |
#perform_stepped_actions(only: stepped_job_classes) ⇒ Object
2 3 4 5 6 7 |
# File 'lib/stepped/test_helper.rb', line 2 def perform_stepped_actions(only: stepped_job_classes) perform_enqueued_jobs_recursively(only:) complete_stepped_outbound_performances perform_stepped_actions(only:) if Stepped::Performance.any? || enqueued_jobs_with(only:).count > 0 end |
#stepped_job_classes ⇒ Object
69 70 71 |
# File 'lib/stepped/test_helper.rb', line 69 def stepped_job_classes [ Stepped::ActionJob, Stepped::TimeoutJob, Stepped::WaitJob ] + Stepped::Registry.job_classes end |