3 class DatabaseResetTest < ActionDispatch::IntegrationTest
4 self.use_transactional_fixtures = false
6 test "reset fails when Rails.env != 'test'" do
8 rails_env_was = Rails.env
10 Rails.env = 'production'
11 Rails.application.reload_routes!
12 post '/database/reset', {}, auth(:admin)
15 Rails.env = rails_env_was
16 Rails.application.reload_routes!
20 test "reset fails with non-admin token" do
21 post '/database/reset', {}, auth(:active)
25 test "database reset doesn't break basic CRUD operations" do
27 active_auth = auth(:active)
28 admin_auth = auth(:admin)
31 post '/database/reset', {}, admin_auth
32 assert_response :success
34 post '/arvados/v1/specimens', {specimen: '{}'}, active_auth
35 assert_response :success
36 new_uuid = json_response['uuid']
38 get '/arvados/v1/specimens/'+new_uuid, {}, active_auth
39 assert_response :success
41 put('/arvados/v1/specimens/'+new_uuid,
42 {specimen: '{"properties":{}}'}, active_auth)
43 assert_response :success
45 delete '/arvados/v1/specimens/'+new_uuid, {}, active_auth
46 assert_response :success
48 get '/arvados/v1/specimens/'+new_uuid, {}, active_auth
52 test "roll back database change" do
54 active_auth = auth(:active)
55 admin_auth = auth(:admin)
57 old_uuid = specimens(:owned_by_active_user).uuid
59 post '/database/reset', {}, admin_auth
60 assert_response :success
62 delete '/arvados/v1/specimens/' + old_uuid, {}, active_auth
63 assert_response :success
64 post '/arvados/v1/specimens', {specimen: '{}'}, active_auth
65 assert_response :success
66 new_uuid = json_response['uuid']
69 post '/database/reset', {}, admin_auth
70 assert_response :success
72 # New specimen should disappear. Old specimen should reappear.
73 get '/arvados/v1/specimens/'+new_uuid, {}, active_auth
75 get '/arvados/v1/specimens/'+old_uuid, {}, active_auth
76 assert_response :success