6466 - Update body html for enable public page and added tests to project controller...
authorManoj <jonam33@gmail.com>
Mon, 6 Jul 2015 18:00:24 +0000 (14:00 -0400)
committerManoj <jonam33@gmail.com>
Mon, 6 Jul 2015 18:00:24 +0000 (14:00 -0400)
apps/workbench/app/views/layouts/body.html.erb
apps/workbench/test/controllers/projects_controller_test.rb

index 54e662605a8314e245ae539fbcd5d6b494676b87..0f90c416f0c929c660dd97616dd54db32a2f4750 100644 (file)
               </li>
             <% end %>
           <% else %>
-            <% if Rails.configuration.anonymous_user_token %>
+            <% if Rails.configuration.anonymous_user_token and Rails.configuration.enable_public_projects_page %>
               <li><%= link_to 'Browse public projects', "/projects/public" %></li>
             <% end %>
             <li class="dropdown hover-dropdown login-menu">
               <span class="caret"></span>
             </a>
             <ul class="dropdown-menu" style="min-width: 20em" role="menu">
-              <% if Rails.configuration.anonymous_user_token %>
+              <% if Rails.configuration.anonymous_user_token and Rails.configuration.enable_public_projects_page %>
                 <li><%= link_to 'Browse public projects', "/projects/public", class: 'btn btn-xs btn-default pull-right' %></li>
               <% end %>
               <li>
index 41ed7277f8e46e7e390e5d6ee2702be50e3e1177..62a93a1308b3755ac64e0f6c49b348b5354957f2 100644 (file)
@@ -267,6 +267,7 @@ class ProjectsControllerTest < ActionController::TestCase
       project_names = assigns(:objects).collect(&:name)
       assert_includes project_names, 'Unrestricted public data'
       assert_not_includes project_names, 'A Project'
+      refute_empty css_select('[href="/projects/public"]')
     end
   end
 
@@ -275,7 +276,7 @@ class ProjectsControllerTest < ActionController::TestCase
     assert_response 404
   end
 
-  test "visit public projects page when anon config is enabled but public projects page is disabled and expect 404" do
+  test "visit public projects page when anon config is enabled but public projects page is disabled as active user and expect 404" do
     Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
     Rails.configuration.enable_public_projects_page = false
     get :public, {}, session_for(:active)
@@ -286,5 +287,23 @@ class ProjectsControllerTest < ActionController::TestCase
     get :public
     assert_response :redirect
     assert_match /\/users\/welcome/, @response.redirect_url
+    assert_empty css_select('[href="/projects/public"]')
+  end
+
+  test "visit public projects page when anon config is enabled and public projects page is disabled and expect login page" do
+    Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
+    Rails.configuration.enable_public_projects_page = false
+    get :index
+    assert_response :redirect
+    assert_match /\/users\/welcome/, @response.redirect_url
+    assert_empty css_select('[href="/projects/public"]')
+  end
+
+  test "visit public projects page when anon config is not enabled and public projects page is enabled and expect login page" do
+    Rails.configuration.enable_public_projects_page = true
+    get :index
+    assert_response :redirect
+    assert_match /\/users\/welcome/, @response.redirect_url
+    assert_empty css_select('[href="/projects/public"]')
   end
 end