trigger_from_commit_hooks_spec.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require_relative '../../../../.dev/rubocop/cop/zammad/trigger_from_commit_hooks'
  4. RSpec.describe RuboCop::Cop::Zammad::TriggerFromCommitHooks, :aggregate_failures, type: :rubocop do
  5. it 'accepts triggers from commit hooks' do
  6. expect_no_offenses('after_create_commit :trigger_subscriptions')
  7. expect_no_offenses('after_update_commit :trigger_subscriptions')
  8. expect_no_offenses('after_save_commit :trigger_subscriptions')
  9. expect_no_offenses('after_destroy_commit :trigger_subscriptions')
  10. expect_no_offenses('after_commit :trigger_subscriptions')
  11. end
  12. it 'ignores other callback methods' do
  13. expect_no_offenses('after_save :other_callback')
  14. end
  15. it 'rejects triggers from non-commit hooks' do
  16. expect_offense(<<~RUBY)
  17. after_create :trigger_subscriptions
  18. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Trigger GraphQL subscriptions only from commit hooks to ensure the data is available in other processes.
  19. RUBY
  20. expect_correction(<<~RUBY)
  21. after_create_commit :trigger_subscriptions
  22. RUBY
  23. expect_offense(<<~RUBY)
  24. after_update :trigger_subscriptions
  25. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Trigger GraphQL subscriptions only from commit hooks to ensure the data is available in other processes.
  26. RUBY
  27. expect_correction(<<~RUBY)
  28. after_update_commit :trigger_subscriptions
  29. RUBY
  30. expect_offense(<<~RUBY)
  31. after_save :trigger_subscriptions
  32. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Trigger GraphQL subscriptions only from commit hooks to ensure the data is available in other processes.
  33. RUBY
  34. expect_correction(<<~RUBY)
  35. after_save_commit :trigger_subscriptions
  36. RUBY
  37. expect_offense(<<~RUBY)
  38. after_destroy :trigger_subscriptions
  39. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Trigger GraphQL subscriptions only from commit hooks to ensure the data is available in other processes.
  40. RUBY
  41. expect_correction(<<~RUBY)
  42. after_destroy_commit :trigger_subscriptions
  43. RUBY
  44. end
  45. end