macro_spec.rb 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright (C) 2012-2022 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 'Instance methods:' do
  9. describe '#applicable_on?' do
  10. let(:ticket) { create(:ticket) }
  11. let(:ticket_a) { create(:ticket, group: group_a) }
  12. let(:ticket_b) { create(:ticket, group: group_b) }
  13. let(:ticket_c) { create(:ticket, group: group_c) }
  14. let(:group_a) { create(:group) }
  15. let(:group_b) { create(:group) }
  16. let(:group_c) { create(:group) }
  17. context 'when macro has no groups' do
  18. subject(:macro) { create(:macro, groups: []) }
  19. it 'return true for a single group' do
  20. expect(macro).to be_applicable_on(ticket)
  21. end
  22. it 'return true for multiple tickets' do
  23. expect(macro).to be_applicable_on([ticket, ticket_a, ticket_b])
  24. end
  25. end
  26. context 'when macro has a single group' do
  27. subject(:macro) { create(:macro, groups: [group_a]) }
  28. it 'returns true if macro group matches ticket' do
  29. expect(macro).to be_applicable_on(ticket_a)
  30. end
  31. it 'returns false if macro group does not match ticket' do
  32. expect(macro).not_to be_applicable_on(ticket_b)
  33. end
  34. it 'returns false if macro group match a ticket and not the other' do
  35. expect(macro).not_to be_applicable_on([ticket_a, ticket_b])
  36. end
  37. end
  38. context 'when macro has multiple groups' do
  39. subject(:macro) { create(:macro, groups: [group_a, group_c]) }
  40. it 'returns true if macro groups include ticket group' do
  41. expect(macro).to be_applicable_on(ticket_a)
  42. end
  43. it 'returns false if macro groups do not include ticket group' do
  44. expect(macro).not_to be_applicable_on(ticket_b)
  45. end
  46. it 'returns true if macro groups match tickets groups' do
  47. expect(macro).to be_applicable_on([ticket_a, ticket_c])
  48. end
  49. it 'returns false if macro groups does not match one of tickets group' do
  50. expect(macro).not_to be_applicable_on([ticket_a, ticket_b])
  51. end
  52. end
  53. end
  54. end
  55. end