Fixes #3315 - nested "view from user perspective" yield to only being able to return to last viewed session
This commit is contained in:
parent
f75e18ab36
commit
9ea4ce9d2f
2 changed files with 53 additions and 2 deletions
|
@ -129,8 +129,8 @@ class SessionsController < ApplicationController
|
|||
return false
|
||||
end
|
||||
|
||||
# remember old user
|
||||
session[:switched_from_user_id] = current_user.id
|
||||
# remember original user
|
||||
session[:switched_from_user_id] ||= current_user.id
|
||||
|
||||
# log new session
|
||||
user.activity_stream_log('switch to', current_user.id, true)
|
||||
|
|
51
spec/system/manage/users_spec.rb
Normal file
51
spec/system/manage/users_spec.rb
Normal file
|
@ -0,0 +1,51 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Manage > Users', type: :system do
|
||||
describe 'switching to an alternative user', authenticated_as: -> { original_user } do
|
||||
let(:original_user) { create(:admin) }
|
||||
let(:alternative_one_user) { create(:admin) }
|
||||
let(:alternative_two_user) { create(:admin) }
|
||||
|
||||
before do
|
||||
alternative_one_user
|
||||
alternative_two_user
|
||||
end
|
||||
|
||||
it 'starts as original user' do
|
||||
expect(current_user).to eq original_user
|
||||
end
|
||||
|
||||
it 'switches to alternative user' do
|
||||
switch_to(alternative_one_user)
|
||||
expect(current_user).to eq alternative_one_user
|
||||
end
|
||||
|
||||
it 'switches to another alternative user' do
|
||||
switch_to(alternative_one_user)
|
||||
switch_to(alternative_two_user)
|
||||
|
||||
expect(current_user).to eq alternative_two_user
|
||||
end
|
||||
|
||||
it 'switches back to original user' do
|
||||
switch_to(alternative_one_user)
|
||||
switch_to(alternative_two_user)
|
||||
|
||||
click '.switchBackToUser-close'
|
||||
|
||||
expect(current_user).to eq original_user
|
||||
end
|
||||
|
||||
def switch_to(user)
|
||||
visit 'manage/users'
|
||||
|
||||
within(:active_content) do
|
||||
row = find("tr[data-id=\"#{user.id}\"]")
|
||||
row.find('.js-action').click
|
||||
row.find('.js-switchTo').click
|
||||
end
|
||||
|
||||
await_empty_ajax_queue
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue