Merge branch 'master' of git.curoverse.com:arvados into 11876-r-sdk
[arvados.git] / services / api / test / unit / application_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6
7 class ApplicationTest < ActiveSupport::TestCase
8   include CurrentApiClient
9
10   test "test act_as_system_user" do
11     Thread.current[:user] = users(:active)
12     assert_equal users(:active), Thread.current[:user]
13     act_as_system_user do
14       assert_not_equal users(:active), Thread.current[:user]
15       assert_equal system_user, Thread.current[:user]
16     end
17     assert_equal users(:active), Thread.current[:user]
18   end
19
20   test "test act_as_system_user is exception safe" do
21     Thread.current[:user] = users(:active)
22     assert_equal users(:active), Thread.current[:user]
23     caught = false
24     begin
25       act_as_system_user do
26         assert_not_equal users(:active), Thread.current[:user]
27         assert_equal system_user, Thread.current[:user]
28         raise "Fail"
29       end
30     rescue
31       caught = true
32     end
33     assert caught
34     assert_equal users(:active), Thread.current[:user]
35   end
36 end