Maintenance: Fixed data leaking test by migrating to db_strategy: :reset from use_transactional_tests.

This commit is contained in:
Thorsten Eckel 2020-11-23 10:51:09 +01:00
parent b930827b77
commit e474539f55

View file

@ -3,8 +3,6 @@ require 'rails_helper'
RSpec.describe NotificationFactory::Renderer do RSpec.describe NotificationFactory::Renderer do
# rubocop:disable Lint/InterpolationCheck # rubocop:disable Lint/InterpolationCheck
describe 'render' do describe 'render' do
self.use_transactional_tests = false
before { @user = User.where(firstname: 'Nicole').first } before { @user = User.where(firstname: 'Nicole').first }
it 'correctly renders a blank template' do it 'correctly renders a blank template' do
@ -31,118 +29,121 @@ RSpec.describe NotificationFactory::Renderer do
ticket.destroy ticket.destroy
end end
it 'correctly renders simple select attributes' do context 'when handling ObjectManager::Attribute usage', db_strategy: :reset do
create :object_manager_attribute_select, name: 'select'
ObjectManager::Attribute.migration_execute
ticket = create :ticket, customer: @user, select: 'key_1' it 'correctly renders simple select attributes' do
create :object_manager_attribute_select, name: 'select'
ObjectManager::Attribute.migration_execute
renderer = build :notification_factory_renderer, ticket = create :ticket, customer: @user, select: 'key_1'
objects: { ticket: ticket },
template: '#{ticket.select} _SEPERATOR_ #{ticket.select.value}'
expect(renderer.render).to eq 'key_1 _SEPERATOR_ value_1' renderer = build :notification_factory_renderer,
ticket.destroy objects: { ticket: ticket },
template: '#{ticket.select} _SEPERATOR_ #{ticket.select.value}'
ObjectManager::Attribute.remove( expect(renderer.render).to eq 'key_1 _SEPERATOR_ value_1'
object: 'Ticket', ticket.destroy
name: 'select',
)
ObjectManager::Attribute.migration_execute
end
it 'correctly renders select attributes on chained user object' do ObjectManager::Attribute.remove(
create :object_manager_attribute_select, object: 'Ticket',
object_lookup_id: ObjectLookup.by_name('User'), name: 'select',
name: 'select' )
ObjectManager::Attribute.migration_execute ObjectManager::Attribute.migration_execute
end
user = User.where(firstname: 'Nicole').first it 'correctly renders select attributes on chained user object' do
user.select = 'key_2' create :object_manager_attribute_select,
user.save object_lookup_id: ObjectLookup.by_name('User'),
ticket = create :ticket, customer: user name: 'select'
ObjectManager::Attribute.migration_execute
renderer = build :notification_factory_renderer, user = User.where(firstname: 'Nicole').first
objects: { ticket: ticket }, user.select = 'key_2'
template: '#{ticket.customer.select} _SEPERATOR_ #{ticket.customer.select.value}' user.save
ticket = create :ticket, customer: user
expect(renderer.render).to eq 'key_2 _SEPERATOR_ value_2' renderer = build :notification_factory_renderer,
ticket.destroy objects: { ticket: ticket },
template: '#{ticket.customer.select} _SEPERATOR_ #{ticket.customer.select.value}'
ObjectManager::Attribute.remove( expect(renderer.render).to eq 'key_2 _SEPERATOR_ value_2'
object: 'User', ticket.destroy
name: 'select',
)
ObjectManager::Attribute.migration_execute
end
it 'correctly renders select attributes on chained group object' do ObjectManager::Attribute.remove(
create :object_manager_attribute_select, object: 'User',
object_lookup_id: ObjectLookup.by_name('Group'), name: 'select',
name: 'select' )
ObjectManager::Attribute.migration_execute ObjectManager::Attribute.migration_execute
end
ticket = create :ticket, customer: @user it 'correctly renders select attributes on chained group object' do
group = ticket.group create :object_manager_attribute_select,
group.select = 'key_3' object_lookup_id: ObjectLookup.by_name('Group'),
group.save name: 'select'
ObjectManager::Attribute.migration_execute
renderer = build :notification_factory_renderer, ticket = create :ticket, customer: @user
objects: { ticket: ticket }, group = ticket.group
template: '#{ticket.group.select} _SEPERATOR_ #{ticket.group.select.value}' group.select = 'key_3'
group.save
expect(renderer.render).to eq 'key_3 _SEPERATOR_ value_3' renderer = build :notification_factory_renderer,
ticket.destroy objects: { ticket: ticket },
template: '#{ticket.group.select} _SEPERATOR_ #{ticket.group.select.value}'
ObjectManager::Attribute.remove( expect(renderer.render).to eq 'key_3 _SEPERATOR_ value_3'
object: 'Group', ticket.destroy
name: 'select',
)
ObjectManager::Attribute.migration_execute
end
it 'correctly renders select attributes on chained organization object' do ObjectManager::Attribute.remove(
create :object_manager_attribute_select, object: 'Group',
object_lookup_id: ObjectLookup.by_name('Organization'), name: 'select',
name: 'select' )
ObjectManager::Attribute.migration_execute ObjectManager::Attribute.migration_execute
end
@user.organization.select = 'key_2' it 'correctly renders select attributes on chained organization object' do
@user.organization.save create :object_manager_attribute_select,
ticket = create :ticket, customer: @user object_lookup_id: ObjectLookup.by_name('Organization'),
name: 'select'
ObjectManager::Attribute.migration_execute
renderer = build :notification_factory_renderer, @user.organization.select = 'key_2'
objects: { ticket: ticket }, @user.organization.save
template: '#{ticket.customer.organization.select} _SEPERATOR_ #{ticket.customer.organization.select.value}' ticket = create :ticket, customer: @user
expect(renderer.render).to eq 'key_2 _SEPERATOR_ value_2' renderer = build :notification_factory_renderer,
ticket.destroy objects: { ticket: ticket },
template: '#{ticket.customer.organization.select} _SEPERATOR_ #{ticket.customer.organization.select.value}'
ObjectManager::Attribute.remove( expect(renderer.render).to eq 'key_2 _SEPERATOR_ value_2'
object: 'Organization', ticket.destroy
name: 'select',
)
ObjectManager::Attribute.migration_execute
end
it 'correctly renders tree select attributes' do ObjectManager::Attribute.remove(
create :object_manager_attribute_tree_select, name: 'tree_select' object: 'Organization',
ObjectManager::Attribute.migration_execute name: 'select',
)
ObjectManager::Attribute.migration_execute
end
ticket = create :ticket, customer: @user, tree_select: 'Incident::Hardware::Laptop' it 'correctly renders tree select attributes' do
create :object_manager_attribute_tree_select, name: 'tree_select'
ObjectManager::Attribute.migration_execute
renderer = build :notification_factory_renderer, ticket = create :ticket, customer: @user, tree_select: 'Incident::Hardware::Laptop'
objects: { ticket: ticket },
template: '#{ticket.tree_select} _SEPERATOR_ #{ticket.tree_select.value}'
expect(renderer.render).to eq 'Incident::Hardware::Laptop _SEPERATOR_ Incident::Hardware::Laptop' renderer = build :notification_factory_renderer,
ticket.destroy objects: { ticket: ticket },
template: '#{ticket.tree_select} _SEPERATOR_ #{ticket.tree_select.value}'
ObjectManager::Attribute.remove( expect(renderer.render).to eq 'Incident::Hardware::Laptop _SEPERATOR_ Incident::Hardware::Laptop'
object: 'Ticket', ticket.destroy
name: 'tree_select',
) ObjectManager::Attribute.remove(
ObjectManager::Attribute.migration_execute object: 'Ticket',
name: 'tree_select',
)
ObjectManager::Attribute.migration_execute
end
end end
end end
# rubocop:enable Lint/InterpolationCheck # rubocop:enable Lint/InterpolationCheck