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 test "select two columns with order" do
39 get "/arvados/v1/links", {:format => :json, :select => ['link_class', 'uuid'], :order => ['link_class asc', "uuid desc"]}, auth(:active)
40 assert_response :success
42 assert json_response['items'].length > 0
45 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
47 json_response['items'].each do |i|
48 if prev_link_class != i['link_class']
49 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
52 assert i['link_class'] >= prev_link_class
53 assert i['uuid'] < prev_uuid
55 prev_link_class = i['link_class']
60 test "select two columns with old-style order syntax" 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 i['link_class'] >= prev_link_class
75 assert i['uuid'] < prev_uuid
77 prev_link_class = i['link_class']