2018-09-26 11:08:18 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe NotificationFactory::Renderer do
|
|
|
|
# rubocop:disable Lint/InterpolationCheck
|
|
|
|
describe 'render' do
|
|
|
|
self.use_transactional_tests = false
|
|
|
|
|
|
|
|
before { @user = User.where(firstname: 'Nicole').first }
|
|
|
|
|
|
|
|
it 'correctly renders a blank template' do
|
|
|
|
renderer = build :notification_factory_renderer
|
|
|
|
expect(renderer.render).to eq ''
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly renders chained object references' do
|
|
|
|
user = User.where(firstname: 'Nicole').first
|
|
|
|
ticket = create :ticket, customer: user
|
|
|
|
renderer = build :notification_factory_renderer,
|
2018-12-19 17:31:51 +00:00
|
|
|
objects: { ticket: ticket },
|
2018-09-26 11:08:18 +00:00
|
|
|
template: '#{ticket.customer.firstname.downcase}'
|
|
|
|
expect(renderer.render).to eq 'nicole'
|
|
|
|
ticket.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly renders multiple value calls' do
|
|
|
|
ticket = create :ticket, customer: @user
|
|
|
|
renderer = build :notification_factory_renderer,
|
2018-12-19 17:31:51 +00:00
|
|
|
objects: { ticket: ticket },
|
2018-09-26 11:08:18 +00:00
|
|
|
template: '#{ticket.created_at.value.value.value.value.to_s.first}'
|
|
|
|
expect(renderer.render).to eq '2'
|
|
|
|
ticket.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly renders simple select attributes' do
|
|
|
|
attribute = create :object_manager_attribute_select, name: 'select'
|
|
|
|
ObjectManager::Attribute.migration_execute
|
|
|
|
|
|
|
|
ticket = create :ticket, customer: @user, select: 'key_1'
|
|
|
|
|
|
|
|
renderer = build :notification_factory_renderer,
|
2018-12-19 17:31:51 +00:00
|
|
|
objects: { ticket: ticket },
|
2018-09-26 11:08:18 +00:00
|
|
|
template: '#{ticket.select} _SEPERATOR_ #{ticket.select.value}'
|
|
|
|
|
|
|
|
expect(renderer.render).to eq 'key_1 _SEPERATOR_ value_1'
|
|
|
|
ticket.destroy
|
|
|
|
|
|
|
|
ObjectManager::Attribute.remove(
|
|
|
|
object: 'Ticket',
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'select',
|
2018-09-26 11:08:18 +00:00
|
|
|
)
|
|
|
|
ObjectManager::Attribute.migration_execute
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly renders select attributes on chained user object' do
|
|
|
|
attribute = create :object_manager_attribute_select,
|
|
|
|
object_lookup_id: ObjectLookup.by_name('User'),
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'select'
|
2018-09-26 11:08:18 +00:00
|
|
|
ObjectManager::Attribute.migration_execute
|
|
|
|
|
|
|
|
user = User.where(firstname: 'Nicole').first
|
|
|
|
user.select = 'key_2'
|
|
|
|
user.save
|
|
|
|
ticket = create :ticket, customer: user
|
|
|
|
|
|
|
|
renderer = build :notification_factory_renderer,
|
2018-12-19 17:31:51 +00:00
|
|
|
objects: { ticket: ticket },
|
2018-09-26 11:08:18 +00:00
|
|
|
template: '#{ticket.customer.select} _SEPERATOR_ #{ticket.customer.select.value}'
|
|
|
|
|
|
|
|
expect(renderer.render).to eq 'key_2 _SEPERATOR_ value_2'
|
|
|
|
ticket.destroy
|
|
|
|
|
|
|
|
ObjectManager::Attribute.remove(
|
|
|
|
object: 'User',
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'select',
|
2018-09-26 11:08:18 +00:00
|
|
|
)
|
|
|
|
ObjectManager::Attribute.migration_execute
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly renders select attributes on chained group object' do
|
|
|
|
attribute = create :object_manager_attribute_select,
|
|
|
|
object_lookup_id: ObjectLookup.by_name('Group'),
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'select'
|
2018-09-26 11:08:18 +00:00
|
|
|
ObjectManager::Attribute.migration_execute
|
|
|
|
|
|
|
|
ticket = create :ticket, customer: @user
|
|
|
|
group = ticket.group
|
|
|
|
group.select = 'key_3'
|
|
|
|
group.save
|
|
|
|
|
|
|
|
renderer = build :notification_factory_renderer,
|
2018-12-19 17:31:51 +00:00
|
|
|
objects: { ticket: ticket },
|
2018-09-26 11:08:18 +00:00
|
|
|
template: '#{ticket.group.select} _SEPERATOR_ #{ticket.group.select.value}'
|
|
|
|
|
|
|
|
expect(renderer.render).to eq 'key_3 _SEPERATOR_ value_3'
|
|
|
|
ticket.destroy
|
|
|
|
|
|
|
|
ObjectManager::Attribute.remove(
|
|
|
|
object: 'Group',
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'select',
|
2018-09-26 11:08:18 +00:00
|
|
|
)
|
|
|
|
ObjectManager::Attribute.migration_execute
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly renders select attributes on chained organization object' do
|
|
|
|
attribute = create :object_manager_attribute_select,
|
|
|
|
object_lookup_id: ObjectLookup.by_name('Organization'),
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'select'
|
2018-09-26 11:08:18 +00:00
|
|
|
ObjectManager::Attribute.migration_execute
|
|
|
|
|
|
|
|
@user.organization.select = 'key_2'
|
|
|
|
@user.organization.save
|
|
|
|
ticket = create :ticket, customer: @user
|
|
|
|
|
|
|
|
renderer = build :notification_factory_renderer,
|
2018-12-19 17:31:51 +00:00
|
|
|
objects: { ticket: ticket },
|
2018-09-26 11:08:18 +00:00
|
|
|
template: '#{ticket.customer.organization.select} _SEPERATOR_ #{ticket.customer.organization.select.value}'
|
|
|
|
|
|
|
|
expect(renderer.render).to eq 'key_2 _SEPERATOR_ value_2'
|
|
|
|
ticket.destroy
|
|
|
|
|
|
|
|
ObjectManager::Attribute.remove(
|
|
|
|
object: 'Organization',
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'select',
|
2018-09-26 11:08:18 +00:00
|
|
|
)
|
|
|
|
ObjectManager::Attribute.migration_execute
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly renders tree select attributes' do
|
|
|
|
attribute = create :object_manager_attribute_tree_select, name: 'tree_select'
|
|
|
|
ObjectManager::Attribute.migration_execute
|
|
|
|
|
|
|
|
ticket = create :ticket, customer: @user, tree_select: 'Incident::Hardware::Laptop'
|
|
|
|
|
|
|
|
renderer = build :notification_factory_renderer,
|
2018-12-19 17:31:51 +00:00
|
|
|
objects: { ticket: ticket },
|
2018-09-26 11:08:18 +00:00
|
|
|
template: '#{ticket.tree_select} _SEPERATOR_ #{ticket.tree_select.value}'
|
|
|
|
|
|
|
|
expect(renderer.render).to eq 'Incident::Hardware::Laptop _SEPERATOR_ Incident::Hardware::Laptop'
|
|
|
|
ticket.destroy
|
|
|
|
|
|
|
|
ObjectManager::Attribute.remove(
|
|
|
|
object: 'Ticket',
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'tree_select',
|
2018-09-26 11:08:18 +00:00
|
|
|
)
|
|
|
|
ObjectManager::Attribute.migration_execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# rubocop:enable Lint/InterpolationCheck
|
|
|
|
end
|