trigger.rb 911 B

123456789101112131415161718192021222324252627282930313233
  1. # Copyright (C) 2012-2022 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. end
  11. trait :conditionable do
  12. transient do
  13. condition_ticket_action { nil }
  14. end
  15. condition { {} }
  16. callback(:after_stub, :before_create) do |object, context|
  17. hash = object.condition
  18. hash['ticket.action'] = { 'operator' => 'is', 'value' => context.condition_ticket_action.to_s } if context.condition_ticket_action
  19. object.condition = hash
  20. end
  21. end
  22. # empty trigger to help to test atomically
  23. trait :no_perform do
  24. perform { { null: true } }
  25. end
  26. end