trigger.rb 941 B

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