Merge branch '2857-collection-tests'
authorTim Pierce <twp@curoverse.com>
Fri, 6 Jun 2014 21:37:18 +0000 (17:37 -0400)
committerTim Pierce <twp@curoverse.com>
Fri, 6 Jun 2014 21:37:18 +0000 (17:37 -0400)
Closes #2857.

services/api/test/functional/arvados/v1/collections_controller_test.rb

index 8b2725a4bd266cf420fc71fc2a2f2bb356f9b860..6830c6b86f70c03379515b70b1967cf308a04c9e 100644 (file)
@@ -56,9 +56,14 @@ EOS
       Digest::MD5.hexdigest(test_collection[:manifest_text]) +
       '+' +
       test_collection[:manifest_text].length.to_s
+
+    # post :create will modify test_collection in place, so we save a copy first.
+    # Hash.deep_dup is not sufficient as it preserves references of strings (??!?)
+    post_collection = Marshal.load(Marshal.dump(test_collection))
     post :create, {
-      collection: test_collection
+      collection: post_collection
     }
+
     assert_response :success
     assert_nil assigns(:objects)
 
@@ -69,7 +74,11 @@ EOS
     assert_not_nil assigns(:object)
     resp = JSON.parse(@response.body)
     assert_equal test_collection[:uuid], resp['uuid']
-    assert_equal test_collection[:manifest_text], resp['manifest_text']
+
+    # The manifest in the response will have had permission hints added.
+    # Remove any permission hints in the response before comparing it to the source.
+    stripped_manifest = resp['manifest_text'].gsub(/\+A[A-Za-z0-9@_-]+/, '')
+    assert_equal test_collection[:manifest_text], stripped_manifest
     assert_equal 9, resp['data_size']
     assert_equal [['.', 'foo.txt', 0],
                   ['.', 'bar.txt', 6],
@@ -393,18 +402,24 @@ EOS
       '+' +
       manifest_text.length.to_s
 
+    test_collection = {
+      manifest_text: manifest_text,
+      uuid: manifest_uuid,
+    }
+    post_collection = Marshal.load(Marshal.dump(test_collection))
     post :create, {
-      collection: {
-        manifest_text: manifest_text,
-        uuid: manifest_uuid,
-      }
+      collection: post_collection
     }
     assert_response :success
     assert_not_nil assigns(:object)
     resp = JSON.parse(@response.body)
     assert_equal manifest_uuid, resp['uuid']
     assert_equal 48, resp['data_size']
-    assert_equal resp['manifest_text'], manifest_text
+
+    # The manifest in the response will have had permission hints added.
+    # Remove any permission hints in the response before comparing it to the source.
+    stripped_manifest = resp['manifest_text'].gsub(/\+A[A-Za-z0-9@_-]+/, '')
+    assert_equal manifest_text, stripped_manifest
   end
 
   test "multiple signed locators per line" do