From ef419002bb9e6fa6ceac9a3117af0263f32f465e Mon Sep 17 00:00:00 2001 From: Matthew Baumann Date: Wed, 13 Jul 2022 17:41:11 -0500 Subject: [PATCH 1/4] Add notifications column to grant permissions index. #792 --- app/helpers/application_helper.rb | 5 +++++ app/views/grant_permissions/index.html.haml | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 49d1d9ec..89729ade 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -32,6 +32,11 @@ def title_tag_content(page_title: '') page_title.empty? ? base_title : "#{page_title} | #{base_title}" end + # Boolean value changes + def on_off_boolean(boolean) + boolean ? 'On' : 'Off' + end + # Dates def date_mmddyyyy(date) date.blank? ? '' : date.strftime('%m/%d/%Y') diff --git a/app/views/grant_permissions/index.html.haml b/app/views/grant_permissions/index.html.haml index e54715bb..4cbd3832 100644 --- a/app/views/grant_permissions/index.html.haml +++ b/app/views/grant_permissions/index.html.haml @@ -41,6 +41,8 @@ %th Role %th + Notifications + %th %tbody - @grant_permissions.each do |grant_permission| @@ -50,5 +52,7 @@ = grant_permission_user_name %td = grant_permission.role.capitalize + %td + = on_off_boolean(grant_permission.submission_notification) %td = render partial: "#{current_user.get_role_by_grant(grant: @grant)}_links", locals: { grant_permission: grant_permission, grant: @grant, grant_permission_user_name: grant_permission_user_name } From 16d2c2975a8c33c87a80ae49c036ee49aaa8cd73 Mon Sep 17 00:00:00 2001 From: Matthew Baumann Date: Fri, 15 Jul 2022 09:41:13 -0500 Subject: [PATCH 2/4] add specs for on_off_boolean helper. #792 --- spec/helpers/application_helper_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index b7a3ef8f..262fcd07 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -36,4 +36,18 @@ def excel_worksheet_reserved_characters expect(title_tag_content(page_title: 'Page Name')).to eql 'Page Name | TEST' end end + + context 'booleans' do + describe '#on_off_boolean(boolean)' do + it 'returns On when given a true boolean' do + boolean = true + helper.on_off_boolean(boolean).should eql("On") + end + + it 'returns Off when given a false boolean' do + boolean = false + helper.on_off_boolean(boolean).should eql("Off") + end + end + end end From e4412aac8af602fc9eced73ff5ee5ab77d9c586b Mon Sep 17 00:00:00 2001 From: Matthew Baumann Date: Fri, 15 Jul 2022 11:09:04 -0500 Subject: [PATCH 3/4] add specs on index row for grant_permissions. #792 --- app/views/grant_permissions/index.html.haml | 2 +- .../grant_permissions_spec.rb | 61 +++---------------- 2 files changed, 11 insertions(+), 52 deletions(-) diff --git a/app/views/grant_permissions/index.html.haml b/app/views/grant_permissions/index.html.haml index 4cbd3832..410d2d57 100644 --- a/app/views/grant_permissions/index.html.haml +++ b/app/views/grant_permissions/index.html.haml @@ -47,7 +47,7 @@ %tbody - @grant_permissions.each do |grant_permission| - grant_permission_user_name = full_name(grant_permission.user) - %tr + %tr{ id: "#{dom_id(grant_permission)}" } %td = grant_permission_user_name %td diff --git a/spec/system/grant_permissions/grant_permissions_spec.rb b/spec/system/grant_permissions/grant_permissions_spec.rb index 581f4bfd..036d073d 100644 --- a/spec/system/grant_permissions/grant_permissions_spec.rb +++ b/spec/system/grant_permissions/grant_permissions_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'rails_helper' +include ApplicationHelper include UsersHelper RSpec.describe 'GrantPermissions', type: :system, js: true do @@ -23,16 +24,15 @@ describe 'grant editor user' do before(:each) do login_as(@grant_editor, scope: :saml_user) + visit grant_grant_permissions_path(@grant) end context '#index' do scenario 'includes link to add permission' do - visit grant_grant_permissions_path(@grant) expect(page).to have_link 'Grant access to another user', href: new_grant_grant_permission_path(@grant) end scenario 'includes edit link, excludes delete link' do - visit grant_grant_permissions_path(@grant) expect(page).to have_link 'Edit', href: edit_grant_grant_permission_path(@grant, @grant_admin_role) expect(page).not_to have_link 'Delete', href: grant_grant_permission_path(@grant, @grant_admin_role) expect(page).to have_link 'Edit', href: edit_grant_grant_permission_path(@grant, @grant_editor_role) @@ -40,6 +40,14 @@ expect(page).to have_link 'Edit', href: edit_grant_grant_permission_path(@grant, @grant_viewer_role) expect(page).not_to have_link 'Delete', href: grant_grant_permission_path(@grant, @grant_viewer_role) end + + scenario 'includes information in grant admin table row' do + within("tr#grant_permission_#{@grant_admin_role.id}") do + expect(page).to have_content(full_name(@grant_admin)) + expect(page).to have_content(@grant_admin_role.role.capitalize) + expect(page).to have_content(on_off_boolean(@grant.grant_permissions.role_admin.first.submission_notification)) + end + end end context '#edit' do @@ -151,55 +159,6 @@ end end - describe 'grant admin user' do - before(:each) do - login_as(@grant_admin, scope: :saml_user) - visit grant_grant_permissions_path(@grant) - end - - context '#index' do - scenario 'includes link to add permission' do - visit grant_grant_permissions_path(@grant) - expect(page).to have_link 'Grant access to another user', href: new_grant_grant_permission_path(@grant) - end - end - - context '#edit' do - scenario 'can visit the permissions index' do - visit grant_grant_permissions_path(@grant) - expect(page).not_to have_content authorization_error_text - end - - scenario 'includes edit and delete links' do - expect(page).to have_link 'Edit', href: edit_grant_grant_permission_path(@grant, @grant_admin_role) - expect(page).to have_link 'Delete', href: grant_grant_permission_path(@grant, @grant_admin_role) - expect(page).to have_link 'Edit', href: edit_grant_grant_permission_path(@grant, @grant_editor_role) - expect(page).to have_link 'Delete', href: grant_grant_permission_path(@grant, @grant_editor_role) - expect(page).to have_link 'Edit', href: edit_grant_grant_permission_path(@grant, @grant_viewer_role) - expect(page).to have_link 'Delete', href: grant_grant_permission_path(@grant, @grant_viewer_role) - end - end - - context '#delete' do - scenario 'cannot delete last admin grant_permission' do - expect do - click_link('Delete', href: grant_grant_permission_path(@grant, @grant_admin_role)) - page.driver.browser.switch_to.alert.accept - expect(page).to have_content('This user\'s role cannot be deleted.') - end.not_to change{@grant.grant_permissions.count} - end - - scenario 'can delete a grant_permission' do - expect do - expect(page).to have_content(full_name(@grant_viewer)) - click_link('Delete', href: grant_grant_permission_path(@grant, @grant_viewer_role)) - page.driver.browser.switch_to.alert.accept - expect(page).to have_content("#{full_name(@grant_viewer)}'s role was removed for this grant.") - end.to change{@grant.grant_permissions.count}.by (-1) - end - end - end - describe 'grant viewer user' do before(:each) do login_as(@grant_viewer, scope: :saml_user) From 310e907d56bcf66b543b15a1fe5d72c5e3110061 Mon Sep 17 00:00:00 2001 From: Matthew Baumann Date: Fri, 15 Jul 2022 11:14:39 -0500 Subject: [PATCH 4/4] replace the grant_admin specs that were deleted. #792 --- .../grant_permissions_spec.rb | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/spec/system/grant_permissions/grant_permissions_spec.rb b/spec/system/grant_permissions/grant_permissions_spec.rb index 036d073d..03580bac 100644 --- a/spec/system/grant_permissions/grant_permissions_spec.rb +++ b/spec/system/grant_permissions/grant_permissions_spec.rb @@ -159,6 +159,55 @@ end end + describe 'grant admin user' do + before(:each) do + login_as(@grant_admin, scope: :saml_user) + visit grant_grant_permissions_path(@grant) + end + + context '#index' do + scenario 'includes link to add permission' do + visit grant_grant_permissions_path(@grant) + expect(page).to have_link 'Grant access to another user', href: new_grant_grant_permission_path(@grant) + end + end + + context '#edit' do + scenario 'can visit the permissions index' do + visit grant_grant_permissions_path(@grant) + expect(page).not_to have_content authorization_error_text + end + + scenario 'includes edit and delete links' do + expect(page).to have_link 'Edit', href: edit_grant_grant_permission_path(@grant, @grant_admin_role) + expect(page).to have_link 'Delete', href: grant_grant_permission_path(@grant, @grant_admin_role) + expect(page).to have_link 'Edit', href: edit_grant_grant_permission_path(@grant, @grant_editor_role) + expect(page).to have_link 'Delete', href: grant_grant_permission_path(@grant, @grant_editor_role) + expect(page).to have_link 'Edit', href: edit_grant_grant_permission_path(@grant, @grant_viewer_role) + expect(page).to have_link 'Delete', href: grant_grant_permission_path(@grant, @grant_viewer_role) + end + end + + context '#delete' do + scenario 'cannot delete last admin grant_permission' do + expect do + click_link('Delete', href: grant_grant_permission_path(@grant, @grant_admin_role)) + page.driver.browser.switch_to.alert.accept + expect(page).to have_content('This user\'s role cannot be deleted.') + end.not_to change{@grant.grant_permissions.count} + end + + scenario 'can delete a grant_permission' do + expect do + expect(page).to have_content(full_name(@grant_viewer)) + click_link('Delete', href: grant_grant_permission_path(@grant, @grant_viewer_role)) + page.driver.browser.switch_to.alert.accept + expect(page).to have_content("#{full_name(@grant_viewer)}'s role was removed for this grant.") + end.to change{@grant.grant_permissions.count}.by (-1) + end + end + end + describe 'grant viewer user' do before(:each) do login_as(@grant_viewer, scope: :saml_user)