From dcdd453287e350a0c58f31945582a7f1302b5b7e Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Fri, 11 Apr 2025 07:43:44 +0000 Subject: [PATCH] Fix RuboCop Lint/SharedMutableDefault (#41884). Although `Hash.new {|h, k| h[k] = []}` is commonly used for this pattern, `Hash.new {|_h, _k| []}` is more appropriate here to avoid modifying the hash when accessing missing keys, which would cause `UserTest#test_accessing_projects_by_role_with_no_projects_should_return_an_empty_array` to fail. git-svn-id: https://svn.redmine.org/redmine/trunk@23622 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/user.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 4ce63f809..4210a6a87 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -643,7 +643,7 @@ class User < Principal def projects_by_role return @projects_by_role if @projects_by_role - result = Hash.new([]) + result = Hash.new {|_h, _k| []} project_ids_by_role.each do |role, ids| result[role] = Project.where(:id => ids).to_a end @@ -676,7 +676,7 @@ class User < Principal hash[role_id] << project_id end - result = Hash.new([]) + result = Hash.new {|_h, _k| []} if hash.present? roles = Role.where(:id => hash.keys).to_a hash.each do |role_id, proj_ids|