Merge branch 'master' into 7454-azure-custom-data
[arvados.git] / apps / workbench / test / controllers / application_controller_test.rb
index 6daa63f9b075bf0d5abb5700c3d533b8c745eede..ef2a989427948a693c1257e7466f09e523c43c7b 100644 (file)
@@ -334,6 +334,26 @@ class ApplicationControllerTest < ActionController::TestCase
     assert_response 404
   end
 
+  [".navbar .login-menu a",
+   ".navbar .login-menu .dropdown-menu a"
+  ].each do |css_selector|
+    test "login link at #{css_selector.inspect} includes return_to param" do
+      # Without an anonymous token, we're immediately redirected to login.
+      Rails.configuration.anonymous_user_token =
+        api_fixture("api_client_authorizations", "anonymous", "api_token")
+      @controller = ProjectsController.new
+      test_uuid = "zzzzz-j7d0g-zzzzzzzzzzzzzzz"
+      get(:show, {id: test_uuid})
+      login_link = css_select(css_selector).first
+      assert_not_nil(login_link, "failed to select login link")
+      login_href = URI.unescape(login_link.attributes["href"])
+      # The parameter needs to include the full URL to work.
+      assert_includes(login_href, "://")
+      assert_match(/[\?&]return_to=[^&]*\/projects\/#{test_uuid}(&|$)/,
+                   login_href)
+    end
+  end
+
   test "Workbench returns 4xx when API server is unreachable" do
     # We're really testing ApplicationController's render_exception.
     # Our primary concern is that it doesn't raise an error and
@@ -422,7 +442,7 @@ class ApplicationControllerTest < ActionController::TestCase
   [
     [VirtualMachinesController.new, 'hostname', false],
     [UsersController.new, 'first_name', true],
-  ].each do |controller, expect_str, expect_home_link=false|
+  ].each do |controller, expect_str, expect_home_link|
     test "access #{controller.controller_name} index as admin and verify Home link is#{' not' if !expect_home_link} shown" do
       @controller = controller
 
@@ -444,7 +464,7 @@ class ApplicationControllerTest < ActionController::TestCase
   [
     [VirtualMachinesController.new, 'hostname', true],
     [UsersController.new, 'first_name', false],
-  ].each do |controller, expect_str, expect_delete_link=false|
+  ].each do |controller, expect_str, expect_delete_link|
     test "access #{controller.controller_name} index as admin and verify Delete option is#{' not' if !expect_delete_link} shown" do
       @controller = controller