Fighting with tests
authorPeter Amstutz <peter.amstutz@curoverse.com>
Mon, 24 Mar 2014 21:10:09 +0000 (17:10 -0400)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Mon, 24 Mar 2014 21:10:09 +0000 (17:10 -0400)
services/api/app/models/arvados_model.rb
services/api/test/functional/arvados/v1/links_controller_test.rb
services/api/test/integration/valid_links_test.rb [new file with mode: 0644]

index 30e907c00d470c3b04120db3b6162e14dee2445d..ed19636fcb20953a84c2f9413402eca24c885137 100644 (file)
@@ -187,10 +187,11 @@ class ArvadosModel < ActiveRecord::Base
     specials = [system_user_uuid, 'd41d8cd98f00b204e9800998ecf8427e+0']
 
     foreign_key_attributes.each do |attr|
+      next if attr == "modified_by_client_uuid"
       begin
         attr_value = send attr
         r = ArvadosModel::resource_class_for_uuid attr_value if attr_value
-        if r and r.where(uuid: attr_value).count == 0 and not specials.include? attr_value
+        if r and r.readable_by(current_user).where(uuid: attr_value).count == 0 and not specials.include? attr_value
           errors.add(attr, "'#{attr_value}' not found")
         end
       rescue Exception => e
index 352ce5505015a7dba3468b819f8ff5f8be97af29..19e821edaa04a97b813e687154c6c7c87e46e397 100644 (file)
@@ -29,7 +29,7 @@ class Arvados::V1::LinksControllerTest < ActionController::TestCase
       tail_uuid: users(:active).uuid,
       head_uuid: 'zzzzz-tpzed-xyzxyzxerrrorxx'
     }
-    authorize_with :active
+    authorize_with :admin
     post :create, link: link
     assert_response 422
   end
@@ -41,12 +41,12 @@ class Arvados::V1::LinksControllerTest < ActionController::TestCase
       head_uuid: users(:active).uuid,
       tail_uuid: 'zzzzz-tpzed-xyzxyzxerrrorxx'
     }
-    authorize_with :active
+    authorize_with :admin
     post :create, link: link
     assert_response 422
   end
 
-  test "tail must exist on update" do
+  test "tail must be visible by user" do
     link = {
       link_class: 'test',
       name: 'stuff',
@@ -55,20 +55,6 @@ class Arvados::V1::LinksControllerTest < ActionController::TestCase
     }
     authorize_with :active
     post :create, link: link
-    u = (ActiveSupport::JSON.decode @response.body)['uuid']
-    assert_response :success
-
-    link = {
-      tail_uuid: virtual_machines(:testvm2).uuid
-    }
-    put :update, {id: u, link: link}
-    assert_equal virtual_machines(:testvm2).uuid, (ActiveSupport::JSON.decode @response.body)['tail_uuid']
-    assert_response :success
-
-    link = {
-      tail_uuid: 'zzzzz-tpzed-xyzxyzxerrrorxx'
-    }
-    put :update, {id: u, link: link}
     assert_response 422
   end
 
diff --git a/services/api/test/integration/valid_links_test.rb b/services/api/test/integration/valid_links_test.rb
new file mode 100644 (file)
index 0000000..65431f3
--- /dev/null
@@ -0,0 +1,42 @@
+require 'test_helper'
+
+class ValidLinksTest < ActionDispatch::IntegrationTest
+  fixtures :all
+
+  test "tail must exist on update" do
+    admin_auth = {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin).api_token}"}
+
+    post "/arvados/v1/links", {
+      :format => :json,
+      :link => {
+        link_class: 'test',
+        name: 'stuff',
+        head_uuid: users(:active).uuid,
+        tail_uuid: virtual_machines(:testvm).uuid
+      }
+    }, admin_auth
+    assert_response :success
+    u = jresponse['uuid']
+
+    put "/arvados/v1/links/#{u}", {
+      :format => :json,
+      :link => {
+        tail_uuid: virtual_machines(:testvm2).uuid
+      }
+    }, admin_auth
+    assert_response :success
+    #puts @response.body
+    #puts jresponse['tail_uuid']
+    #puts virtual_machines(:testvm2)
+    assert_equal virtual_machines(:testvm2).uuid, (ActiveSupport::JSON.decode @response.body)['tail_uuid']
+
+    put "/arvados/v1/links/#{u}", {
+      :format => :json,
+      :link => {
+        tail_uuid: 'zzzzz-tpzed-xyzxyzxerrrorxx'
+      }
+    }, admin_auth
+    assert_response 422
+  end
+
+end