4533: Replace enable_remote_reset config knob with check for existence of non-fixture...
[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   test "reset fails with non-admin token" do
7     authorize_with :active
8     post :reset
9     assert_response 403
10   end
11
12   test "route not found when not in test mode" do
13     authorize_with :admin
14     env_was = Rails.env
15     Rails.application.reload_routes!
16     begin
17       assert_raises ActionController::RoutingError do
18         Rails.env = 'production'
19         Rails.application.reload_routes!
20         post :reset
21       end
22     ensure
23       Rails.env = env_was
24       Rails.application.reload_routes!
25     end
26   end
27
28   test "reset fails when a non-test-fixture user exists" do
29     act_as_system_user do
30       User.create!(uuid: 'abcde-tpzed-123451234512345', email: 'bar@example.net')
31     end
32     authorize_with :admin
33     post :reset
34     assert_response 403
35   end
36
37   test "reset succeeds with admin token" do
38     new_uuid = nil
39     act_as_system_user do
40       new_uuid = Specimen.create.uuid
41     end
42     assert_not_empty Specimen.where(uuid: new_uuid)
43     authorize_with :admin
44     post :reset
45     assert_response 200
46     assert_empty Specimen.where(uuid: new_uuid)
47   end
48 end