diff options
Diffstat (limited to 'spec/controllers/sessions_controller_spec.rb')
-rw-r--r-- | spec/controllers/sessions_controller_spec.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index 2f597fd5cb3..a677e17ab0c 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -495,4 +495,45 @@ describe SessionsController do expect(session[:failed_login_attempts]).to eq(1) end end + + describe '#set_current_context' do + before do + set_devise_mapping(context: @request) + end + + context 'when signed in' do + let_it_be(:user) { create(:user) } + + before do + sign_in(user) + end + + it 'sets the username and caller_id in the context' do + expect(controller).to receive(:destroy).and_wrap_original do |m, *args| + expect(Labkit::Context.current.to_h) + .to include('meta.user' => user.username, + 'meta.caller_id' => 'SessionsController#destroy') + + m.call(*args) + end + + delete :destroy + end + end + + context 'when not signed in' do + it 'sets the caller_id in the context' do + expect(controller).to receive(:new).and_wrap_original do |m, *args| + expect(Labkit::Context.current.to_h) + .to include('meta.caller_id' => 'SessionsController#new') + expect(Labkit::Context.current.to_h) + .not_to include('meta.user') + + m.call(*args) + end + + get :new + end + end + end end |