Fixes #3028 - Syntax errors break scheduler job for good

This commit is contained in:
Mantas 2021-09-27 17:24:09 +03:00 committed by Thorsten Eckel
parent 13668dfc8b
commit d7b0c639c4
2 changed files with 19 additions and 37 deletions

View file

@ -38,6 +38,10 @@ examples how to use
def render def render
ERB.new(@template.to_s).result(binding) ERB.new(@template.to_s).result(binding)
rescue Exception => e # rubocop:disable Lint/RescueException
raise StandardError, e.message if e.is_a? SyntaxError
raise
end end
# d - data of object # d - data of object

View file

@ -34,7 +34,6 @@ RSpec.describe NotificationFactory::Renderer do
objects: { ticket: ticket }, objects: { ticket: ticket },
template: '#{ticket.customer.firstname.downcase}' template: '#{ticket.customer.firstname.downcase}'
expect(renderer.render).to eq 'nicole' expect(renderer.render).to eq 'nicole'
ticket.destroy
end end
it 'correctly renders multiple value calls' do it 'correctly renders multiple value calls' do
@ -43,7 +42,21 @@ RSpec.describe NotificationFactory::Renderer do
objects: { ticket: ticket }, objects: { ticket: ticket },
template: '#{ticket.created_at.value.value.value.value.to_s.first}' template: '#{ticket.created_at.value.value.value.value.to_s.first}'
expect(renderer.render).to eq '2' expect(renderer.render).to eq '2'
ticket.destroy end
it 'raises a StandardError when rendering a template with a broken syntax' do
renderer = build :notification_factory_renderer, template: 'test <% if %>', objects: {}, trusted: true
expect { renderer.render }.to raise_error(StandardError)
end
it 'raises a StandardError when rendering a template calling a non existant method' do
renderer = build :notification_factory_renderer, template: 'test <% Ticket.non_existant_method %>', objects: {}, trusted: true
expect { renderer.render }.to raise_error(StandardError)
end
it 'raises a StandardError when rendering a template referencing a non existant object' do
renderer = build :notification_factory_renderer, template: 'test <% NonExistantObject.first %>', objects: {}, trusted: true
expect { renderer.render }.to raise_error(StandardError)
end end
context 'when handling ObjectManager::Attribute usage', db_strategy: :reset do context 'when handling ObjectManager::Attribute usage', db_strategy: :reset do
@ -59,13 +72,6 @@ RSpec.describe NotificationFactory::Renderer do
template: '#{ticket.select} _SEPERATOR_ #{ticket.select.value}' template: '#{ticket.select} _SEPERATOR_ #{ticket.select.value}'
expect(renderer.render).to eq 'key_1 _SEPERATOR_ value_1' expect(renderer.render).to eq 'key_1 _SEPERATOR_ value_1'
ticket.destroy
ObjectManager::Attribute.remove(
object: 'Ticket',
name: 'select',
)
ObjectManager::Attribute.migration_execute
end end
it 'correctly renders select attributes on chained user object' do it 'correctly renders select attributes on chained user object' do
@ -84,13 +90,6 @@ RSpec.describe NotificationFactory::Renderer do
template: '#{ticket.customer.select} _SEPERATOR_ #{ticket.customer.select.value}' template: '#{ticket.customer.select} _SEPERATOR_ #{ticket.customer.select.value}'
expect(renderer.render).to eq 'key_2 _SEPERATOR_ value_2' expect(renderer.render).to eq 'key_2 _SEPERATOR_ value_2'
ticket.destroy
ObjectManager::Attribute.remove(
object: 'User',
name: 'select',
)
ObjectManager::Attribute.migration_execute
end end
it 'correctly renders select attributes on chained group object' do it 'correctly renders select attributes on chained group object' do
@ -109,13 +108,6 @@ RSpec.describe NotificationFactory::Renderer do
template: '#{ticket.group.select} _SEPERATOR_ #{ticket.group.select.value}' template: '#{ticket.group.select} _SEPERATOR_ #{ticket.group.select.value}'
expect(renderer.render).to eq 'key_3 _SEPERATOR_ value_3' expect(renderer.render).to eq 'key_3 _SEPERATOR_ value_3'
ticket.destroy
ObjectManager::Attribute.remove(
object: 'Group',
name: 'select',
)
ObjectManager::Attribute.migration_execute
end end
it 'correctly renders select attributes on chained organization object' do it 'correctly renders select attributes on chained organization object' do
@ -133,13 +125,6 @@ RSpec.describe NotificationFactory::Renderer do
template: '#{ticket.customer.organization.select} _SEPERATOR_ #{ticket.customer.organization.select.value}' template: '#{ticket.customer.organization.select} _SEPERATOR_ #{ticket.customer.organization.select.value}'
expect(renderer.render).to eq 'key_2 _SEPERATOR_ value_2' expect(renderer.render).to eq 'key_2 _SEPERATOR_ value_2'
ticket.destroy
ObjectManager::Attribute.remove(
object: 'Organization',
name: 'select',
)
ObjectManager::Attribute.migration_execute
end end
it 'correctly renders tree select attributes' do it 'correctly renders tree select attributes' do
@ -153,13 +138,6 @@ RSpec.describe NotificationFactory::Renderer do
template: '#{ticket.tree_select} _SEPERATOR_ #{ticket.tree_select.value}' template: '#{ticket.tree_select} _SEPERATOR_ #{ticket.tree_select.value}'
expect(renderer.render).to eq 'Incident::Hardware::Laptop _SEPERATOR_ Incident::Hardware::Laptop' expect(renderer.render).to eq 'Incident::Hardware::Laptop _SEPERATOR_ Incident::Hardware::Laptop'
ticket.destroy
ObjectManager::Attribute.remove(
object: 'Ticket',
name: 'tree_select',
)
ObjectManager::Attribute.migration_execute
end end
end end
end end