2017-05-05 02:34:47 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe BasicGroupSerializer do
|
2018-04-17 03:56:55 -04:00
|
|
|
let(:guardian) { Guardian.new }
|
|
|
|
let(:group) { Fabricate(:group) }
|
2018-05-17 06:10:17 -04:00
|
|
|
subject { described_class.new(group, scope: guardian, root: false) }
|
2017-05-05 02:34:47 -04:00
|
|
|
|
|
|
|
describe '#display_name' do
|
|
|
|
describe 'automatic group' do
|
|
|
|
let(:group) { Group.find(1) }
|
|
|
|
|
|
|
|
it 'should include the display name' do
|
|
|
|
expect(subject.display_name).to eq(I18n.t('groups.default_names.admins'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'normal group' do
|
|
|
|
let(:group) { Fabricate(:group) }
|
|
|
|
|
|
|
|
it 'should not include the display name' do
|
|
|
|
expect(subject.display_name).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-04-17 03:56:55 -04:00
|
|
|
|
|
|
|
describe '#bio_raw' do
|
|
|
|
let(:group) { Fabricate(:group, bio_raw: 'testing') }
|
|
|
|
|
2018-05-17 06:10:17 -04:00
|
|
|
subject do
|
|
|
|
described_class.new(group, scope: guardian, root: false, owner_group_ids: [group.id])
|
2018-04-17 03:56:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'group owner' do
|
2018-05-17 06:10:17 -04:00
|
|
|
let(:user) do
|
|
|
|
user = Fabricate(:user)
|
|
|
|
group.add_owner(user)
|
|
|
|
user
|
|
|
|
end
|
|
|
|
|
2018-04-17 03:56:55 -04:00
|
|
|
it 'should include bio_raw' do
|
2018-05-17 06:10:17 -04:00
|
|
|
expect(subject.as_json[:bio_raw]).to eq('testing')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#has_messages' do
|
|
|
|
let(:group) { Fabricate(:group, has_messages: true) }
|
|
|
|
|
|
|
|
describe 'for a staff user' do
|
|
|
|
let(:guardian) { Guardian.new(Fabricate(:moderator)) }
|
|
|
|
|
|
|
|
it 'should be present' do
|
|
|
|
expect(subject.as_json[:has_messages]).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'for a group user' do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:guardian) { Guardian.new(user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
group.add(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be present' do
|
|
|
|
expect(subject.as_json[:has_messages]).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'for a normal user' do
|
|
|
|
let(:guardian) { Guardian.new(Fabricate(:user)) }
|
|
|
|
|
|
|
|
it 'should not be present' do
|
|
|
|
expect(subject.as_json[:has_messages]).to eq(nil)
|
2018-04-17 03:56:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-05-05 02:34:47 -04:00
|
|
|
end
|