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 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 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'
105 test "collections for object" do
108 ac = ApplicationController.new
110 uuid = api_fixture('collections')['foo_file']['uuid']
112 collections = ac.send :collections_for_object, uuid
114 assert collections, 'Expected collections'
115 assert collections.is_a?(Array), 'Expected an array'
116 assert collections.size == 1, 'Expected one collection object'
117 assert_equal collections[0][:uuid], uuid, 'Expected uuid not found in collections'
120 test "collections for no such object" do
123 ac = ApplicationController.new
125 collections = ac.send :collections_for_object, "no-such-uuid"
127 assert collections, 'Expected collections'
128 assert collections.is_a?(Array), 'Expected an array'
129 assert collections.size == 0, 'Expected no collection'
132 test "preload collections for given uuids" do
135 ac = ApplicationController.new
137 uuid1 = api_fixture('collections')['foo_file']['uuid']
138 uuid2 = api_fixture('collections')['bar_file']['uuid']
140 uuids = [uuid1, uuid2]
141 collections = ac.send :preload_collections_for_objects, uuids
143 assert collections, 'Expected collection'
144 assert collections.is_a?(Hash), 'Expected a hash'
145 assert collections.size == 2, 'Expected two objects in the preloaded collection hash'
146 assert collections[uuid1], 'Expected collections for the passed in uuid'
147 assert_equal collections[uuid1].size, 1, 'Expected one collection for the passed in uuid'
148 assert collections[uuid2], 'Expected collections for the passed in uuid'
149 assert_equal collections[uuid2].size, 1, 'Expected one collection for the passed in uuid'
152 test "preload collections for wrong typed input" do
155 ac = ApplicationController.new
157 assert_raise ArgumentError do
158 ac.send :preload_collections_for_objects, 'input not an array'
162 test "preload collections for nil input" do
165 ac = ApplicationController.new
167 assert_raise ArgumentError do
168 ac.send :preload_collections_for_objects, nil
172 test "preload collections for empty array input" do
175 ac = ApplicationController.new
177 collections = ac.send :preload_links_for_objects, []
179 assert collections, 'Expected collections'
180 assert collections.is_a?(Hash), 'Expected a hash'
181 assert collections.size == 0, 'Expected no objects in the preloaded collections hash'