diff --git a/spec/requests/ticket_spec.rb b/spec/requests/ticket_spec.rb index 7bb90f188..148481027 100644 --- a/spec/requests/ticket_spec.rb +++ b/spec/requests/ticket_spec.rb @@ -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 diff --git a/spec/support/cache.rb b/spec/support/cache.rb index ca769af4f..256509030 100644 --- a/spec/support/cache.rb +++ b/spec/support/cache.rb @@ -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 diff --git a/spec/support/capybara/set_up.rb b/spec/support/capybara/set_up.rb index f9a83e03f..8048567dc 100644 --- a/spec/support/capybara/set_up.rb +++ b/spec/support/capybara/set_up.rb @@ -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') diff --git a/spec/support/request.rb b/spec/support/request.rb index 4eccddfe6..e94dcfc93 100644 --- a/spec/support/request.rb +++ b/spec/support/request.rb @@ -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