2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-04-29 02:33:24 -04:00
|
|
|
|
|
|
|
describe Group do
|
2017-02-03 03:51:32 -05:00
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
let(:user) { Fabricate(:user) }
|
2017-06-02 04:38:14 -04:00
|
|
|
let(:group) { Fabricate(:group) }
|
2013-05-06 00:49:56 -04:00
|
|
|
|
2016-01-08 05:53:52 -05:00
|
|
|
describe '#builtin' do
|
|
|
|
context "verify enum sequence" do
|
|
|
|
before do
|
|
|
|
@builtin = Group.builtin
|
|
|
|
end
|
|
|
|
|
|
|
|
it "'moderators' should be at 1st position" do
|
|
|
|
expect(@builtin[:moderators]).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "'trust_level_2' should be at 4th position" do
|
|
|
|
expect(@builtin[:trust_level_2]).to eq(4)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-16 20:46:30 -04:00
|
|
|
# UGLY but perf is horrible with this callback
|
|
|
|
before do
|
|
|
|
User.set_callback(:create, :after, :ensure_in_trust_level_group)
|
|
|
|
end
|
|
|
|
after do
|
|
|
|
User.skip_callback(:create, :after, :ensure_in_trust_level_group)
|
|
|
|
end
|
|
|
|
|
2013-05-09 03:37:34 -04:00
|
|
|
describe "validation" do
|
|
|
|
let(:group) { build(:group) }
|
|
|
|
|
|
|
|
it "is invalid for blank" do
|
|
|
|
group.name = ""
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(group.valid?).to eq false
|
2013-05-09 03:37:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "is valid for a longer name" do
|
|
|
|
group.name = "this_is_a_name"
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(group.valid?).to eq true
|
2013-05-09 03:37:34 -04:00
|
|
|
end
|
2013-06-16 23:43:06 -04:00
|
|
|
|
|
|
|
it "is invalid for non names" do
|
|
|
|
group.name = "this is_a_name"
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(group.valid?).to eq false
|
2013-06-16 23:43:06 -04:00
|
|
|
end
|
2014-12-16 07:07:15 -05:00
|
|
|
|
|
|
|
it "is invalid for case-insensitive existing names" do
|
|
|
|
build(:group, name: 'this_is_a_name').save
|
|
|
|
group.name = 'This_Is_A_Name'
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(group.valid?).to eq false
|
2014-12-16 07:07:15 -05:00
|
|
|
end
|
2015-11-27 00:35:16 -05:00
|
|
|
|
|
|
|
it "is invalid for poorly formatted domains" do
|
|
|
|
group.automatic_membership_email_domains = "wikipedia.org|*@example.com"
|
|
|
|
expect(group.valid?).to eq false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is valid for proper domains" do
|
|
|
|
group.automatic_membership_email_domains = "discourse.org|wikipedia.org"
|
|
|
|
expect(group.valid?).to eq true
|
|
|
|
end
|
2015-12-07 06:39:28 -05:00
|
|
|
|
2016-04-08 12:11:58 -04:00
|
|
|
it "is valid for newer TLDs" do
|
|
|
|
group.automatic_membership_email_domains = "discourse.institute"
|
|
|
|
expect(group.valid?).to eq true
|
|
|
|
end
|
|
|
|
|
2015-12-07 06:39:28 -05:00
|
|
|
it "is invalid for bad incoming email" do
|
|
|
|
group.incoming_email = "foo.bar.org"
|
|
|
|
expect(group.valid?).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is valid for proper incoming email" do
|
|
|
|
group.incoming_email = "foo@bar.org"
|
|
|
|
expect(group.valid?).to eq(true)
|
|
|
|
end
|
2017-06-02 10:15:57 -04:00
|
|
|
|
|
|
|
context 'when a group has no owners' do
|
|
|
|
it 'should not allow membership requests' do
|
|
|
|
group.allow_membership_requests = true
|
|
|
|
|
|
|
|
expect(group.valid?).to eq(false)
|
|
|
|
|
|
|
|
expect(group.errors.full_messages).to include(I18n.t(
|
|
|
|
"groups.errors.cant_allow_membership_requests"
|
|
|
|
))
|
|
|
|
|
|
|
|
group.allow_membership_requests = false
|
|
|
|
group.save!
|
|
|
|
|
|
|
|
group.add_owner(user)
|
|
|
|
group.allow_membership_requests = true
|
|
|
|
|
|
|
|
expect(group.valid?).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
2013-05-09 03:37:34 -04:00
|
|
|
end
|
|
|
|
|
2013-09-06 00:07:23 -04:00
|
|
|
def real_admins
|
|
|
|
Group[:admins].user_ids - [-1]
|
|
|
|
end
|
|
|
|
|
|
|
|
def real_moderators
|
|
|
|
Group[:moderators].user_ids - [-1]
|
|
|
|
end
|
|
|
|
|
|
|
|
def real_staff
|
|
|
|
Group[:staff].user_ids - [-1]
|
|
|
|
end
|
|
|
|
|
2015-04-09 22:17:28 -04:00
|
|
|
it "Correctly handles primary groups" do
|
|
|
|
group = Fabricate(:group, primary_group: true)
|
|
|
|
user = Fabricate(:user)
|
|
|
|
|
|
|
|
group.add(user)
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
expect(user.primary_group_id).to eq group.id
|
|
|
|
|
|
|
|
group.remove(user)
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
expect(user.primary_group_id).to eq nil
|
|
|
|
|
|
|
|
group.add(user)
|
|
|
|
group.primary_group = false
|
|
|
|
group.save
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
expect(user.primary_group_id).to eq nil
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
it "Correctly handles title" do
|
|
|
|
|
|
|
|
group = Fabricate(:group, title: 'Super Awesome')
|
|
|
|
user = Fabricate(:user)
|
|
|
|
|
|
|
|
expect(user.title).to eq nil
|
|
|
|
|
|
|
|
group.add(user)
|
|
|
|
user.reload
|
|
|
|
|
|
|
|
expect(user.title).to eq 'Super Awesome'
|
|
|
|
|
|
|
|
group.title = 'BOOM'
|
|
|
|
group.save
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
expect(user.title).to eq 'BOOM'
|
|
|
|
|
|
|
|
group.title = nil
|
|
|
|
group.save
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
expect(user.title).to eq nil
|
|
|
|
|
|
|
|
group.title = "BOB"
|
|
|
|
group.save
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
expect(user.title).to eq "BOB"
|
|
|
|
|
|
|
|
group.remove(user)
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
expect(user.title).to eq nil
|
|
|
|
|
|
|
|
group.add(user)
|
|
|
|
group.destroy
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
expect(user.title).to eq nil
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2017-01-17 23:20:23 -05:00
|
|
|
describe '.refresh_automatic_group!' do
|
|
|
|
it "makes sure the everyone group is not visible" do
|
|
|
|
g = Group.refresh_automatic_group!(:everyone)
|
2017-07-03 15:26:46 -04:00
|
|
|
expect(g.visibility_level).to eq(Group.visibility_levels[:owners])
|
2017-01-17 23:20:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "uses the localized name if name has not been taken" do
|
|
|
|
begin
|
|
|
|
default_locale = SiteSetting.default_locale
|
|
|
|
I18n.locale = SiteSetting.default_locale = 'de'
|
|
|
|
|
|
|
|
group = Group.refresh_automatic_group!(:staff)
|
|
|
|
|
|
|
|
expect(group.name).to_not eq('staff')
|
|
|
|
expect(group.name).to eq(I18n.t('groups.default_names.staff'))
|
|
|
|
ensure
|
|
|
|
I18n.locale = SiteSetting.default_locale = default_locale
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not use the localized name if name has already been taken" do
|
|
|
|
begin
|
|
|
|
default_locale = SiteSetting.default_locale
|
|
|
|
I18n.locale = SiteSetting.default_locale = 'de'
|
|
|
|
|
|
|
|
another_group = Fabricate(:group,
|
2017-03-06 04:24:03 -05:00
|
|
|
name: I18n.t('groups.default_names.staff').upcase
|
2017-01-17 23:20:23 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
group = Group.refresh_automatic_group!(:staff)
|
|
|
|
|
|
|
|
expect(group.name).to eq('staff')
|
|
|
|
ensure
|
|
|
|
I18n.locale = SiteSetting.default_locale = default_locale
|
|
|
|
end
|
|
|
|
end
|
2016-10-23 22:03:22 -04:00
|
|
|
end
|
|
|
|
|
2015-04-09 22:17:28 -04:00
|
|
|
it "Correctly handles removal of primary group" do
|
2015-02-09 00:03:09 -05:00
|
|
|
group = Fabricate(:group)
|
|
|
|
user = Fabricate(:user)
|
|
|
|
group.add(user)
|
|
|
|
group.save
|
|
|
|
|
|
|
|
user.primary_group = group
|
|
|
|
user.save
|
|
|
|
|
|
|
|
group.reload
|
|
|
|
|
|
|
|
group.remove(user)
|
|
|
|
group.save
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
expect(user.primary_group).to eq nil
|
|
|
|
end
|
|
|
|
|
2013-05-06 00:49:56 -04:00
|
|
|
it "Can update moderator/staff/admin groups correctly" do
|
2013-05-09 03:37:34 -04:00
|
|
|
|
2013-05-06 00:49:56 -04:00
|
|
|
admin = Fabricate(:admin)
|
|
|
|
moderator = Fabricate(:moderator)
|
|
|
|
|
|
|
|
Group.refresh_automatic_groups!(:admins, :staff, :moderators)
|
|
|
|
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(real_admins).to eq [admin.id]
|
|
|
|
expect(real_moderators).to eq [moderator.id]
|
|
|
|
expect(real_staff.sort).to eq [moderator.id,admin.id].sort
|
2013-05-06 00:49:56 -04:00
|
|
|
|
|
|
|
admin.admin = false
|
|
|
|
admin.save
|
|
|
|
|
|
|
|
Group.refresh_automatic_group!(:admins)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(real_admins).to be_empty
|
2013-05-06 00:49:56 -04:00
|
|
|
|
|
|
|
moderator.revoke_moderation!
|
|
|
|
|
|
|
|
admin.grant_admin!
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(real_admins).to eq [admin.id]
|
|
|
|
expect(real_staff).to eq [admin.id]
|
2013-05-06 00:49:56 -04:00
|
|
|
|
|
|
|
admin.revoke_admin!
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(real_admins).to be_empty
|
|
|
|
expect(real_staff).to be_empty
|
2013-05-06 00:49:56 -04:00
|
|
|
|
|
|
|
admin.grant_moderation!
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(real_moderators).to eq [admin.id]
|
|
|
|
expect(real_staff).to eq [admin.id]
|
2013-05-06 00:49:56 -04:00
|
|
|
|
|
|
|
admin.revoke_moderation!
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(real_admins).to be_empty
|
|
|
|
expect(real_staff).to eq []
|
2013-05-06 00:49:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "Correctly updates automatic trust level groups" do
|
|
|
|
user = Fabricate(:user)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(Group[:trust_level_0].user_ids).to include user.id
|
2014-06-16 20:46:30 -04:00
|
|
|
|
2014-09-05 01:20:39 -04:00
|
|
|
user.change_trust_level!(TrustLevel[1])
|
2013-05-06 00:49:56 -04:00
|
|
|
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(Group[:trust_level_1].user_ids).to include user.id
|
2013-05-06 00:49:56 -04:00
|
|
|
|
2014-09-05 01:20:39 -04:00
|
|
|
user.change_trust_level!(TrustLevel[2])
|
2013-05-06 00:49:56 -04:00
|
|
|
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(Group[:trust_level_1].user_ids).to include user.id
|
|
|
|
expect(Group[:trust_level_2].user_ids).to include user.id
|
2013-05-07 20:32:29 -04:00
|
|
|
|
|
|
|
user2 = Fabricate(:coding_horror)
|
2014-09-05 01:20:39 -04:00
|
|
|
user2.change_trust_level!(TrustLevel[3])
|
2013-05-07 20:32:29 -04:00
|
|
|
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(Group[:trust_level_2].user_ids.sort).to eq [-1, user.id, user2.id].sort
|
2013-05-06 00:49:56 -04:00
|
|
|
end
|
|
|
|
|
2013-05-08 01:20:38 -04:00
|
|
|
it "Correctly updates all automatic groups upon request" do
|
2013-06-25 10:15:41 -04:00
|
|
|
Fabricate(:admin)
|
2013-05-08 01:20:38 -04:00
|
|
|
user = Fabricate(:user)
|
2014-09-05 01:20:39 -04:00
|
|
|
user.change_trust_level!(TrustLevel[2])
|
2013-05-08 01:20:38 -04:00
|
|
|
|
|
|
|
Group.exec_sql("update groups set user_count=0 where id = #{Group::AUTO_GROUPS[:trust_level_2]}")
|
|
|
|
|
|
|
|
Group.refresh_automatic_groups!
|
|
|
|
|
|
|
|
groups = Group.includes(:users).to_a
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(groups.count).to eq Group::AUTO_GROUPS.count
|
2013-05-08 01:20:38 -04:00
|
|
|
|
2016-04-08 12:11:58 -04:00
|
|
|
g = groups.find{|grp| grp.id == Group::AUTO_GROUPS[:admins]}
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(g.users.count).to eq 2
|
|
|
|
expect(g.user_count).to eq 2
|
2013-05-08 01:20:38 -04:00
|
|
|
|
2016-04-08 12:11:58 -04:00
|
|
|
g = groups.find{|grp| grp.id == Group::AUTO_GROUPS[:staff]}
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(g.users.count).to eq 2
|
|
|
|
expect(g.user_count).to eq 2
|
2014-06-16 20:46:30 -04:00
|
|
|
|
2016-04-08 12:11:58 -04:00
|
|
|
g = groups.find{|grp| grp.id == Group::AUTO_GROUPS[:trust_level_1]}
|
2014-06-16 20:46:30 -04:00
|
|
|
# admin, system and user
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(g.users.count).to eq 3
|
|
|
|
expect(g.user_count).to eq 3
|
2014-06-16 20:46:30 -04:00
|
|
|
|
2016-04-08 12:11:58 -04:00
|
|
|
g = groups.find{|grp| grp.id == Group::AUTO_GROUPS[:trust_level_2]}
|
2014-06-16 20:46:30 -04:00
|
|
|
# system and user
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(g.users.count).to eq 2
|
|
|
|
expect(g.user_count).to eq 2
|
2013-05-08 01:20:38 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-05-08 21:33:56 -04:00
|
|
|
it "can set members via usernames helper" do
|
|
|
|
g = Fabricate(:group)
|
|
|
|
u1 = Fabricate(:user)
|
|
|
|
u2 = Fabricate(:user)
|
|
|
|
u3 = Fabricate(:user)
|
|
|
|
|
|
|
|
g.add(u1)
|
|
|
|
g.save!
|
|
|
|
|
|
|
|
usernames = "#{u2.username},#{u3.username}"
|
|
|
|
|
|
|
|
# no side effects please
|
|
|
|
g.usernames = usernames
|
|
|
|
g.reload
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(g.users.count).to eq 1
|
2013-05-08 21:33:56 -04:00
|
|
|
|
|
|
|
g.usernames = usernames
|
|
|
|
g.save!
|
|
|
|
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(g.usernames.split(",").sort).to eq usernames.split(",").sort
|
2013-05-08 21:33:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "correctly destroys groups" do
|
2013-11-18 10:52:01 -05:00
|
|
|
|
2013-05-08 21:33:56 -04:00
|
|
|
g = Fabricate(:group)
|
|
|
|
u1 = Fabricate(:user)
|
|
|
|
g.add(u1)
|
|
|
|
g.save!
|
|
|
|
|
|
|
|
g.destroy
|
|
|
|
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(User.where(id: u1.id).count).to eq 1
|
|
|
|
expect(GroupUser.where(group_id: g.id).count).to eq 0
|
2013-05-08 21:33:56 -04:00
|
|
|
end
|
|
|
|
|
2014-04-25 09:14:05 -04:00
|
|
|
|
|
|
|
it "has custom fields" do
|
|
|
|
group = Fabricate(:group)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(group.custom_fields["a"]).to be_nil
|
2014-04-25 09:14:05 -04:00
|
|
|
|
|
|
|
group.custom_fields["hugh"] = "jackman"
|
|
|
|
group.custom_fields["jack"] = "black"
|
|
|
|
group.save
|
|
|
|
|
|
|
|
group = Group.find(group.id)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(group.custom_fields).to eq({"hugh" => "jackman", "jack" => "black"})
|
2014-04-25 09:14:05 -04:00
|
|
|
end
|
|
|
|
|
2013-07-22 20:10:36 -04:00
|
|
|
it "allows you to lookup a new group by name" do
|
|
|
|
group = Fabricate(:group)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(group.id).to eq Group[group.name].id
|
|
|
|
expect(group.id).to eq Group[group.name.to_sym].id
|
2013-07-22 20:10:36 -04:00
|
|
|
end
|
|
|
|
|
2014-06-16 20:46:30 -04:00
|
|
|
it "can find desired groups correctly" do
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(Group.desired_trust_level_groups(2).sort).to eq [10,11,12]
|
2014-06-16 20:46:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "correctly handles trust level changes" do
|
|
|
|
user = Fabricate(:user, trust_level: 2)
|
|
|
|
Group.user_trust_level_change!(user.id, 2)
|
|
|
|
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(user.groups.map(&:name).sort).to eq ["trust_level_0","trust_level_1", "trust_level_2"]
|
2014-06-16 20:46:30 -04:00
|
|
|
|
|
|
|
Group.user_trust_level_change!(user.id, 0)
|
|
|
|
user.reload
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(user.groups.map(&:name).sort).to eq ["trust_level_0"]
|
2014-06-16 20:46:30 -04:00
|
|
|
end
|
|
|
|
|
2015-01-08 18:35:52 -05:00
|
|
|
context "group management" do
|
|
|
|
let(:group) {Fabricate(:group)}
|
|
|
|
|
|
|
|
it "by default has no managers" do
|
2015-11-09 08:55:16 -05:00
|
|
|
expect(group.group_users.where('group_users.owner')).to be_empty
|
2015-01-08 18:35:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "multiple managers can be appointed" do
|
|
|
|
2.times do |i|
|
|
|
|
u = Fabricate(:user)
|
2015-11-09 08:55:16 -05:00
|
|
|
group.add_owner(u)
|
2015-01-08 18:35:52 -05:00
|
|
|
end
|
2015-11-09 08:55:16 -05:00
|
|
|
expect(group.group_users.where('group_users.owner').count).to eq(2)
|
2015-01-08 18:35:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "manager has authority to edit membership" do
|
|
|
|
u = Fabricate(:user)
|
|
|
|
expect(Guardian.new(u).can_edit?(group)).to be_falsy
|
2015-11-09 08:55:16 -05:00
|
|
|
group.add_owner(u)
|
2015-01-08 18:35:52 -05:00
|
|
|
expect(Guardian.new(u).can_edit?(group)).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-01 16:52:05 -04:00
|
|
|
it "correctly grants a trust level to members" do
|
|
|
|
group = Fabricate(:group, grant_trust_level: 2)
|
|
|
|
u0 = Fabricate(:user, trust_level: 0)
|
|
|
|
u3 = Fabricate(:user, trust_level: 3)
|
|
|
|
|
|
|
|
group.add(u0)
|
|
|
|
expect(u0.reload.trust_level).to eq(2)
|
|
|
|
|
|
|
|
group.add(u3)
|
|
|
|
expect(u3.reload.trust_level).to eq(3)
|
|
|
|
end
|
|
|
|
|
2016-12-05 03:18:24 -05:00
|
|
|
it 'should cook the bio' do
|
|
|
|
group = Fabricate(:group)
|
|
|
|
group.update_attributes!(bio_raw: 'This is a group for :unicorn: lovers')
|
|
|
|
|
|
|
|
expect(group.bio_cooked).to include("unicorn.png")
|
|
|
|
end
|
|
|
|
|
2017-02-03 03:51:32 -05:00
|
|
|
describe ".visible_groups" do
|
|
|
|
|
2017-07-03 15:26:46 -04:00
|
|
|
def can_view?(user, group)
|
|
|
|
Group.visible_groups(user).where(id: group.id).exists?
|
2017-02-03 03:51:32 -05:00
|
|
|
end
|
|
|
|
|
2017-07-03 15:26:46 -04:00
|
|
|
it 'correctly restricts group visibility' do
|
|
|
|
group = Fabricate.build(:group, visibility_level: Group.visibility_levels[:owners])
|
|
|
|
member = Fabricate(:user)
|
|
|
|
group.add(member)
|
|
|
|
group.save!
|
2017-02-03 03:51:32 -05:00
|
|
|
|
2017-07-03 15:26:46 -04:00
|
|
|
owner = Fabricate(:user)
|
|
|
|
group.add_owner(owner)
|
2017-02-03 03:51:32 -05:00
|
|
|
|
2017-07-03 15:26:46 -04:00
|
|
|
moderator = Fabricate(:user, moderator: true)
|
|
|
|
admin = Fabricate(:user, admin: true)
|
2017-02-03 03:51:32 -05:00
|
|
|
|
2017-07-03 15:26:46 -04:00
|
|
|
expect(can_view?(admin, group)).to eq(true)
|
|
|
|
expect(can_view?(owner, group)).to eq(true)
|
|
|
|
expect(can_view?(moderator, group)).to eq(false)
|
|
|
|
expect(can_view?(member, group)).to eq(false)
|
|
|
|
expect(can_view?(nil, group)).to eq(false)
|
2017-02-03 03:51:32 -05:00
|
|
|
|
2017-07-03 15:26:46 -04:00
|
|
|
group.update_columns(visibility_level: Group.visibility_levels[:staff])
|
|
|
|
|
|
|
|
expect(can_view?(admin, group)).to eq(true)
|
|
|
|
expect(can_view?(owner, group)).to eq(true)
|
|
|
|
expect(can_view?(moderator, group)).to eq(true)
|
|
|
|
expect(can_view?(member, group)).to eq(false)
|
|
|
|
expect(can_view?(nil, group)).to eq(false)
|
|
|
|
|
|
|
|
group.update_columns(visibility_level: Group.visibility_levels[:members])
|
|
|
|
|
|
|
|
expect(can_view?(admin, group)).to eq(true)
|
|
|
|
expect(can_view?(owner, group)).to eq(true)
|
|
|
|
expect(can_view?(moderator, group)).to eq(false)
|
|
|
|
expect(can_view?(member, group)).to eq(true)
|
|
|
|
expect(can_view?(nil, group)).to eq(false)
|
|
|
|
|
|
|
|
group.update_columns(visibility_level: Group.visibility_levels[:public])
|
|
|
|
|
|
|
|
expect(can_view?(admin, group)).to eq(true)
|
|
|
|
expect(can_view?(owner, group)).to eq(true)
|
|
|
|
expect(can_view?(moderator, group)).to eq(true)
|
|
|
|
expect(can_view?(member, group)).to eq(true)
|
|
|
|
expect(can_view?(nil, group)).to eq(true)
|
2017-02-03 03:51:32 -05:00
|
|
|
end
|
2017-07-03 15:26:46 -04:00
|
|
|
|
2017-02-03 03:51:32 -05:00
|
|
|
end
|
2017-06-02 04:38:14 -04:00
|
|
|
|
|
|
|
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
|
2017-06-29 03:36:51 -04:00
|
|
|
|
|
|
|
describe '.search_group' do
|
|
|
|
let(:group) { Fabricate(:group, name: 'tEsT', full_name: 'eSTt') }
|
|
|
|
|
|
|
|
it 'should return the right groups' do
|
|
|
|
group
|
|
|
|
|
|
|
|
expect(Group.search_group('te')).to eq([group])
|
|
|
|
expect(Group.search_group('TE')).to eq([group])
|
|
|
|
expect(Group.search_group('es')).to eq([group])
|
|
|
|
expect(Group.search_group('ES')).to eq([group])
|
|
|
|
expect(Group.search_group('test2')).to eq([])
|
|
|
|
end
|
|
|
|
end
|
2013-04-29 02:33:24 -04:00
|
|
|
end
|