ticket_spec.rb 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Copyright (C) 2012-2025 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. describe 'set unexpected defaults' do
  53. before { attribute }
  54. let(:attribute) do
  55. attribute = create(:object_manager_attribute_text, data_option: { type: 'text', maxlength: 100, default: false })
  56. ObjectManager::Attribute.migration_execute
  57. attribute
  58. end
  59. let(:ticket) { create(:ticket) }
  60. let(:mysql?) { ActiveRecord::Base.connection_db_config.configuration_hash[:adapter] == 'mysql2' }
  61. it 'is successful' do
  62. expect(ticket.attributes[attribute.name]).to eq(mysql? ? '0' : 'f')
  63. end
  64. end
  65. end