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 == 2 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 distinct.count < links.count, "distinct count should be less than link count"
22 assert_equal links.uniq.count, distinct.count
25 test "select with order" do
26 get "/arvados/v1/links", {:format => :json, :select => ['uuid'], :order => ["uuid asc"]}, auth(:active)
27 assert_response :success
29 assert json_response['items'].length > 0
32 json_response['items'].each do |i|
38 def assert_link_classes_ascend(current_class, prev_class)
39 # Databases and Ruby don't always agree about string ordering with
40 # punctuation. If the strings aren't ascending normally, check
41 # that they're equal up to punctuation.
42 if current_class < prev_class
43 class_prefix = current_class.split(/\W/).first
44 assert prev_class.start_with?(class_prefix)
48 test "select two columns with order" do
49 get "/arvados/v1/links", {:format => :json, :select => ['link_class', 'uuid'], :order => ['link_class asc', "uuid desc"]}, auth(:active)
50 assert_response :success
52 assert json_response['items'].length > 0
55 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
57 json_response['items'].each do |i|
58 if prev_link_class != i['link_class']
59 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
62 assert_link_classes_ascend(i['link_class'], prev_link_class)
63 assert i['uuid'] < prev_uuid
65 prev_link_class = i['link_class']
70 test "select two columns with old-style order syntax" do
71 get "/arvados/v1/links", {:format => :json, :select => ['link_class', 'uuid'], :order => 'link_class asc, uuid desc'}, auth(:active)
72 assert_response :success
74 assert json_response['items'].length > 0
77 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
79 json_response['items'].each do |i|
80 if prev_link_class != i['link_class']
81 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
84 assert_link_classes_ascend(i['link_class'], prev_link_class)
85 assert i['uuid'] < prev_uuid
87 prev_link_class = i['link_class']