Merge branch 'master' into 10112-workflow-show
[arvados.git] / apps / workbench / test / controllers / actions_controller_test.rb
index d8c17c9d82a3e30174fb00ac12621a33c6f38958..9f561aa577037210f72ea06352254f71ae732d18 100644 (file)
@@ -27,19 +27,18 @@ class ActionsControllerTest < ActionController::TestCase
 
     assert_response 302   # collection created and redirected to new collection page
 
 
     assert_response 302   # collection created and redirected to new collection page
 
-    assert response.headers['Location'].include? '/collections/'
+    assert_includes(response.headers['Location'], '/collections/')
     new_collection_uuid = response.headers['Location'].split('/')[-1]
 
     use_token :active
     collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
     manifest_text = collection['manifest_text']
     new_collection_uuid = response.headers['Location'].split('/')[-1]
 
     use_token :active
     collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
     manifest_text = collection['manifest_text']
-    assert manifest_text.include?('foo'), 'Not found foo in new collection manifest text'
-    assert manifest_text.include?('bar'), 'Not found bar in new collection manifest text'
-    assert manifest_text.include?('baz'), 'Not found baz in new collection manifest text'
-    assert manifest_text.include?('0:0:file1 0:0:file2 0:0:file3'),
-                'Not found 0:0:file1 0:0:file2 0:0:file3 in new collection manifest text'
-    assert manifest_text.include?('dir1/subdir'), 'Not found dir1/subdir in new collection manifest text'
-    assert manifest_text.include?('dir2'), 'Not found dir2 in new collection manifest text'
+    assert_includes(manifest_text, "foo")
+    assert_includes(manifest_text, "bar")
+    assert_includes(manifest_text, "baz")
+    assert_includes(manifest_text, "0:0:file1 0:0:file2 0:0:file3")
+    assert_includes(manifest_text, "dir1/subdir")
+    assert_includes(manifest_text, "dir2")
   end
 
   test "combine files  with repeated names into new collection" do
   end
 
   test "combine files  with repeated names into new collection" do
@@ -55,21 +54,19 @@ class ActionsControllerTest < ActionController::TestCase
 
     assert_response 302   # collection created and redirected to new collection page
 
 
     assert_response 302   # collection created and redirected to new collection page
 
-    assert response.headers['Location'].include? '/collections/'
+    assert_includes(response.headers['Location'], '/collections/')
     new_collection_uuid = response.headers['Location'].split('/')[-1]
 
     use_token :active
     collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
     manifest_text = collection['manifest_text']
     new_collection_uuid = response.headers['Location'].split('/')[-1]
 
     use_token :active
     collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
     manifest_text = collection['manifest_text']
-    assert manifest_text.include?('foo'), 'Not found foo in new collection manifest text'
-    assert manifest_text.include?('foo(1)'), 'Not found foo(1) in new collection manifest text'
-    assert manifest_text.include?('foo(2)'), 'Not found foo(2) in new collection manifest text'
-    assert manifest_text.include?('bar'), 'Not found bar in new collection manifest text'
-    assert manifest_text.include?('baz'), 'Not found baz in new collection manifest text'
-    assert manifest_text.include?('0:0:file1 0:0:file2 0:0:file3'),
-                'Not found 0:0:file1 0:0:file2 0:0:file3 in new collection manifest text'
-    assert manifest_text.include?('dir1/subdir'), 'Not found dir1/subdir in new collection manifest text'
-    assert manifest_text.include?('dir2'), 'Not found dir2 in new collection manifest text'
+    assert_includes(manifest_text, "foo(1)")
+    assert_includes(manifest_text, "foo(2)")
+    assert_includes(manifest_text, "bar")
+    assert_includes(manifest_text, "baz")
+    assert_includes(manifest_text, "0:0:file1 0:0:file2 0:0:file3")
+    assert_includes(manifest_text, "dir1/subdir")
+    assert_includes(manifest_text, "dir2")
   end
 
   test "combine collections with repeated filenames in almost similar directories and expect files with proper suffixes" do
   end
 
   test "combine collections with repeated filenames in almost similar directories and expect files with proper suffixes" do
@@ -90,26 +87,26 @@ class ActionsControllerTest < ActionController::TestCase
     collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
     manifest_text = collection['manifest_text']
 
     collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
     manifest_text = collection['manifest_text']
 
-    assert manifest_text.include?('foo'), 'Not found foo in new collection manifest text'
-    assert manifest_text.include?('foo(1)'), 'Not found foo(1) in new collection manifest text'
+    assert_includes(manifest_text, 'foo')
+    assert_includes(manifest_text, 'foo(1)')
 
     streams = manifest_text.split "\n"
     streams.each do |stream|
       if stream.start_with? './dir1'
         # dir1 stream
 
     streams = manifest_text.split "\n"
     streams.each do |stream|
       if stream.start_with? './dir1'
         # dir1 stream
-        assert stream.include?(':alice(1)'), 'Not found: alice(1) in dir1'
-        assert stream.include?(':alice.txt'), 'Not found: alice.txt in dir1'
-        assert stream.include?(':alice(1).txt'), 'Not found: alice(1).txt in dir1'
-        assert stream.include?(':bob.txt'), 'Not found: bob.txt in dir1'
-        assert stream.include?(':carol.txt'), 'Not found: carol.txt in dir1'
+        assert_includes(stream, ':alice(1)')
+        assert_includes(stream, ':alice.txt')
+        assert_includes(stream, ':alice(1).txt')
+        assert_includes(stream, ':bob.txt')
+        assert_includes(stream, ':carol.txt')
       elsif stream.start_with? './dir2'
         # dir2 stream
       elsif stream.start_with? './dir2'
         # dir2 stream
