3 class DatabaseResetTest < ActionDispatch::IntegrationTest
4 self.use_transactional_fixtures = false
6 test "reset fails when Rails.env != 'test'" do
7 rails_env_was = Rails.env
9 Rails.env = 'production'
10 Rails.application.reload_routes!
11 post '/database/reset', {}, auth(:admin)
14 Rails.env = rails_env_was
15 Rails.application.reload_routes!
19 test "reset fails with non-admin token" do
20 post '/database/reset', {}, auth(:active)
24 test "database reset doesn't break basic CRUD operations" do
25 active_auth = auth(:active)
26 admin_auth = auth(:admin)
29 post '/database/reset', {}, admin_auth
30 assert_response :success
32 post '/arvados/v1/specimens', {specimen: '{}'}, active_auth
33 assert_response :success
34 new_uuid = json_response['uuid']
36 get '/arvados/v1/specimens/'+new_uuid, {}, active_auth
37 assert_response :success
39 put('/arvados/v1/specimens/'+new_uuid,
40 {specimen: '{"properties":{}}'}, active_auth)
41 assert_response :success
43 delete '/arvados/v1/specimens/'+new_uuid, {}, active_auth
44 assert_response :success
46 get '/arvados/v1/specimens/'+new_uuid, {}, active_auth
50 test "roll back database change" do
51 active_auth = auth(:active)
52 admin_auth = auth(:admin)
54 old_uuid = specimens(:owned_by_active_user).uuid
56 post '/database/reset', {}, admin_auth
57 assert_response :success
59 delete '/arvados/v1/specimens/' + old_uuid, {}, active_auth
60 assert_response :success
61 post '/arvados/v1/specimens', {specimen: '{}'}, active_auth
62 assert_response :success
63 new_uuid = json_response['uuid']
66 post '/database/reset', {}, admin_auth
67 assert_response :success
69 # New specimen should disappear. Old specimen should reappear.
70 get '/arvados/v1/specimens/'+new_uuid, {}, active_auth
72 get '/arvados/v1/specimens/'+old_uuid, {}, active_auth
73 assert_response :success