trigger.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. FactoryBot.define do
  3. factory :trigger do
  4. sequence(:name) { |n| "Test trigger #{n}" }
  5. activator { 'action' }
  6. execution_condition_mode { 'selective' }
  7. condition { { 'ticket.state_id' => { 'operator' => 'is not', 'value' => 4 } } }
  8. perform { { 'ticket.state_id' => { 'value' => 4 } } }
  9. active { true }
  10. created_by_id { 1 }
  11. updated_by_id { 1 }
  12. trait :conditionable do
  13. transient do
  14. condition_ticket_action { nil }
  15. end
  16. condition { {} }
  17. callback(:after_stub, :before_create) do |object, context|
  18. hash = object.condition
  19. hash['ticket.action'] = { 'operator' => 'is', 'value' => context.condition_ticket_action.to_s } if context.condition_ticket_action
  20. object.condition = hash
  21. end
  22. end
  23. # empty trigger to help to test atomically
  24. trait :no_perform do
  25. perform { { null: true } }
  26. end
  27. end
  28. end