1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class SelectTest < ActionDispatch::IntegrationTest
8 test "should select just two columns" do
9 get "/arvados/v1/links", {:format => :json, :select => ['uuid', 'link_class']}, auth(:active)
10 assert_response :success
11 assert_equal json_response['items'].count, json_response['items'].select { |i|
12 i.count == 3 and i['uuid'] != nil and i['link_class'] != nil
16 test "fewer distinct than total count" do
17 get "/arvados/v1/links", {:format => :json, :select => ['link_class'], :distinct => false}, auth(:active)
18 assert_response :success
19 links = json_response['items']
21 get "/arvados/v1/links", {:format => :json, :select => ['link_class'], :distinct => true}, auth(:active)
22 assert_response :success
23 distinct = json_response['items']
25 assert_operator(distinct.count, :<, links.count,
26 "distinct count should be less than link count")
27 assert_equal links.uniq.count, distinct.count
30 test "select with order" do
31 get "/arvados/v1/links", {:format => :json, :select => ['uuid'], :order => ["uuid asc"]}, auth(:active)
32 assert_response :success
34 assert json_response['items'].length > 0
37 json_response['items'].each do |i|
43 test "select with default order" do
44 get "/arvados/v1/links", {format: :json, select: ['uuid']}, auth(:admin)
45 assert_response :success
46 uuids = json_response['items'].collect { |i| i['uuid'] }
47 assert_equal uuids, uuids.sort
50 def assert_link_classes_ascend(current_class, prev_class)
51 # Databases and Ruby don't always agree about string ordering with
52 # punctuation. If the strings aren't ascending normally, check
53 # that they're equal up to punctuation.
54 if current_class < prev_class
55 class_prefix = current_class.split(/\W/).first
56 assert prev_class.start_with?(class_prefix)
60 test "select two columns with order" do
61 get "/arvados/v1/links", {:format => :json, :select => ['link_class', 'uuid'], :order => ['link_class asc', "uuid desc"]}, auth(:active)
62 assert_response :success
64 assert json_response['items'].length > 0
67 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
69 json_response['items'].each do |i|
70 if prev_link_class != i['link_class']
71 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
74 assert_link_classes_ascend(i['link_class'], prev_link_class)
75 assert i['uuid'] < prev_uuid
77 prev_link_class = i['link_class']
82 test "select two columns with old-style order syntax" do
83 get "/arvados/v1/links", {:format => :json, :select => ['link_class', 'uuid'], :order => 'link_class asc, uuid desc'}, auth(:active)
84 assert_response :success
86 assert json_response['items'].length > 0
89 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
91 json_response['items'].each do |i|
92 if prev_link_class != i['link_class']
93 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
96 assert_link_classes_ascend(i['link_class'], prev_link_class)
97 assert i['uuid'] < prev_uuid
99 prev_link_class = i['link_class']
100 prev_uuid = i['uuid']