mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:28:37 +08:00
FIX: Show groups that user is owner of on groups page.
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Group do
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
describe '#builtin' do
|
||||
context "verify enum sequence" do
|
||||
@ -408,4 +410,44 @@ describe Group do
|
||||
expect(group.bio_cooked).to include("unicorn.png")
|
||||
end
|
||||
|
||||
describe ".visible_groups" do
|
||||
let(:group) { Fabricate(:group, visible: false) }
|
||||
let(:group_2) { Fabricate(:group, visible: true) }
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
group
|
||||
group_2
|
||||
end
|
||||
|
||||
describe 'when user is an admin' do
|
||||
it 'should return the right groups' do
|
||||
expect(Group.visible_groups(admin).pluck(:id).sort)
|
||||
.to eq([group.id, group_2.id].concat(Group::AUTO_GROUP_IDS.keys - [0]).sort)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when user is owner of a group' do
|
||||
it 'should return the right groups' do
|
||||
group.add_owner(user)
|
||||
|
||||
expect(Group.visible_groups(user).pluck(:id).sort)
|
||||
.to eq([group.id, group_2.id])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when user is not the owner of any group' do
|
||||
it 'should return the right groups' do
|
||||
expect(Group.visible_groups(user).pluck(:id).sort)
|
||||
.to eq([group_2.id])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'user is nil' do
|
||||
it 'should return the right groups' do
|
||||
expect(Group.visible_groups(nil).pluck(:id).sort).to eq([group_2.id])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user