2017-07-27 02:39:47 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-08-23 23:01:11 -04:00
|
|
|
RSpec.describe Admin::GroupsController do
|
2017-07-27 02:39:47 -04:00
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
let(:user) { Fabricate(:user) }
|
2017-08-02 07:58:35 -04:00
|
|
|
let(:group) { Fabricate(:group) }
|
2017-07-27 02:39:47 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
2017-08-24 02:28:18 -04:00
|
|
|
describe '#create' do
|
2017-07-27 02:39:47 -04:00
|
|
|
it 'should work' do
|
2017-08-31 00:06:56 -04:00
|
|
|
post "/admin/groups.json", params: {
|
|
|
|
group: {
|
|
|
|
name: 'testing',
|
|
|
|
usernames: [admin.username, user.username].join(","),
|
|
|
|
owner_usernames: [user.username].join(","),
|
|
|
|
allow_membership_requests: true,
|
|
|
|
membership_request_template: 'Testing',
|
|
|
|
}
|
2017-07-27 02:39:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
|
|
|
|
group = Group.last
|
|
|
|
|
|
|
|
expect(group.name).to eq('testing')
|
|
|
|
expect(group.users).to contain_exactly(admin, user)
|
|
|
|
expect(group.allow_membership_requests).to eq(true)
|
2017-08-08 05:53:02 -04:00
|
|
|
expect(group.membership_request_template).to eq('Testing')
|
2017-07-27 02:39:47 -04:00
|
|
|
end
|
|
|
|
end
|
2017-08-02 07:58:35 -04:00
|
|
|
|
2017-08-23 23:01:11 -04:00
|
|
|
describe '#add_owners' do
|
2017-08-02 07:58:35 -04:00
|
|
|
it 'should work' do
|
2017-08-31 00:06:56 -04:00
|
|
|
put "/admin/groups/#{group.id}/owners.json", params: {
|
|
|
|
group: {
|
|
|
|
usernames: [user.username, admin.username].join(",")
|
|
|
|
}
|
2017-08-02 07:58:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
|
|
|
|
expect(group.group_users.where(owner: true).map(&:user))
|
|
|
|
.to contain_exactly(user, admin)
|
|
|
|
end
|
|
|
|
end
|
2017-07-27 02:39:47 -04:00
|
|
|
end
|