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