-        assert stream.include?(':alice.txt'), 'Not found: alice.txt in dir2'
-        assert stream.include?(':alice(1).txt'), 'Not found: alice(1).txt in dir2'
+        assert_includes(stream, ':alice.txt')
+        assert_includes(stream, ':alice(1).txt')
       elsif stream.start_with? '. '
         # . stream
       elsif stream.start_with? '. '
         # . stream
-        assert stream.include?(':foo'), 'Not found: foo in .'
-        assert stream.include?(':foo(1)'), 'Not found: foo(1) in .'
+        assert_includes(stream, ':foo')
+        assert_includes(stream, ':foo(1)')
       end
     end
   end
       end
     end
   end
@@ -123,7 +120,7 @@ class ActionsControllerTest < ActionController::TestCase
 
     assert_response 302   # collection created and redirected to new collection page
 
 
     assert_response 302   # collection created and redirected to new collection page
 
-    assert response.headers['Location'].include? '/collections/'
+    assert_includes(response.headers['Location'], '/collections/')
     new_collection_uuid = response.headers['Location'].split('/')[-1]
 
     use_token :active
     new_collection_uuid = response.headers['Location'].split('/')[-1]
 
     use_token :active
@@ -134,12 +131,12 @@ class ActionsControllerTest < ActionController::TestCase
     assert_equal 2, streams.length
     streams.each do |stream|
       if stream.start_with? './dir1'
     assert_equal 2, streams.length
     streams.each do |stream|
       if stream.start_with? './dir1'
-        assert stream.include?('foo'), 'Not found: foo in dir1'
+        assert_includes(stream, 'foo')
       elsif stream.start_with? '. '
       elsif stream.start_with? '. '
-        assert stream.include?('foo'), 'Not found: foo in .'
+        assert_includes(stream, 'foo')
       end
     end
       end
     end
-    assert !manifest_text.include?('foo(1)'), 'Found foo(1) in new collection manifest text'
+    refute_includes(manifest_text, 'foo(1)')
   end
 
   test "combine foo files from two different collection streams and expect proper filename suffixes" do
   end
 
   test "combine foo files from two different collection streams and expect proper filename suffixes" do
@@ -151,7 +148,7 @@ class ActionsControllerTest < ActionController::TestCase
 
     assert_response 302   # collection created and redirected to new collection page
 
 
     assert_response 302   # collection created and redirected to new collection page
 
-    assert response.headers['Location'].include? '/collections/'
+    assert_includes(response.headers['Location'], '/collections/')
     new_collection_uuid = response.headers['Location'].split('/')[-1]
 
     use_token :active
     new_collection_uuid = response.headers['Location'].split('/')[-1]
 
     use_token :active
@@ -159,8 +156,47 @@ class ActionsControllerTest < ActionController::TestCase
     manifest_text = collection['manifest_text']
 
     streams = manifest_text.split "\n"
     manifest_text = collection['manifest_text']
 
     streams = manifest_text.split "\n"
-    assert_equal 1, streams.length
-    assert manifest_text.include?('foo'), 'Found foo in new collection manifest text'
-    assert manifest_text.include?('foo(1)'), 'Found foo(1) in new collection manifest text'
+    assert_equal 1, streams.length, "Incorrect number of streams in #{manifest_text}"
+    assert_includes(manifest_text, 'foo')
+    assert_includes(manifest_text, 'foo(1)')
+  end
+
+  [
+    ['collections', 'user_agreement_in_anonymously_accessible_project'],
+    ['groups', 'anonymously_accessible_project'],
+    ['jobs', 'running_job_in_publicly_accessible_project'],
+    ['pipeline_instances', 'pipeline_in_publicly_accessible_project'],
+    ['pipeline_templates', 'pipeline_template_in_publicly_accessible_project'],
+  ].each do |dm, fixture|
+    test "access show method for public #{dm} and expect to see page" do
+      Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
+      get(:show, {uuid: api_fixture(dm)[fixture]['uuid']})
+      assert_response :redirect
+      if dm == 'groups'
+        assert_includes @response.redirect_url, "projects/#{fixture['uuid']}"
+      else
+        assert_includes @response.redirect_url, "#{dm}/#{fixture['uuid']}"
+      end
+    end
+  end
+
+  [
+    ['collections', 'foo_collection_in_aproject', 404],
+    ['groups', 'subproject_in_asubproject_with_same_name_as_one_in_active_user_home', 404],
+    ['jobs', 'job_with_latest_version', 404],
+    ['pipeline_instances', 'pipeline_owned_by_active_in_home', 404],
+    ['pipeline_templates', 'template_in_asubproject_with_same_name_as_one_in_active_user_home', 404],
+    ['traits', 'owned_by_aproject_with_no_name', :redirect],
+  ].each do |dm, fixture, expected|
+    test "access show method for non-public #{dm} and expect #{expected}" do
+      Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
+      get(:show, {uuid: api_fixture(dm)[fixture]['uuid']})
+      assert_response expected
+      if expected == 404
+        assert_includes @response.inspect, 'Log in'
+      else
+        assert_match /\/users\/welcome/, @response.redirect_url
+      end
+    end
   end
 end
   end
 end