Skip to content

Commit

Permalink
Merge pull request #3349 from dodona-edu/fix/institution-merge-should…
Browse files Browse the repository at this point in the history
…-also-merge-case-insensetive-equal-users

Merge usernames which match case insensitively when merging institutions
  • Loading branch information
jorg-vr authored Feb 4, 2022
2 parents a5d83e6 + 9a8a26c commit d6bcd9a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tasks/merge_institutions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def merge_institutions_interactive(i1_id, i2_id)
return unless c == 'y'

i1.users.where(username: i2.users.pluck(:username)).each do |u1|
u2 = i2.users.find { |u| u.username == u1.username }
u2 = i2.users.find { |u| u.username.downcase == u1.username.downcase }
next if u2.nil?

@output.puts ''
Expand Down
16 changes: 16 additions & 0 deletions test/tasks/merge_institutions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,20 @@ def merge_institutions_interactive(i1_id, i2_id, *chars)
assert Institution.exists?(i2.id)
assert s.on_filesystem?
end

test 'The script should also merge case insensitive equal usernames' do
i1 = create :institution
i2 = create :institution
u1 = create :user, username: 'test', institution: i1
u2 = create :user, username: 'Test', institution: i2

merge_institutions_interactive i1.id, i2.id, 'y', 'y', 'y'

assert_not Institution.exists?(i1.id)
assert Institution.exists?(i2.id)
assert_not User.exists?(u1.id)
assert User.exists?(u2.id)
u2.reload
assert_equal i2, u2.institution
end
end

0 comments on commit d6bcd9a

Please sign in to comment.