Maintenance: Fixed caching issue in authenticate_as spec helper and enhanced capabilities.

This commit is contained in:
Mantas Masalskis 2019-05-31 09:54:38 +02:00 committed by Thorsten Eckel
parent 4767aa0771
commit 48766c7db9
4 changed files with 22 additions and 33 deletions

View file

@ -2089,7 +2089,6 @@ RSpec.describe 'Ticket', type: :request do
describe 'reopening a ticket' do
shared_examples 'successfully reopen a ticket' do
it 'succeeds' do
authenticated_as(user)
put "/api/v1/tickets/#{ticket.id}",
params: { state_id: Ticket::State.find_by(name: 'open').id },
as: :json
@ -2101,7 +2100,6 @@ RSpec.describe 'Ticket', type: :request do
shared_examples 'fail to reopen a ticket' do
it 'fails' do
authenticated_as(user)
put "/api/v1/tickets/#{ticket.id}",
params: { state_id: Ticket::State.find_by(name: 'open').id },
as: :json
@ -2114,44 +2112,32 @@ RSpec.describe 'Ticket', type: :request do
context 'when ticket.group.follow_up_possible = "yes"' do
before { ticket.group.update(follow_up_possible: 'yes') }
context 'as admin' do
include_examples 'successfully reopen a ticket' do
let(:user) { admin }
end
context 'as admin', authenticated_as: -> { admin } do
include_examples 'successfully reopen a ticket'
end
context 'as agent' do
include_examples 'successfully reopen a ticket' do
let(:user) { agent }
end
context 'as agent', authenticated_as: -> { agent } do
include_examples 'successfully reopen a ticket'
end
context 'as customer' do
include_examples 'successfully reopen a ticket' do
let(:user) { customer }
end
context 'as customer', authenticated_as: -> { customer } do
include_examples 'successfully reopen a ticket'
end
end
context 'when ticket.group.follow_up_possible = "new_ticket"' do
before { ticket.group.update(follow_up_possible: 'new_ticket') }
context 'as admin' do
include_examples 'successfully reopen a ticket' do
let(:user) { admin }
end
context 'as admin', authenticated_as: -> { admin } do
include_examples 'successfully reopen a ticket'
end
context 'as agent' do
include_examples 'successfully reopen a ticket' do
let(:user) { agent }
end
context 'as agent', authenticated_as: -> { agent } do
include_examples 'successfully reopen a ticket'
end
context 'as customer' do
include_examples 'fail to reopen a ticket' do
let(:user) { customer }
end
context 'as customer', authenticated_as: -> { customer } do
include_examples 'fail to reopen a ticket'
end
end
end

View file

@ -1,5 +1,7 @@
RSpec.configure do |config|
config.before(:each) do
# Cache setup must be the first before hook
# Otherwise authenticated_as hook fails with random errors
config.prepend_before(:each) do
# clear the cache otherwise it won't
# be able to recognize the rollbacks
# done by RSpec

View file

@ -1,11 +1,6 @@
RSpec.configure do |config|
config.before(:each, type: :system) do |example|
# make sure system is in a fresh state
Cache.clear
Setting.reload
BulkImportInfo.disable
# check if system is already set up
next if Setting.get('system_init_done')

View file

@ -143,6 +143,12 @@ RSpec.configure do |config|
# let(:user) { create(:customer_user) }
#
config.before(:each, :authenticated_as) do |example|
authenticated_as(send(example.metadata[:authenticated_as]))
@current_user = if example.metadata[:authenticated_as].is_a? Proc
instance_exec(&example.metadata[:authenticated_as])
else
create(*Array(example.metadata[:authenticated_as]))
end
authenticated_as @current_user unless @current_user.nil?
end
end