3 class ApplicationControllerTest < ActionController::TestCase
4 BAD_UUID = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
11 # These tests are meant to check behavior in ApplicationController.
12 # We instantiate a small concrete controller for convenience.
13 @controller = Arvados::V1::SpecimensController.new
14 @start_stamp = now_timestamp
18 token = json_response['error_token']
20 token_time = token.split('+', 2).first.to_i
21 assert_operator(token_time, :>=, @start_stamp, "error token too old")
22 assert_operator(token_time, :<=, now_timestamp, "error token too new")
25 def check_404(errmsg="Path not found")
27 assert_equal([errmsg], json_response['errors'])
31 test "requesting nonexistent object returns 404 error" do
33 get(:show, id: BAD_UUID)
37 test "requesting object without read permission returns 404 error" do
38 authorize_with :spectator
39 get(:show, id: specimens(:owned_by_active_user).uuid)
43 test "submitting bad object returns error" do
44 authorize_with :spectator
45 post(:create, specimen: {badattr: "badvalue"})
50 ['foo', '', 'FALSE', 'TRUE', nil, [true], {a:true}, '"true"'].each do |bogus|
51 test "bogus boolean parameter #{bogus.inspect} returns error" do
52 @controller = Arvados::V1::GroupsController.new
53 authorize_with :active
56 ensure_unique_name: bogus
59 assert_match(/parameter must be a boolean/, json_response['errors'].first,
60 'Helpful error message not found')
64 [[true, [true, 'true', 1, '1']],
65 [false, [false, 'false', 0, '0']]].each do |bool, boolparams|
66 boolparams.each do |boolparam|
67 # Ensure boolparam is acceptable as a boolean
68 test "boolean parameter #{boolparam.inspect} acceptable" do
69 @controller = Arvados::V1::GroupsController.new
70 authorize_with :active
73 ensure_unique_name: boolparam
75 assert_response :success
78 # Ensure boolparam is acceptable as the _intended_ boolean
79 test "boolean parameter #{boolparam.inspect} accepted as #{bool.inspect}" do
80 @controller = Arvados::V1::GroupsController.new
81 authorize_with :active
84 name: groups(:aproject).name,
85 owner_uuid: groups(:aproject).owner_uuid
87 ensure_unique_name: boolparam
89 assert_response (bool ? :success : 422)