checklist_template_spec.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe ChecklistTemplate, :aggregate_failures, current_user_id: 1, type: :model do
  4. describe '#replace_items!' do
  5. let(:template) { create(:checklist_template, item_count: 0) }
  6. it 'adds given items' do
  7. template.replace_items! %w[item1 item2]
  8. expect(template.sorted_items).to contain_exactly(
  9. have_attributes(text: 'item1'),
  10. have_attributes(text: 'item2')
  11. )
  12. end
  13. it 'ensures a limit of 100 items' do
  14. huge_list = Array.new(101, 'item')
  15. expect { template.replace_items!(huge_list) }
  16. .to raise_error(
  17. Exceptions::UnprocessableEntity,
  18. 'Checklist Template items are limited to 100 items per checklist.'
  19. )
  20. end
  21. context 'when pre-existing items exist' do
  22. before do
  23. template.replace_items! %w[initial]
  24. end
  25. it 'drops pre-existing items' do
  26. template.replace_items! %w[item1 item2]
  27. expect(template.sorted_items).to contain_exactly(
  28. have_attributes(text: 'item1'),
  29. have_attributes(text: 'item2')
  30. )
  31. end
  32. end
  33. end
  34. end