4253: Add tests for renaming repos.
authorBrett Smith <brett@curoverse.com>
Tue, 31 Mar 2015 13:24:42 +0000 (09:24 -0400)
committerBrett Smith <brett@curoverse.com>
Tue, 31 Mar 2015 15:14:11 +0000 (11:14 -0400)
services/api/test/test_helper.rb
services/api/test/unit/repository_test.rb

index f155fc070848ccd926c87ca9c057e127d7bb856c..bf5afea1e2dd6b44fa68332df4c1f1512855a472 100644 (file)
@@ -62,6 +62,15 @@ class ActiveSupport::TestCase
     end
   end
 
+  def add_permission_link from_who, to_what, perm_type
+    act_as_system_user do
+      Link.create!(tail_uuid: from_who.uuid,
+                   head_uuid: to_what.uuid,
+                   link_class: 'permission',
+                   name: perm_type)
+    end
+  end
+
   def restore_configuration
     # Restore configuration settings changed during tests
     $application_config.each do |k,v|
index ef780f893cad7b8ede7ca62fbd51c8f7108d86bf..a6b0be5f0a4eeff024136422fff08d3d6f182533 100644 (file)
@@ -263,4 +263,26 @@ class RepositoryTest < ActiveSupport::TestCase
       assert_equal modtime_was, r.modified_at
     end
   end
+
+  ### Renaming
+
+  test "non-admin can rename own repo" do
+    act_as_user users(:active) do
+      assert repositories(:foo).update_attributes(name: 'active/foo12345')
+    end
+  end
+
+  test "top level repo can be touched by non-admin with can_manage" do
+    add_permission_link users(:active), repositories(:arvados), 'can_manage'
+    act_as_user users(:active) do
+      assert changed_repo(:arvados, modified_at: Time.now).save
+    end
+  end
+
+  test "top level repo cannot be renamed by non-admin with can_manage" do
+    add_permission_link users(:active), repositories(:arvados), 'can_manage'
+    act_as_user users(:active) do
+      assert_not_allowed { changed_repo(:arvados, name: 'xarvados').save }
+    end
+  end
 end