Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix|Refactor: Use global permission mock shared context

Aaron Contreras744133127e5a
diff --git a/spec/features/global_roles/global_role_assignment_spec.rb b/spec/features/global_roles/global_role_assignment_spec.rb
index 802df4c5370..3e4a09d00f0 100644
--- a/spec/features/global_roles/global_role_assignment_spec.rb
+++ b/spec/features/global_roles/global_role_assignment_spec.rb
@@ -27,7 +27,7 @@
#++
require 'spec_helper'
-require_relative './mock_global_permissions'
+require_relative 'mock_global_permissions'
RSpec.describe 'Global role: Global role assignment',
js: true,
@@ -37,9 +37,8 @@ RSpec.describe 'Global role: Global role assignment',
end
describe 'Going to the global role assignment page' do
- before do
- mock_global_permissions [['global1', { project_module: :global }], ['global2', { project_module: :global }]]
- end
+ include_context 'with mocked global permissions',
+ [['global1', { project_module: :global }], ['global2', { project_module: :global }]]
let!(:global_role1) { create(:global_role, name: 'global_role1', permissions: %i[global1]) }
let!(:global_role2) { create(:global_role, name: 'global_role2', permissions: %i[global2]) }
@@ -67,36 +66,43 @@ RSpec.describe 'Global role: Global role assignment',
expect(page).to have_text 'global_role2'
end
- # And I select the available global role "global_role"
+ # And I select the available global role "global_role2"
check 'global_role2'
# And I press "Add"
click_on 'Add'
- # And I should not see "global_role" within "#available_principal_roles"
- # And I should see "There is currently nothing to display"
+ wait_for_network_idle
+
+ # And I should see "global_role1" within "#table_principal_roles"
+ # Then I should see "global_role2" within "#table_principal_roles"
page.within('#table_principal_roles') do
expect(page).to have_text 'global_role1'
expect(page).to have_text 'global_role2'
end
- # Then I should see "global_role" within "#table_principal_roles"
+ # And I should not see "global_role1" within "#available_principal_roles"
+ # And I should not see "global_role2" within "#available_principal_roles"
page.within('#available_principal_roles') do
expect(page).not_to have_text 'global_role1'
expect(page).not_to have_text 'global_role2'
end
- # And I delete the assigned role "global_role"
+ # And I delete the assigned role "global_role1"
page.within("#assigned_global_role_#{global_role1.id}") do
page.find('.buttons a.icon-delete').click
end
- # Then I should see "global_role" within "#table_principal_roles"
+ wait_for_network_idle
+
+ # Then I should see "global_role1" within "#available_principal_roles"
+ # And I should not see "global_role2" within "#available_principal_roles"
page.within('#available_principal_roles') do
- expect(page).not_to have_text 'global_role2'
expect(page).to have_text 'global_role1'
+ expect(page).not_to have_text 'global_role2'
end
- # And I should not see "global_role" within "#available_principal_roles"
- # And I should see "There is currently nothing to display"
+
+ # And I should not see "global_role1" within "#table_principal_roles"
+ # And I should see "global_role1" within "#table_principal_roles"
page.within('#table_principal_roles') do
expect(page).not_to have_text 'global_role1'
expect(page).to have_text 'global_role2'
diff --git a/spec/features/global_roles/global_role_crud_spec.rb b/spec/features/global_roles/global_role_crud_spec.rb
index 61fd9b1e9c3..896c2ce647e 100644
--- a/spec/features/global_roles/global_role_crud_spec.rb
+++ b/spec/features/global_roles/global_role_crud_spec.rb
@@ -27,15 +27,16 @@
#++
require 'spec_helper'
-require_relative './mock_global_permissions'
+require_relative 'mock_global_permissions'
RSpec.describe 'Global role: Global role CRUD',
js: true,
with_cuprite: true do
# Scenario: Global Role creation
# Given there is the global permission "glob_test" of the module "global_group"
+ include_context 'with mocked global permissions', [['glob_test', { project_module: 'global_group' }]]
+
before do
- mock_global_permissions [['glob_test', { project_module: 'global_group' }]]
login_as current_user
end
@@ -53,7 +54,7 @@ RSpec.describe 'Global role: Global role CRUD',
# And I should see "Global group"
expect(page).to have_text 'GLOBAL GROUP'
# And I should see "Glob test"
- expect(page).to have_text 'Permission Glob Test'
+ expect(page).to have_text 'Glob test'
# And I should not see "Issues can be assigned to this role"
expect(page).not_to have_text 'Issues can be assigned to this role'
# When I fill in "Name" with "Manager"
diff --git a/spec/features/global_roles/no_module_spec.rb b/spec/features/global_roles/no_module_spec.rb
index fdbd402a734..955ee285583 100644
--- a/spec/features/global_roles/no_module_spec.rb
+++ b/spec/features/global_roles/no_module_spec.rb
@@ -27,7 +27,7 @@
#++
require 'spec_helper'
-require_relative './mock_global_permissions'
+require_relative 'mock_global_permissions'
RSpec.describe 'Global role: No module',
js: true,
@@ -36,15 +36,15 @@ RSpec.describe 'Global role: No module',
let(:project) { create(:project) }
let!(:role) { create(:role) }
+ # Scenario:
+ # Given there is the global permission "glob_test" of the module "global"
+ include_context 'with mocked global permissions', [['global_perm1', { project_module: :global }]]
+
before do
login_as admin
end
it 'Global Rights Modules do not exist as Project -> Settings -> Modules' do
- # Scenario:
- # Given there is the global permission "glob_test" of the module "global"
- mock_global_permissions [['global_perm1', { project_module: :global }]]
-
# And there is 1 project with the following:
# | name | test |
# | identifier | test |