16007: Refactoring and update comments.
[arvados.git] / services / api / test / integration / collections_api_test.rb
index 49c3cb425f53b28462d59f2c4526b7044709702b..86195fba750877af031abc92d451570a567ac096 100644 (file)
@@ -275,6 +275,41 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest
     end
   end
 
+  [
+    ["false", false],
+    ["0", false],
+    ["true", true],
+    ["1", true]
+  ].each do |param, truthiness|
+    test "include_trash=#{param.inspect} param JSON-encoded should be interpreted as include_trash=#{truthiness}" do
+      expired_col = collections(:expired_collection)
+      assert expired_col.is_trashed
+      # Try #index first
+      post "/arvados/v1/collections",
+          params: {
+            :_method => 'GET',
+            :include_trash => param,
+            :filters => [['uuid', '=', expired_col.uuid]].to_json
+          },
+          headers: auth(:active)
+      assert_response :success
+      assert_not_nil json_response['items']
+      assert_equal truthiness, json_response['items'].collect {|c| c['uuid']}.include?(expired_col.uuid)
+      # Try #show next
+      post "/arvados/v1/collections/#{expired_col.uuid}",
+        params: {
+          :_method => 'GET',
+          :include_trash => param,
+        },
+        headers: auth(:active)
+      if truthiness
+        assert_response :success
+      else
+        assert_response 404
+      end
+    end
+  end
+
   [
     ["false", false],
     ["0", false],
@@ -311,11 +346,12 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest
       expired_col = collections(:expired_collection)
       assert expired_col.is_trashed
       params = [
+        ['_method', 'GET'],
         ['include_trash', param],
         ['filters', [['uuid','=',expired_col.uuid]].to_json],
       ]
       # Try #index first
-      get "/arvados/v1/collections",
+      post "/arvados/v1/collections",
         params: URI.encode_www_form(params),
         headers: {
           "Content-type" => "application/x-www-form-urlencoded"
@@ -324,8 +360,8 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest
       assert_not_nil json_response['items']
       assert_equal truthiness, json_response['items'].collect {|c| c['uuid']}.include?(expired_col.uuid)
       # Try #show next
-      get "/arvados/v1/collections",
-        params: URI.encode_www_form([['include_trash', param]]),
+      post "/arvados/v1/collections/#{expired_col.uuid}",
+        params: URI.encode_www_form([['_method', 'GET'],['include_trash', param]]),
         headers: {
           "Content-type" => "application/x-www-form-urlencoded"
         }.update(auth(:active))