migration_scheduler_last_run_spec.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require_relative '../../../../.dev/rubocop/cop/zammad/migration_scheduler_last_run'
  4. RSpec.describe RuboCop::Cop::Zammad::MigrationSchedulerLastRun, type: :rubocop do
  5. it 'shows no error for create_if_not_exists when last_run is set' do
  6. expect_no_offenses(<<-RUBY)
  7. Scheduler.create_if_not_exists(
  8. name: "Clean up 'DataPrivacyTask'.",
  9. method: 'DataPrivacyTask.cleanup',
  10. period: 1.day,
  11. prio: 2,
  12. active: true,
  13. updated_by_id: 1,
  14. created_by_id: 1,
  15. last_run: Time.zone.now,
  16. )
  17. RUBY
  18. end
  19. it 'shows error for create_if_not_exists when last_run is not set' do
  20. result = inspect_source(<<~RUBY)
  21. Scheduler.create_if_not_exists(
  22. name: "Clean up 'DataPrivacyTask'.",
  23. method: 'DataPrivacyTask.cleanup',
  24. period: 1.day,
  25. prio: 2,
  26. active: true,
  27. updated_by_id: 1,
  28. created_by_id: 1,
  29. )
  30. RUBY
  31. expect(result.first.cop_name).to eq('Zammad/MigrationSchedulerLastRun')
  32. end
  33. it 'shows no error for create_or_update when last_run is set' do
  34. expect_no_offenses(<<-RUBY)
  35. Scheduler.create_or_update(
  36. name: "Clean up 'DataPrivacyTask'.",
  37. method: 'DataPrivacyTask.cleanup',
  38. period: 1.day,
  39. prio: 2,
  40. active: true,
  41. updated_by_id: 1,
  42. created_by_id: 1,
  43. last_run: Time.zone.now,
  44. )
  45. RUBY
  46. end
  47. it 'shows error for create_or_update when last_run is not set' do
  48. result = inspect_source(<<~RUBY)
  49. Scheduler.create_or_update(
  50. name: "Clean up 'DataPrivacyTask'.",
  51. method: 'DataPrivacyTask.cleanup',
  52. period: 1.day,
  53. prio: 2,
  54. active: true,
  55. updated_by_id: 1,
  56. created_by_id: 1,
  57. )
  58. RUBY
  59. expect(result.first.cop_name).to eq('Zammad/MigrationSchedulerLastRun')
  60. end
  61. end