renderer_spec.rb 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. require 'rails_helper'
  2. RSpec.describe NotificationFactory::Renderer do
  3. # rubocop:disable Lint/InterpolationCheck
  4. describe 'render' do
  5. before { @user = User.where(firstname: 'Nicole').first }
  6. it 'correctly renders a blank template' do
  7. renderer = build :notification_factory_renderer
  8. expect(renderer.render).to eq ''
  9. end
  10. it 'correctly renders chained object references' do
  11. user = User.where(firstname: 'Nicole').first
  12. ticket = create :ticket, customer: user
  13. renderer = build :notification_factory_renderer,
  14. objects: { ticket: ticket },
  15. template: '#{ticket.customer.firstname.downcase}'
  16. expect(renderer.render).to eq 'nicole'
  17. ticket.destroy
  18. end
  19. it 'correctly renders multiple value calls' do
  20. ticket = create :ticket, customer: @user
  21. renderer = build :notification_factory_renderer,
  22. objects: { ticket: ticket },
  23. template: '#{ticket.created_at.value.value.value.value.to_s.first}'
  24. expect(renderer.render).to eq '2'
  25. ticket.destroy
  26. end
  27. context 'when handling ObjectManager::Attribute usage', db_strategy: :reset do
  28. it 'correctly renders simple select attributes' do
  29. create :object_manager_attribute_select, name: 'select'
  30. ObjectManager::Attribute.migration_execute
  31. ticket = create :ticket, customer: @user, select: 'key_1'
  32. renderer = build :notification_factory_renderer,
  33. objects: { ticket: ticket },
  34. template: '#{ticket.select} _SEPERATOR_ #{ticket.select.value}'
  35. expect(renderer.render).to eq 'key_1 _SEPERATOR_ value_1'
  36. ticket.destroy
  37. ObjectManager::Attribute.remove(
  38. object: 'Ticket',
  39. name: 'select',
  40. )
  41. ObjectManager::Attribute.migration_execute
  42. end
  43. it 'correctly renders select attributes on chained user object' do
  44. create :object_manager_attribute_select,
  45. object_lookup_id: ObjectLookup.by_name('User'),
  46. name: 'select'
  47. ObjectManager::Attribute.migration_execute
  48. user = User.where(firstname: 'Nicole').first
  49. user.select = 'key_2'
  50. user.save
  51. ticket = create :ticket, customer: user
  52. renderer = build :notification_factory_renderer,
  53. objects: { ticket: ticket },
  54. template: '#{ticket.customer.select} _SEPERATOR_ #{ticket.customer.select.value}'
  55. expect(renderer.render).to eq 'key_2 _SEPERATOR_ value_2'
  56. ticket.destroy
  57. ObjectManager::Attribute.remove(
  58. object: 'User',
  59. name: 'select',
  60. )
  61. ObjectManager::Attribute.migration_execute
  62. end
  63. it 'correctly renders select attributes on chained group object' do
  64. create :object_manager_attribute_select,
  65. object_lookup_id: ObjectLookup.by_name('Group'),
  66. name: 'select'
  67. ObjectManager::Attribute.migration_execute
  68. ticket = create :ticket, customer: @user
  69. group = ticket.group
  70. group.select = 'key_3'
  71. group.save
  72. renderer = build :notification_factory_renderer,
  73. objects: { ticket: ticket },
  74. template: '#{ticket.group.select} _SEPERATOR_ #{ticket.group.select.value}'
  75. expect(renderer.render).to eq 'key_3 _SEPERATOR_ value_3'
  76. ticket.destroy
  77. ObjectManager::Attribute.remove(
  78. object: 'Group',
  79. name: 'select',
  80. )
  81. ObjectManager::Attribute.migration_execute
  82. end
  83. it 'correctly renders select attributes on chained organization object' do
  84. create :object_manager_attribute_select,
  85. object_lookup_id: ObjectLookup.by_name('Organization'),
  86. name: 'select'
  87. ObjectManager::Attribute.migration_execute
  88. @user.organization.select = 'key_2'
  89. @user.organization.save
  90. ticket = create :ticket, customer: @user
  91. renderer = build :notification_factory_renderer,
  92. objects: { ticket: ticket },
  93. template: '#{ticket.customer.organization.select} _SEPERATOR_ #{ticket.customer.organization.select.value}'
  94. expect(renderer.render).to eq 'key_2 _SEPERATOR_ value_2'
  95. ticket.destroy
  96. ObjectManager::Attribute.remove(
  97. object: 'Organization',
  98. name: 'select',
  99. )
  100. ObjectManager::Attribute.migration_execute
  101. end
  102. it 'correctly renders tree select attributes' do
  103. create :object_manager_attribute_tree_select, name: 'tree_select'
  104. ObjectManager::Attribute.migration_execute
  105. ticket = create :ticket, customer: @user, tree_select: 'Incident::Hardware::Laptop'
  106. renderer = build :notification_factory_renderer,
  107. objects: { ticket: ticket },
  108. template: '#{ticket.tree_select} _SEPERATOR_ #{ticket.tree_select.value}'
  109. expect(renderer.render).to eq 'Incident::Hardware::Laptop _SEPERATOR_ Incident::Hardware::Laptop'
  110. ticket.destroy
  111. ObjectManager::Attribute.remove(
  112. object: 'Ticket',
  113. name: 'tree_select',
  114. )
  115. ObjectManager::Attribute.migration_execute
  116. end
  117. end
  118. end
  119. # rubocop:enable Lint/InterpolationCheck
  120. end