ticket_spec.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'ObjectManager::Attribute::Object::Ticket', aggregate_failures: true, db_strategy: :reset do
  4. shared_context 'with ticket attribute setup' do
  5. before { attribute }
  6. let(:attribute) do
  7. attribute = create(:object_manager_attribute_text)
  8. ObjectManager::Attribute.migration_execute
  9. attribute
  10. end
  11. let(:ticket) { create(:ticket) }
  12. end
  13. describe 'add ticket attribute' do
  14. include_context 'with ticket attribute setup'
  15. it 'is successful' do
  16. ticket.update(attribute.name => 'Bazinga!')
  17. expect(ticket.reload).to have_attributes(attribute.name => 'Bazinga!')
  18. end
  19. end
  20. describe 'update ticket attribute' do
  21. include_context 'with ticket attribute setup'
  22. it 'is successful' do
  23. skip 'Missing error handling on edit misconfiguration.'
  24. ticket.update!(attribute.name => 'Bazinga!')
  25. attributes = attribute.attributes
  26. attributes.delete('data_option_new')
  27. attributes['data_option'] = {
  28. maxlength: 3,
  29. type: 'text',
  30. null: false,
  31. }
  32. ObjectManager::Attribute.add(attributes.deep_symbolize_keys)
  33. ObjectManager::Attribute.migration_execute
  34. expect { ticket.reload }.not_to raise_error
  35. new_ticket = create(:ticket).tap { |t| t.update!(attribute.name => 'Bazinga!') }
  36. expect(new_ticket.attributes[attribute.name].length).to be(3)
  37. end
  38. end
  39. describe 'remove ticket attribute' do
  40. include_context 'with ticket attribute setup'
  41. it 'is successful' do
  42. ticket.update!(attribute.name => 'Bazinga!')
  43. attribute_name = attribute.name
  44. ObjectManager::Attribute.remove(
  45. object: 'Ticket',
  46. name: attribute_name
  47. )
  48. ObjectManager::Attribute.migration_execute
  49. expect(ticket.reload.attributes).not_to include(attribute_name)
  50. end
  51. end
  52. end