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 0cc5764ab3
commit 68adb3974e
2 changed files with 19 additions and 37 deletions

View file

@ -37,6 +37,10 @@ examples how to use
def render
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
# d - data of object

View file

@ -19,7 +19,6 @@ RSpec.describe NotificationFactory::Renderer do
objects: { ticket: ticket },
template: '#{ticket.customer.firstname.downcase}'
expect(renderer.render).to eq 'nicole'
ticket.destroy
end
it 'correctly renders multiple value calls' do
@ -28,7 +27,21 @@ RSpec.describe NotificationFactory::Renderer do
objects: { ticket: ticket },
template: '#{ticket.created_at.value.value.value.value.to_s.first}'
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: {}
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: {}
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: {}
expect { renderer.render }.to raise_error(StandardError)
end
context 'when handling ObjectManager::Attribute usage', db_strategy: :reset do
@ -44,13 +57,6 @@ RSpec.describe NotificationFactory::Renderer do
template: '#{ticket.select} _SEPERATOR_ #{ticket.select.value}'
expect(renderer.render).to eq 'key_1 _SEPERATOR_ value_1'
ticket.destroy
ObjectManager::Attribute.remove(
object: 'Ticket',
name: 'select',
)
ObjectManager::Attribute.migration_execute
end
it 'correctly renders select attributes on chained user object' do
@ -69,13 +75,6 @@ RSpec.describe NotificationFactory::Renderer do
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',
name: 'select',
)
ObjectManager::Attribute.migration_execute
end
it 'correctly renders select attributes on chained group object' do
@ -94,13 +93,6 @@ RSpec.describe NotificationFactory::Renderer do
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',
name: 'select',
)
ObjectManager::Attribute.migration_execute
end
it 'correctly renders select attributes on chained organization object' do
@ -118,13 +110,6 @@ RSpec.describe NotificationFactory::Renderer do
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',
name: 'select',
)
ObjectManager::Attribute.migration_execute
end
it 'correctly renders tree select attributes' do
@ -138,13 +123,6 @@ RSpec.describe NotificationFactory::Renderer do
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',
name: 'tree_select',
)
ObjectManager::Attribute.migration_execute
end
end
end