3 class ApplicationControllerTest < ActionController::TestCase
5 test "links for object" do
8 ac = ApplicationController.new
10 link_head_uuid = api_fixture('links')['foo_file_readable_by_active']['head_uuid']
12 links = ac.send :links_for_object, link_head_uuid
14 assert links, 'Expected links'
15 assert links.is_a?(Array), 'Expected an array'
16 assert links.size > 0, 'Expected at least one link'
17 assert links[0][:uuid], 'Expected uuid for the head_link'
20 test "links for no such object" do
23 ac = ApplicationController.new
25 links = ac.send :links_for_object, "no-such-uuid"
27 assert links, 'Expected links'
28 assert links.is_a?(Array), 'Expected an array'
29 assert links.size == 0, 'Expected no links'
32 test "preload links for given uuids" do
35 ac = ApplicationController.new
37 link_head_uuid1 = api_fixture('links')['foo_file_readable_by_active']['head_uuid']
38 link_head_uuid2 = api_fixture('links')['bar_file_readable_by_active']['head_uuid']
40 uuids = [link_head_uuid1, link_head_uuid2]
41 links = ac.send :preload_links_for_objects, uuids
43 assert links, 'Expected links'
44 assert links.is_a?(Hash), 'Expected a hash'
45 assert links.size == 2, 'Expected two objects in the preloaded links hash'
46 assert links[link_head_uuid1], 'Expected links for the passed in head_uuid'
47 assert links[link_head_uuid2], 'Expected links for the passed in head_uuid'
50 test "preload links for object and uuids" do
53 ac = ApplicationController.new
55 link1_head_uuid = api_fixture('links')['foo_file_readable_by_active']['head_uuid']
56 link2_uuid = api_fixture('links')['bar_file_readable_by_active']['uuid']
57 link3_head_uuid = api_fixture('links')['bar_file_readable_by_active']['head_uuid']
59 link2_object = User.find(api_fixture('users')['active']['uuid'])
60 link2_object_uuid = link2_object['uuid']
62 uuids = [link1_head_uuid, link2_object, link3_head_uuid]
63 links = ac.send :preload_links_for_objects, uuids
65 assert links, 'Expected links'
66 assert links.is_a?(Hash), 'Expected a hash'
67 assert links.size == 3, 'Expected two objects in the preloaded links hash'
68 assert links[link1_head_uuid], 'Expected links for the passed in link head_uuid'
69 assert links[link2_object_uuid], 'Expected links for the passed in object uuid'
70 assert links[link3_head_uuid], 'Expected links for the passed in link head_uuid'
73 test "preload links for wrong typed input" do
76 ac = ApplicationController.new
78 assert_raise ArgumentError do
79 links = ac.send :preload_links_for_objects, 'input not an array'
83 test "preload links for nil input" do
86 ac = ApplicationController.new
88 assert_raise ArgumentError do
89 links = ac.send :preload_links_for_objects, nil
93 test "preload links for empty array input" do
96 ac = ApplicationController.new
98 links = ac.send :preload_links_for_objects, []
100 assert links, 'Expected links'
101 assert links.is_a?(Hash), 'Expected a hash'
102 assert links.size == 0, 'Expected no objects in the preloaded links hash'