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 def assert_link_classes_ascend(current_class, prev_class)
40 # Databases and Ruby don't always agree about string ordering with
41 # punctuation. If the strings aren't ascending normally, check
42 # that they're equal up to punctuation.
43 if current_class < prev_class
44 class_prefix = current_class.split(/\W/).first
45 assert prev_class.start_with?(class_prefix)
49 test "select two columns with order" do
50 get "/arvados/v1/links", {:format => :json, :select => ['link_class', 'uuid'], :order => ['link_class asc', "uuid desc"]}, auth(:active)
51 assert_response :success
53 assert json_response['items'].length > 0
56 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
58 json_response['items'].each do |i|
59 if prev_link_class != i['link_class']
60 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
63 assert_link_classes_ascend(i['link_class'], prev_link_class)
64 assert i['uuid'] < prev_uuid
66 prev_link_class = i['link_class']
71 test "select two columns with old-style order syntax" do
72 get "/arvados/v1/links", {:format => :json, :select => ['link_class', 'uuid'], :order => 'link_class asc, uuid desc'}, auth(:active)
73 assert_response :success
75 assert json_response['items'].length > 0
78 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
80 json_response['items'].each do |i|
81 if prev_link_class != i['link_class']
82 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
85 assert_link_classes_ascend(i['link_class'], prev_link_class)
86 assert i['uuid'] < prev_uuid
88 prev_link_class = i['link_class']