4533: Merge branch 'master' into 4533-remote-reset
[arvados.git] / services / api / test / functional / database_controller_test.rb
1 require 'test_helper'
2
3 class DatabaseControllerTest < ActionController::TestCase
4   include CurrentApiClient
5
6   teardown do
7     restore_configuration
8     # We made configuration changes here that affect routing.
9     Rails.application.reload_routes!
10   end
11
12   test "reset fails with non-admin token" do
13     authorize_with :active
14     post :reset
15     assert_response 403
16   end
17
18   test "reset fails when not in test mode" do
19     authorize_with :admin
20     env_was = Rails.env
21     begin
22       Rails.env = 'development'
23       post :reset
24       assert_response 403
25     ensure
26       Rails.env = env_was
27     end
28   end
29
30   test "reset fails when not configured" do
31     Rails.configuration.enable_remote_database_reset = false
32     Rails.application.reload_routes!
33     authorize_with :admin
34     assert_raise ActionController::RoutingError do
35       post :reset
36     end
37   end
38
39   test "reset succeeds with admin token" do
40     new_uuid = nil
41     act_as_system_user do
42       new_uuid = Specimen.create.uuid
43     end
44     assert_not_empty Specimen.where(uuid: new_uuid)
45     authorize_with :admin
46     post :reset
47     assert_response 200
48     assert_empty Specimen.where(uuid: new_uuid)
49   end
50 end