Merge branch '2640-folder-api'
authorTom Clegg <tom@curoverse.com>
Fri, 25 Apr 2014 14:07:36 +0000 (10:07 -0400)
committerTom Clegg <tom@curoverse.com>
Fri, 25 Apr 2014 14:07:36 +0000 (10:07 -0400)
refs #2640

Conflicts:
services/api/app/controllers/application_controller.rb
services/api/config/routes.rb

1  2 
apps/workbench/test/unit/user_test.rb
services/api/app/controllers/application_controller.rb
services/api/config/routes.rb
services/api/test/functional/arvados/v1/users_controller_test.rb
services/api/test/integration/collections_api_test.rb
services/api/test/integration/errors_test.rb

index 82f61e0109663ddb34c9850653978c5280db0d59,2a4721720249811557a32a9b40e1afb977771e13..d82765135c4af855c11009bcdec91d88cc262ebb
@@@ -1,7 -1,16 +1,16 @@@
  require 'test_helper'
  
  class UserTest < ActiveSupport::TestCase
-   # test "the truth" do
-   #   assert true
-   # end
+   test "get owned_items" do
+     use_token :active
+     oi = User.find(api_fixture('users')['active']['uuid']).owned_items
+     assert_operator(0, :<, oi.count,
+                     "Expected to find some items belonging to :active user")
 -    assert_operator(0, :<, oi.items_available
++    assert_operator(0, :<, oi.items_available,
+                     "Expected owned_items response to have items_available > 0")
+     oi_uuids = oi.collect { |i| i['uuid'] }
+     expect = api_fixture('specimens')['owned_by_active_user']['uuid']
+     assert_includes(oi_uuids, expect,
+                     "Expected active user's owned_items to include #{expect}")
+   end
  end
index fcc7618fb6b78409a2c014cbebe3e5e92b5b16b0,74f6bb28ef1ffc9b3ca4c358876f4efe50259391..6339125a00b69f2991353c8e6c91a7bb2f9be0c8
@@@ -164,15 -268,19 +273,19 @@@ class ApplicationController < ActionCon
                operand = Time.parse operand
              end
              param_out << operand
+           elsif operand.nil? and operator == '='
+             cond_out << "#{ar_table_name}.#{attr} is null"
            else
-             raise ArgumentError.new("Invalid operand type '#{operand.class}' for '#{operator}' operator in filter")
 -            raise ArgumentError.new("Invalid operand type '#{attr.class}' "\
++            raise ArgumentError.new("Invalid operand type '#{operand.class}' "\
+                                     "for '#{operator}' operator in filters")
            end
          when 'in'
            if operand.is_a? Array
-             cond_out << "#{table_name}.#{attr} IN (?)"
+             cond_out << "#{ar_table_name}.#{attr} IN (?)"
              param_out << operand
            else
-             raise ArgumentError.new("Invalid argument '#{operand}' for 'in' operator in filter")
 -            raise ArgumentError.new("Invalid operand type '#{attr.class}' "\
++            raise ArgumentError.new("Invalid operand type '#{operand.class}' "\
+                                     "for '#{operator}' operator in filters")
            end
          when 'is_a'
            operand = [operand] unless operand.is_a? Array
index 5a11143a0691bfcdeba16698a45a8cb0b3aaf16b,cfd3b615374de7f429360951676844fc33fa21c3..b229511de6a61ce5db09b90ddeaec8e79c1f7b54
@@@ -5,54 -81,50 +5,57 @@@ Server::Application.routes.draw d
  
    namespace :arvados do
      namespace :v1 do
 -      match '/nodes/:uuid/ping' => 'nodes#ping', :as => :ping_node
 -      match '/keep_disks/ping' => 'keep_disks#ping', :as => :ping_keep_disk
 -      match '/links/from/:tail_uuid' => 'links#index', :as => :arvados_v1_links_from
 -      match '/users/current' => 'users#current'
 -      match '/users/system' => 'users#system'
 -      match '/jobs/queue' => 'jobs#queue'
 -      match '/jobs/:uuid/log_tail_follow' => 'jobs#log_tail_follow'
 -      post '/jobs/:uuid/cancel' => 'jobs#cancel'
 -      match '/users/:uuid/event_stream' => 'users#event_stream'
 -      post '/users/:uuid/activate' => 'users#activate'
 -      post '/users/setup' => 'users#setup'
 -      post '/users/:uuid/unsetup' => 'users#unsetup'
 -      match '/virtual_machines/get_all_logins' => 'virtual_machines#get_all_logins'
 -      match '/virtual_machines/:uuid/logins' => 'virtual_machines#logins'
 -      post '/api_client_authorizations/create_system_auth' => 'api_client_authorizations#create_system_auth'
 -      match '/repositories/get_all_permissions' => 'repositories#get_all_permissions'
 -      get '/user_agreements/signatures' => 'user_agreements#signatures'
 -      post '/user_agreements/sign' => 'user_agreements#sign'
 -      get '/collections/:uuid/provenance' => 'collections#provenance'
 -      get '/collections/:uuid/used_by' => 'collections#used_by'
 -      resources :collections
 -      resources :links
 -      resources :nodes
 -      resources :pipeline_templates
 -      resources :pipeline_instances
 -      resources :specimens
 +      resources :api_client_authorizations do
 +        post 'create_system_auth', on: :collection
 +      end
 +      resources :api_clients
 +      resources :authorized_keys
 +      resources :collections do
 +        get 'provenance', on: :member
 +        get 'used_by', on: :member
 +      end
-       resources :groups
+       resources :groups do
+         get 'owned_items', on: :member
+       end
 +      resources :humans
 +      resources :job_tasks
 +      resources :jobs do
 +        get 'queue', on: :collection
 +        get 'log_tail_follow', on: :member
 +        post 'cancel', on: :member
 +      end
 +      resources :keep_disks do
 +        post 'ping', on: :collection
 +      end
 +      resources :links
        resources :logs
 +      resources :nodes do
 +        post 'ping', on: :member
 +      end
 +      resources :pipeline_instances
 +      resources :pipeline_templates
 +      resources :repositories do
 +        get 'get_all_permissions', on: :collection
 +      end
 +      resources :specimens
 +      resources :traits
 +      resources :user_agreements do
 +        get 'signatures', on: :collection
 +        post 'sign', on: :collection
 +      end
        resources :users do
 +        get 'current', on: :collection
 +        get 'system', on: :collection
 +        get 'event_stream', on: :member
 +        post 'activate', on: :member
 +        post 'setup', on: :collection
 +        post 'unsetup', on: :member
+         get 'owned_items', on: :member
        end
 -      resources :api_clients
 -      resources :api_client_authorizations
 -      resources :jobs
 -      resources :job_tasks
 -      resources :keep_disks
 -      resources :authorized_keys
 -      resources :virtual_machines
 -      resources :repositories
 -      resources :traits
 -      resources :humans
 -      resources :user_agreements
 +      resources :virtual_machines do
 +        get 'logins', on: :member
 +        get 'get_all_logins', on: :collection
 +      end
      end
    end
  
index e13d336505993a8e03ce2a5bd68a28fced93691c,8856fd509b5756a526be8d71408b7943a2f70996..b0fddb8f29022d13a56263773e58cf0157fd390f
@@@ -12,45 -12,9 +12,45 @@@ class CollectionsApiTest < ActionDispat
    test "get index with filters= (empty string)" do
      get "/arvados/v1/collections", {:format => :json, :filters => ''}, auth(:active)
      assert_response :success
-     assert_equal "arvados#collectionList", jresponse['kind']
+     assert_equal "arvados#collectionList", json_response['kind']
    end
  
-     assert_match /nvalid element.*not an array/, jresponse['errors'].join(' ')
 +  test "get index with invalid filters (array of strings) responds 422" do
 +    get "/arvados/v1/collections", {
 +      :format => :json,
 +      :filters => ['uuid', '=', 'ad02e37b6a7f45bbe2ead3c29a109b8a+54'].to_json
 +    }, auth(:active)
 +    assert_response 422
-     assert_match /nvalid attribute/, jresponse['errors'].join(' ')
++    assert_match /nvalid element.*not an array/, json_response['errors'].join(' ')
 +  end
 +
 +  test "get index with invalid filters (unsearchable column) responds 422" do
 +    get "/arvados/v1/collections", {
 +      :format => :json,
 +      :filters => [['this_column_does_not_exist', '=', 'bogus']].to_json
 +    }, auth(:active)
 +    assert_response 422
-     assert_match /nvalid operator/, jresponse['errors'].join(' ')
++    assert_match /nvalid attribute/, json_response['errors'].join(' ')
 +  end
 +
 +  test "get index with invalid filters (invalid operator) responds 422" do
 +    get "/arvados/v1/collections", {
 +      :format => :json,
 +      :filters => [['uuid', ':-(', 'displeased']].to_json
 +    }, auth(:active)
 +    assert_response 422
-     assert_match /nvalid operand type/, jresponse['errors'].join(' ')
++    assert_match /nvalid operator/, json_response['errors'].join(' ')
 +  end
 +
 +  test "get index with invalid filters (invalid operand type) responds 422" do
 +    get "/arvados/v1/collections", {
 +      :format => :json,
 +      :filters => [['uuid', '=', {foo: 'bar'}]].to_json
 +    }, auth(:active)
 +    assert_response 422
++    assert_match /nvalid operand type/, json_response['errors'].join(' ')
 +  end
 +
    test "get index with where= (empty string)" do
      get "/arvados/v1/collections", {:format => :json, :where => ''}, auth(:active)
      assert_response :success
index 3a58e4840bb20f54beac9d5d39eb319e9188d8ee,0000000000000000000000000000000000000000..b2ef13e1d3bdc2c69932729a0fa0b382ef357547
mode 100644,000000..100644
--- /dev/null
@@@ -1,27 -1,0 +1,27 @@@
-       assert_not_nil jresponse['errors']
 +require 'test_helper'
 +
 +class ErrorsTest < ActionDispatch::IntegrationTest
 +  fixtures :api_client_authorizations
 +
 +  %w(/arvados/v1/shoes /arvados/shoes /shoes /nodes /users).each do |path|
 +    test "non-existent route #{path}" do
 +      get path, {:format => :json}, auth(:active)
 +      assert_nil assigns(:objects)
 +      assert_nil assigns(:object)
++      assert_not_nil json_response['errors']
 +      assert_response 404
 +    end
 +  end
 +
 +  n=0
 +  Rails.application.routes.routes.each do |route|
 +    test "route #{n += 1} '#{route.path.spec.to_s}' is not an accident" do
 +      # Generally, new routes should appear under /arvados/v1/. If
 +      # they appear elsewhere, that might have been caused by default
 +      # rails generator behavior that we don't want.
 +      assert_match(/^\/(|\*a|arvados\/v1\/.*|auth\/.*|login|logout|discovery\/.*|static\/.*|themes\/.*)(\(\.:format\))?$/,
 +                   route.path.spec.to_s,
 +                   "Unexpected new route: #{route.path.spec}")
 +    end
 +  end
 +end