Fixes #3028 - Syntax errors break scheduler job for good
This commit is contained in:
parent
0cc5764ab3
commit
68adb3974e
2 changed files with 19 additions and 37 deletions
|
@ -37,6 +37,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
|
||||||
|
|
|
@ -19,7 +19,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
|
||||||
|
@ -28,7 +27,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: {}
|
||||||
|
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
|
end
|
||||||
|
|
||||||
context 'when handling ObjectManager::Attribute usage', db_strategy: :reset do
|
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}'
|
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
|
||||||
|
@ -69,13 +75,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
|
||||||
|
@ -94,13 +93,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
|
||||||
|
@ -118,13 +110,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
|
||||||
|
@ -138,13 +123,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
|
||||||
|
|
Loading…
Reference in a new issue