2016-11-29 16:25:02 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe GroupShowSerializer do
|
2017-07-27 16:51:25 +08:00
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:group) { Fabricate(:group) }
|
|
|
|
|
2016-11-29 16:25:02 +08:00
|
|
|
context 'admin user' do
|
|
|
|
let(:user) { Fabricate(:admin) }
|
|
|
|
let(: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
|
2017-07-27 16:51:25 +08:00
|
|
|
|
|
|
|
describe '#mentionable' do
|
2017-08-29 00:32:08 +08:00
|
|
|
let(:group) { Fabricate(:group, mentionable_level: Group::ALIAS_LEVELS[:everyone]) }
|
2017-07-27 16:51:25 +08:00
|
|
|
|
|
|
|
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
|
2016-11-29 16:25:02 +08:00
|
|
|
end
|