6465-Added tests to project_controllers_test and users_controller
authorManoj <jonam33@gmail.com>
Wed, 15 Jul 2015 12:22:16 +0000 (08:22 -0400)
committerManoj <jonam33@gmail.com>
Wed, 15 Jul 2015 12:22:16 +0000 (08:22 -0400)
test and removed tests from users_test.

apps/workbench/test/controllers/projects_controller_test.rb
apps/workbench/test/controllers/users_controller_test.rb
apps/workbench/test/integration/users_test.rb

index ba4188e4c5cd57cb214a0e93a7254f13c24293be..a036a8f4f6bdb04603ded2e826492a4ffd9f4b89 100644 (file)
@@ -353,8 +353,19 @@ class ProjectsControllerTest < ActionController::TestCase
   test "project viewer can't see project sharing tab" do
     project = api_fixture('groups')['aproject']
     get(:show, {id: project['uuid']}, session_for(:project_viewer))
-    refute_includes @response.body, '<div id ="Sharing"'
+    refute_includes @response.body, '<div id="Sharing"'
     assert_includes @response.body, '<div id="Data_collections"'
   end
 
+  [
+    'admin',
+    'active',
+  ].each do |username|
+    test "#{username} can see project sharing tab" do
+     project = api_fixture('groups')['aproject']
+     get(:show, {id: project['uuid']}, session_for(username))
+     assert_includes @response.body, '<div id="Sharing"'
+     assert_includes @response.body, '<div id="Data_collections"'
+    end
+  end
 end
index c1436da4545e93197c95d2b850614cf55c95cafc..f439d6eab28a2c9b368778cdfed11e382cf8bbc1 100644 (file)
@@ -1,6 +1,7 @@
 require 'test_helper'
 
 class UsersControllerTest < ActionController::TestCase
+
   test "valid token works in controller test" do
     get :index, {}, session_for(:active)
     assert_response :success
@@ -74,4 +75,48 @@ class UsersControllerTest < ActionController::TestCase
     end
     assert_equal 1, found_email, "Expected 1 email after requesting shell access"
   end
+
+  [
+    'admin',
+    'active',
+  ].each do |username|
+    test "access users page as #{username} and verify show button is available" do
+      admin_user = api_fixture('users','admin')
+      active_user = api_fixture('users','active')
+      get :index, {}, session_for(username)
+      if username == 'admin'
+        assert_match /<a href="\/projects\/#{admin_user['uuid']}">Home<\/a.*./, @response.body
+        assert_match /<a href="\/projects\/#{active_user['uuid']}">Home<\/a.*./, @response.body
+        assert_match /<a.*href="\/users\/#{admin_user['uuid']}".*Show<\/a.*./, @response.body
+        assert_match /<a.*href="\/users\/#{active_user['uuid']}".*Show<\/a.*./, @response.body
+        assert_includes @response.body, admin_user['email']
+        assert_includes @response.body, active_user['email']
+      else
+        refute_match  /a href=.*Home<.*\/a.*./, @response.body
+        refute_match /<a.*href="\/users\/#{admin_user['uuid']}".*Show<\/a.*./, @response.body
+        assert_match /<a.*href="\/users\/#{active_user['uuid']}".*Show<\/a.*./, @response.body
+        assert_includes @response.body, active_user['email']
+      end
+    end
+  end
+
+  [
+    'admin',
+    'active',
+  ].each do |username|
+    test "access settings drop down menu as #{username}" do
+      admin_user = api_fixture('users','admin')
+      active_user = api_fixture('users','active')
+      get :show, {
+        id: api_fixture('users')[username]['uuid']
+      }, session_for(username)
+      if username == 'admin'
+        assert_includes @response.body, admin_user['email']
+        refute_empty css_select('[id="system-menu"]')
+      else
+        assert_includes @response.body, active_user['email']
+        assert_empty css_select('[id="system-menu"]')
+      end
+    end
+  end
 end
index db670815d83ca1ca86816c859191dbce9dd52660..1ae302c23947c2968d194fdb006bcdaf3561be04 100644 (file)
@@ -197,44 +197,4 @@ class UsersTest < ActionDispatch::IntegrationTest
     click_link 'Metadata'
     assert page.has_text? 'VirtualMachine: testvm.shell'
   end
-
-  [
-    'admin',
-    'active',
-  ].each do |username|
-    test "login as #{username} and access show button" do
-      need_javascript
-
-      user = api_fixture('users', username)
-
-      visit page_with_token(username, '/users')
-
-      within('tr', text: user['uuid']) do
-        assert_text user['email']
-        if username == 'admin'
-          assert_selector 'a', text: 'Home'
-        else
-          assert_no_selector 'a', text: 'Home'
-        end
-        assert_selector 'a', text: 'Show'
-        find('a', text: 'Show').click
-      end
-      assert_selector 'a', text: 'Attributes'
-    end
-  end
-
-  test "admin user can access another user page" do
-    need_javascript
-
-    visit page_with_token('admin', '/users')
-
-    active_user = api_fixture('users', 'active')
-    within('tr', text: active_user['uuid']) do
-      assert_text active_user['email']
-      assert_selector "a[href=\"/projects/#{active_user['uuid']}\"]", text: 'Home'
-      assert_selector 'a', text: 'Show'
-      find('a', text: 'Show').click
-    end
-    assert_selector 'a', text:'Attributes'
-  end
 end