8784: Fix test for latest firefox.
[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       if 'MissingAttribute check is re-enabled' == true
35         assert_raises ActiveModel::MissingAttributeError do
36           c.properties
37         end
38       else
39         assert_equal({}, c.properties)
40       end
41
42       got_query = nil
43       stub_api_calls
44       stub_api_client.expects(:post).with do |url, query, opts={}|
45         got_query = query
46         true
47       end.returns fake_api_response('{}', 200, {})
48       c.name = 'foo'
49       c.save
50
51       updates = JSON.parse got_query['collection']
52       assert_includes updates, 'name'
53       refute_includes updates, 'description'
54       refute_includes updates, 'properties'
55     end
56   end
57
58   [false,
59    {},
60    {'foo' => 'bar'},
61   ].each do |init_props|
62     test "#save sends serialized attributes if changed from #{init_props}" do
63       use_token :active do
64         fixture = api_fixture("collections")["foo_collection_in_aproject"]
65         c = Collection.find(fixture['uuid'])
66
67         if init_props
68           c.properties = init_props if init_props
69           c.save!
70         end
71
72         got_query = nil
73         stub_api_calls
74         stub_api_client.expects(:post).with do |url, query, opts={}|
75           got_query = query
76           true
77         end.returns fake_api_response('{"etag":"fake","uuid":"fake"}', 200, {})
78
79         c.properties['baz'] = 'qux'
80         c.save!
81
82         updates = JSON.parse got_query['collection']
83         assert_includes updates, 'properties'
84       end
85     end
86   end
87 end