4533: Reset fixtures after each test case by default.
[arvados.git] / services / api / test / integration / remote_reset_test.rb
1 require 'test_helper'
2
3 class RemoteResetTest < ActionDispatch::IntegrationTest
4   self.use_transactional_fixtures = false
5
6   test "roll back database change" do
7     active_auth = auth(:active)
8     admin_auth = auth(:admin)
9
10     old_uuid = specimens(:owned_by_active_user).uuid
11     new_uuid = nil
12     authorize_with :admin
13     post '/database/reset', {}, admin_auth
14     assert_response :success
15
16     delete '/arvados/v1/specimens/' + old_uuid, {}, active_auth
17     assert_response :success
18     post '/arvados/v1/specimens', {specimen: '{}'}, active_auth
19     assert_response :success
20     new_uuid = json_response['uuid']
21
22     # Perhaps redundant: confirm the above changes are observable from
23     # here using get(). Otherwise, the assertions below would not be
24     # informative. (Aside from confirming that integration-testing
25     # features work, this confirms that /database/reset didn't somehow
26     # put the database into a "don't persist any changes" mode -- not
27     # that I can think of a way for that to happen.)
28     get '/arvados/v1/specimens/'+new_uuid, {}, active_auth
29     assert_response :success
30     get '/arvados/v1/specimens/'+old_uuid, {}, active_auth
31     assert_response 404
32
33     # Reset to fixtures.
34     post '/database/reset', {}, admin_auth
35     assert_response :success
36
37     # New speciment should disappear. Old specimen should reappear.
38     get '/arvados/v1/specimens/'+new_uuid, {}, active_auth
39     assert_response 404
40     get '/arvados/v1/specimens/'+old_uuid, {}, active_auth
41     assert_response :success
42     assert_empty Specimen.where(uuid: new_uuid)
43   end
44 end