macro_spec.rb 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'models/concerns/has_collection_update_examples'
  4. require 'models/concerns/has_xss_sanitized_note_examples'
  5. RSpec.describe Macro, type: :model do
  6. it_behaves_like 'HasCollectionUpdate', collection_factory: :macro
  7. it_behaves_like 'HasXssSanitizedNote', model_factory: :macro
  8. describe 'validation' do
  9. it 'uses Validations::VerifyPerformRulesValidator' do
  10. expect(described_class).to have_validator(Validations::VerifyPerformRulesValidator).on(:perform)
  11. end
  12. end
  13. describe 'Instance methods:' do
  14. describe '#applicable_on?' do
  15. let(:ticket) { create(:ticket) }
  16. let(:ticket_a) { create(:ticket, group: group_a) }
  17. let(:ticket_b) { create(:ticket, group: group_b) }
  18. let(:ticket_c) { create(:ticket, group: group_c) }
  19. let(:group_a) { create(:group) }
  20. let(:group_b) { create(:group) }
  21. let(:group_c) { create(:group) }
  22. context 'when macro has no groups' do
  23. subject(:macro) { create(:macro, groups: []) }
  24. it 'return true for a single group' do
  25. expect(macro).to be_applicable_on(ticket)
  26. end
  27. it 'return true for multiple tickets' do
  28. expect(macro).to be_applicable_on([ticket, ticket_a, ticket_b])
  29. end
  30. end
  31. context 'when macro has a single group' do
  32. subject(:macro) { create(:macro, groups: [group_a]) }
  33. it 'returns true if macro group matches ticket' do
  34. expect(macro).to be_applicable_on(ticket_a)
  35. end
  36. it 'returns false if macro group does not match ticket' do
  37. expect(macro).not_to be_applicable_on(ticket_b)
  38. end
  39. it 'returns false if macro group match a ticket and not the other' do
  40. expect(macro).not_to be_applicable_on([ticket_a, ticket_b])
  41. end
  42. end
  43. context 'when macro has multiple groups' do
  44. subject(:macro) { create(:macro, groups: [group_a, group_c]) }
  45. it 'returns true if macro groups include ticket group' do
  46. expect(macro).to be_applicable_on(ticket_a)
  47. end
  48. it 'returns false if macro groups do not include ticket group' do
  49. expect(macro).not_to be_applicable_on(ticket_b)
  50. end
  51. it 'returns true if macro groups match tickets groups' do
  52. expect(macro).to be_applicable_on([ticket_a, ticket_c])
  53. end
  54. it 'returns false if macro groups does not match one of tickets group' do
  55. expect(macro).not_to be_applicable_on([ticket_a, ticket_b])
  56. end
  57. end
  58. end
  59. end
  60. end