3 class SelectTest < ActionDispatch::IntegrationTest
4 test "should select just two columns" do
5 get "/arvados/v1/links", {:format => :json, :select => ['uuid', 'link_class']}, auth(:active)
6 assert_response :success
7 assert_equal json_response['items'].count, json_response['items'].select { |i|
8 i.count == 3 and i['uuid'] != nil and i['link_class'] != nil
12 test "fewer distinct than total count" do
13 get "/arvados/v1/links", {:format => :json, :select => ['link_class'], :distinct => false}, auth(:active)
14 assert_response :success
15 links = json_response['items']
17 get "/arvados/v1/links", {:format => :json, :select => ['link_class'], :distinct => true}, auth(:active)
18 assert_response :success
19 distinct = json_response['items']
21 assert_operator(distinct.count, :<, links.count,
22 "distinct count should be less than link count")
23 assert_equal links.uniq.count, distinct.count
26 test "select with order" do
27 get "/arvados/v1/links", {:format => :json, :select => ['uuid'], :order => ["uuid asc"]}, auth(:active)
28 assert_response :success
30 assert json_response['items'].length > 0
33 json_response['items'].each do |i|
39 test "select with default order" do
40 get "/arvados/v1/links", {format: :json, select: ['uuid']}, auth(:admin)
41 assert_response :success
42 uuids = json_response['items'].collect { |i| i['uuid'] }
43 assert_equal uuids, uuids.sort
46 def assert_link_classes_ascend(current_class, prev_class)
47 # Databases and Ruby don't always agree about string ordering with
48 # punctuation. If the strings aren't ascending normally, check
49 # that they're equal up to punctuation.
50 if current_class < prev_class
51 class_prefix = current_class.split(/\W/).first
52 assert prev_class.start_with?(class_prefix)
56 test "select two columns with order" do
57 get "/arvados/v1/links", {:format => :json, :select => ['link_class', 'uuid'], :order => ['link_class asc', "uuid desc"]}, auth(:active)
58 assert_response :success
60 assert json_response['items'].length > 0
63 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
65 json_response['items'].each do |i|
66 if prev_link_class != i['link_class']
67 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
70 assert_link_classes_ascend(i['link_class'], prev_link_class)
71 assert i['uuid'] < prev_uuid
73 prev_link_class = i['link_class']
78 test "select two columns with old-style order syntax" do
79 get "/arvados/v1/links", {:format => :json, :select => ['link_class', 'uuid'], :order => 'link_class asc, uuid desc'}, auth(:active)
80 assert_response :success
82 assert json_response['items'].length > 0
85 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
87 json_response['items'].each do |i|
88 if prev_link_class != i['link_class']
89 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
92 assert_link_classes_ascend(i['link_class'], prev_link_class)
93 assert i['uuid'] < prev_uuid
95 prev_link_class = i['link_class']