FIX: Publish group's categories to user when adding user to group.
https://meta.discourse.org/t/joining-a-group-doesnt-take-effect-unless-the-browser-is-hard-refreshed/57357/11?u=tgxworld
This commit is contained in:
parent
5f441a2614
commit
af3dc4e537
|
@ -371,6 +371,11 @@ class Group < ActiveRecord::Base
|
|||
|
||||
def add(user)
|
||||
self.users.push(user) unless self.users.include?(user)
|
||||
|
||||
MessageBus.publish('/categories', {
|
||||
categories: ActiveModel::ArraySerializer.new(self.categories).as_json
|
||||
}, user_ids: [user.id])
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ require 'rails_helper'
|
|||
describe Group do
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:group) { Fabricate(:group) }
|
||||
|
||||
describe '#builtin' do
|
||||
context "verify enum sequence" do
|
||||
|
@ -450,4 +451,20 @@ describe Group do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#add' do
|
||||
context 'when adding a user into a public group' do
|
||||
let(:category) { Fabricate(:category) }
|
||||
|
||||
it "should publish the group's categories to the client" do
|
||||
group.update!(public: true, categories: [category])
|
||||
|
||||
message = MessageBus.track_publish { group.add(user) }.first
|
||||
|
||||
expect(message.data[:categories].count).to eq(1)
|
||||
expect(message.data[:categories].first[:id]).to eq(category.id)
|
||||
expect(message.user_ids).to eq([user.id])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue