FIX: only ONE user on site could have a list of muted users
This commit is contained in:
parent
4e3bea67e4
commit
14741b5dac
|
@ -75,17 +75,13 @@ class UserUpdater
|
|||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :user, :guardian
|
||||
|
||||
def update_muted_users(usernames)
|
||||
usernames ||= ""
|
||||
desired_ids = User.where(username: usernames.split(",")).pluck(:id)
|
||||
if desired_ids.empty?
|
||||
MutedUser.where(user_id: user.id).destroy_all
|
||||
else
|
||||
MutedUser.where('id not in (?)', desired_ids).destroy_all
|
||||
MutedUser.where('user_id = ? AND muted_user_id not in (?)', user.id, desired_ids).destroy_all
|
||||
|
||||
# SQL is easier here than figuring out how to do the same in AR
|
||||
MutedUser.exec_sql("INSERT into muted_users(user_id, muted_user_id, created_at, updated_at)
|
||||
|
@ -102,6 +98,10 @@ class UserUpdater
|
|||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :user, :guardian
|
||||
|
||||
def format_url(website)
|
||||
if website =~ /^http/
|
||||
website
|
||||
|
|
|
@ -4,6 +4,31 @@ describe UserUpdater do
|
|||
|
||||
let(:acting_user) { Fabricate.build(:user) }
|
||||
|
||||
describe '#update_muted_users' do
|
||||
it 'has no cross talk' do
|
||||
u1 = Fabricate(:user)
|
||||
u2 = Fabricate(:user)
|
||||
u3 = Fabricate(:user)
|
||||
|
||||
|
||||
updater = UserUpdater.new(u1, u1)
|
||||
updater.update_muted_users("#{u2.username},#{u3.username}")
|
||||
|
||||
updater = UserUpdater.new(u2, u2)
|
||||
updater.update_muted_users("#{u3.username},#{u1.username}")
|
||||
|
||||
|
||||
updater = UserUpdater.new(u3, u3)
|
||||
updater.update_muted_users("")
|
||||
|
||||
|
||||
expect(MutedUser.where(user_id: u2.id).count).to eq 2
|
||||
expect(MutedUser.where(user_id: u1.id).count).to eq 2
|
||||
expect(MutedUser.where(user_id: u3.id).count).to eq 0
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe '#update' do
|
||||
it 'saves user' do
|
||||
user = Fabricate(:user, name: 'Billy Bob')
|
||||
|
|
Loading…
Reference in New Issue