Maintenance: Fixed caching issue in authenticate_as
spec helper and enhanced capabilities.
This commit is contained in:
parent
4767aa0771
commit
48766c7db9
4 changed files with 22 additions and 33 deletions
|
@ -2089,7 +2089,6 @@ RSpec.describe 'Ticket', type: :request do
|
||||||
describe 'reopening a ticket' do
|
describe 'reopening a ticket' do
|
||||||
shared_examples 'successfully reopen a ticket' do
|
shared_examples 'successfully reopen a ticket' do
|
||||||
it 'succeeds' do
|
it 'succeeds' do
|
||||||
authenticated_as(user)
|
|
||||||
put "/api/v1/tickets/#{ticket.id}",
|
put "/api/v1/tickets/#{ticket.id}",
|
||||||
params: { state_id: Ticket::State.find_by(name: 'open').id },
|
params: { state_id: Ticket::State.find_by(name: 'open').id },
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -2101,7 +2100,6 @@ RSpec.describe 'Ticket', type: :request do
|
||||||
|
|
||||||
shared_examples 'fail to reopen a ticket' do
|
shared_examples 'fail to reopen a ticket' do
|
||||||
it 'fails' do
|
it 'fails' do
|
||||||
authenticated_as(user)
|
|
||||||
put "/api/v1/tickets/#{ticket.id}",
|
put "/api/v1/tickets/#{ticket.id}",
|
||||||
params: { state_id: Ticket::State.find_by(name: 'open').id },
|
params: { state_id: Ticket::State.find_by(name: 'open').id },
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -2114,44 +2112,32 @@ RSpec.describe 'Ticket', type: :request do
|
||||||
context 'when ticket.group.follow_up_possible = "yes"' do
|
context 'when ticket.group.follow_up_possible = "yes"' do
|
||||||
before { ticket.group.update(follow_up_possible: 'yes') }
|
before { ticket.group.update(follow_up_possible: 'yes') }
|
||||||
|
|
||||||
context 'as admin' do
|
context 'as admin', authenticated_as: -> { admin } do
|
||||||
include_examples 'successfully reopen a ticket' do
|
include_examples 'successfully reopen a ticket'
|
||||||
let(:user) { admin }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'as agent' do
|
context 'as agent', authenticated_as: -> { agent } do
|
||||||
include_examples 'successfully reopen a ticket' do
|
include_examples 'successfully reopen a ticket'
|
||||||
let(:user) { agent }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'as customer' do
|
context 'as customer', authenticated_as: -> { customer } do
|
||||||
include_examples 'successfully reopen a ticket' do
|
include_examples 'successfully reopen a ticket'
|
||||||
let(:user) { customer }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when ticket.group.follow_up_possible = "new_ticket"' do
|
context 'when ticket.group.follow_up_possible = "new_ticket"' do
|
||||||
before { ticket.group.update(follow_up_possible: 'new_ticket') }
|
before { ticket.group.update(follow_up_possible: 'new_ticket') }
|
||||||
|
|
||||||
context 'as admin' do
|
context 'as admin', authenticated_as: -> { admin } do
|
||||||
include_examples 'successfully reopen a ticket' do
|
include_examples 'successfully reopen a ticket'
|
||||||
let(:user) { admin }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'as agent' do
|
context 'as agent', authenticated_as: -> { agent } do
|
||||||
include_examples 'successfully reopen a ticket' do
|
include_examples 'successfully reopen a ticket'
|
||||||
let(:user) { agent }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'as customer' do
|
context 'as customer', authenticated_as: -> { customer } do
|
||||||
include_examples 'fail to reopen a ticket' do
|
include_examples 'fail to reopen a ticket'
|
||||||
let(:user) { customer }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
RSpec.configure do |config|
|
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
|
# clear the cache otherwise it won't
|
||||||
# be able to recognize the rollbacks
|
# be able to recognize the rollbacks
|
||||||
# done by RSpec
|
# done by RSpec
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.before(:each, type: :system) do |example|
|
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
|
# check if system is already set up
|
||||||
next if Setting.get('system_init_done')
|
next if Setting.get('system_init_done')
|
||||||
|
|
||||||
|
|
|
@ -143,6 +143,12 @@ RSpec.configure do |config|
|
||||||
# let(:user) { create(:customer_user) }
|
# let(:user) { create(:customer_user) }
|
||||||
#
|
#
|
||||||
config.before(:each, :authenticated_as) do |example|
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue