mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
Fix flickering cleanup_inherited_roles_service_integration_spec test
The subject test was `Member.find_by(principal: users.last).roles`. As there are 3 different `Member` records having the same principal, it could return any of them. Most of the time it would always be the first one, which is a project role membership and satisfies the test conditions, but occasionnally, it would be the global role membership or the work package role membership and the test would fail. Using `Member.where(principal: users.last).flat_map(&:roles)` and testing for all roles fixes the test flakiness. Also changed some wording here and there to make the test easier to understand.
This commit is contained in:
@@ -32,16 +32,16 @@ require "spec_helper"
|
||||
|
||||
RSpec.describe Groups::CleanupInheritedRolesService, "integration", type: :model do
|
||||
subject(:service_call) do
|
||||
members.destroy_all
|
||||
group_members.destroy_all
|
||||
instance.call(params)
|
||||
end
|
||||
|
||||
shared_let(:current_user) { create(:admin) }
|
||||
shared_let(:project) { create(:project) }
|
||||
shared_let(:work_package) { create(:work_package, project:) }
|
||||
shared_let(:work_package) { create(:work_package, project:, author: current_user) }
|
||||
shared_let(:role) { create(:project_role) }
|
||||
shared_let(:work_package_role) { create(:view_work_package_role) }
|
||||
shared_let(:global_role) { create(:global_role) }
|
||||
shared_let(:current_user) { create(:admin) }
|
||||
|
||||
shared_let(:users) { create_list(:user, 2) }
|
||||
|
||||
@@ -62,7 +62,7 @@ RSpec.describe Groups::CleanupInheritedRolesService, "integration", type: :model
|
||||
|
||||
let(:params) { { message: } }
|
||||
let(:message) { "Some message" }
|
||||
let(:members) { Member.where(principal: group) }
|
||||
let(:group_members) { Member.where(principal: group) }
|
||||
|
||||
let(:instance) do
|
||||
described_class.new(group, current_user:)
|
||||
@@ -211,18 +211,18 @@ RSpec.describe Groups::CleanupInheritedRolesService, "integration", type: :model
|
||||
.to be_success
|
||||
end
|
||||
|
||||
it "removes memberships associated to the member roles" do
|
||||
it "removes memberships associated to the given member roles" do
|
||||
service_call
|
||||
|
||||
expect(Member.where(principal: users.first))
|
||||
.to be_empty
|
||||
end
|
||||
|
||||
it "keeps the memberships not associated to the member roles" do
|
||||
it "keeps the memberships not associated to the given member roles" do
|
||||
service_call
|
||||
|
||||
expect(Member.find_by(principal: users.last).roles)
|
||||
.to contain_exactly(role)
|
||||
expect(Member.where(principal: users.last).flat_map(&:roles))
|
||||
.to contain_exactly(role, work_package_role, global_role)
|
||||
end
|
||||
|
||||
it "sends no notifications" do
|
||||
|
||||
Reference in New Issue
Block a user