mirror of
https://github.com/meineerde/redmine.git
synced 2026-02-01 03:57:15 +00:00
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
This commit is contained in:
parent
d325010d64
commit
dcdd453287
@ -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|
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user