Fix 2.4.2 upgrade notes formatting refs #19330
[arvados.git] / apps / workbench / test / unit / arvados_base_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6
7 class ArvadosBaseTest < ActiveSupport::TestCase
8   test '#save does not send unchanged string attributes' do
9     use_token :active do
10       fixture = api_fixture("collections")["foo_collection_in_aproject"]
11       c = Collection.find(fixture['uuid'])
12
13       new_name = 'name changed during test'
14
15       got_query = nil
16       stub_api_calls
17       stub_api_client.expects(:post).with do |url, query, opts={}|
18         got_query = query
19         true
20       end.returns fake_api_response('{}', 200, {})
21       c.name = new_name
22       c.save
23
24       updates = JSON.parse got_query['collection']
25       assert_equal updates['name'], new_name
26       refute_includes updates, 'description'
27       refute_includes updates, 'manifest_text'
28     end
29   end
30
31   test '#save does not send unchanged attributes missing because of select' do
32     use_token :active do
33       fixture = api_fixture("collections")["foo_collection_in_aproject"]
34       c = Collection.
35         filter([['uuid','=',fixture['uuid']]]).
36         select(['uuid']).
37         first
38       if 'MissingAttribute check is re-enabled' == true
39         assert_raises ActiveModel::MissingAttributeError do
40           c.properties
41         end
42       else
43         assert_equal({}, c.properties)
44       end
45
46       got_query = nil
47       stub_api_calls
48       stub_api_client.expects(:post).with do |url, query, opts={}|
49         got_query = query
50         true
51       end.returns fake_api_response('{}', 200, {})
52       c.name = 'foo'
53       c.save
54
55       updates = JSON.parse got_query['collection']
56       assert_includes updates, 'name'
57       refute_includes updates, 'description'
58       refute_includes updates, 'properties'
59     end
60   end
61
62   [false,
63    {},
64    {'foo' => 'bar'},
65   ].each do |init_props|
66     test "#save sends serialized attributes if changed from #{init_props}" do
67       use_token :active do
68         fixture = api_fixture("collections")["foo_collection_in_aproject"]
69         c = Collection.find(fixture['uuid'])
70
71         if init_props
72           c.properties = init_props if init_props
73           c.save!
74         end
75
76         got_query = nil
77         stub_api_calls
78         stub_api_client.expects(:post).with do |url, query, opts={}|
79           got_query = query
80           true
81         end.returns fake_api_response('{"etag":"fake","uuid":"fake"}', 200, {})
82
83         c.properties['baz'] = 'qux'
84         c.save!
85
86         updates = JSON.parse got_query['collection']
87         assert_includes updates, 'properties'
88       end
89     end
90   end
91 end