mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 12:33:45 +08:00
e219588142
* Introduced fab!, a helper that creates database state for a group It's almost identical to let_it_be, except: 1. It creates a new object for each test by default, 2. You can disable it using PREFABRICATION=0
48 lines
1.3 KiB
Ruby
48 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe GroupShowSerializer do
|
|
fab!(:user) { Fabricate(:user) }
|
|
fab!(:group) { Fabricate(:group) }
|
|
|
|
context 'admin user' do
|
|
fab!(:user) { Fabricate(:admin) }
|
|
fab!(:group) { Fabricate(:group, users: [user]) }
|
|
|
|
it 'should return the right attributes' do
|
|
json = GroupShowSerializer.new(group, scope: Guardian.new(user)).as_json
|
|
|
|
expect(json[:group_show][:is_group_owner]).to eq(true)
|
|
expect(json[:group_show][:is_group_user]).to eq(true)
|
|
end
|
|
end
|
|
|
|
context 'group owner' do
|
|
before do
|
|
group.add_owner(user)
|
|
end
|
|
|
|
it 'should return the right attributes' do
|
|
json = GroupShowSerializer.new(group, scope: Guardian.new(user)).as_json
|
|
|
|
expect(json[:group_show][:is_group_owner]).to eq(true)
|
|
expect(json[:group_show][:is_group_user]).to eq(true)
|
|
end
|
|
end
|
|
|
|
describe '#mentionable' do
|
|
fab!(:group) { Fabricate(:group, mentionable_level: Group::ALIAS_LEVELS[:everyone]) }
|
|
|
|
it 'should return the right value' do
|
|
json = GroupShowSerializer.new(group, scope: Guardian.new).as_json
|
|
|
|
expect(json[:group_show][:mentionable]).to eq(nil)
|
|
|
|
json = GroupShowSerializer.new(group, scope: Guardian.new(user)).as_json
|
|
|
|
expect(json[:group_show][:mentionable]).to eq(true)
|
|
end
|
|
end
|
|
end
|