From d076882dc14edac0b25768cb3677f2323346d79e Mon Sep 17 00:00:00 2001 From: Chris Lowis Date: Tue, 3 Oct 2023 15:51:41 +0100 Subject: [PATCH] WIP: failing tests to reproduce bug --- test/models/user_test.rb | 10 ++++++++++ test/models/users_filter_test.rb | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 3e1014c1ac..f029ca7250 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -1043,6 +1043,16 @@ def setup specified_permissions = [app1.signin_permission, app2.signin_permission] assert_equal [user1, user2], User.with_permission(specified_permissions.map(&:to_param)) end + + should "only return a user once even when they have two permissions for the same app" do + app = create(:application) + + permission = create(:supported_permission, application: app) + create(:user, supported_permissions: [app.signin_permission, permission]) + + specified_permissions = [app.signin_permission, permission] + assert_equal 1, User.with_permission(specified_permissions.map(&:to_param)).count + end end context ".with_organisation" do diff --git a/test/models/users_filter_test.rb b/test/models/users_filter_test.rb index 3db9b54eff..6d1b4768f9 100644 --- a/test/models/users_filter_test.rb +++ b/test/models/users_filter_test.rb @@ -211,6 +211,17 @@ class UsersFilterTest < ActiveSupport::TestCase assert_equal %w[user1 user3], filter.users.map(&:name) end + + should "return a user once if they have multiple selected permissions for the same app" do + app = create(:application, name: "App 1") + permission = create(:supported_permission, application: app, name: "Permission 1") + + create(:user, name: "user", supported_permissions: [app.signin_permission, permission]) + + filter = UsersFilter.new(User.all, @current_user, permissions: [app.signin_permission, permission].map(&:to_param)) + + assert_equal %w[user], filter.users.map(&:name) + end end context "#permission_option_select_options" do