FIX: update group user count when bulk adding users
This commit is contained in:
parent
4791b39773
commit
709f201bd4
|
@ -534,6 +534,16 @@ class Group < ActiveRecord::Base
|
||||||
if user_attributes.present?
|
if user_attributes.present?
|
||||||
User.where(id: user_ids).update_all(user_attributes)
|
User.where(id: user_ids).update_all(user_attributes)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# update group user count
|
||||||
|
Group.exec_sql <<-SQL.squish
|
||||||
|
UPDATE groups g
|
||||||
|
SET user_count =
|
||||||
|
(SELECT COUNT(gu.user_id)
|
||||||
|
FROM group_users gu
|
||||||
|
WHERE gu.group_id = g.id)
|
||||||
|
WHERE g.id = #{self.id};
|
||||||
|
SQL
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.grant_trust_level.present?
|
if self.grant_trust_level.present?
|
||||||
|
|
|
@ -619,6 +619,13 @@ describe Group do
|
||||||
|
|
||||||
expect(group.group_users.map(&:user_id)).to contain_exactly(user.id, admin.id)
|
expect(group.group_users.map(&:user_id)).to contain_exactly(user.id, admin.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'updates group user count' do
|
||||||
|
expect {
|
||||||
|
group.bulk_add([user.id, admin.id])
|
||||||
|
group.reload
|
||||||
|
}.to change { group.user_count }.by(2)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "Correctly updates has_messages" do
|
it "Correctly updates has_messages" do
|
||||||
|
|
Loading…
Reference in New Issue