2017-07-27 14:39:47 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-08-24 11:01:11 +08:00
|
|
|
RSpec.describe Admin::GroupsController do
|
2017-07-27 14:39:47 +08:00
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
let(:user) { Fabricate(:user) }
|
2017-08-02 19:58:35 +08:00
|
|
|
let(:group) { Fabricate(:group) }
|
2017-07-27 14:39:47 +08:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
2017-08-24 14:28:18 +08:00
|
|
|
describe '#create' do
|
2017-07-27 14:39:47 +08:00
|
|
|
it 'should work' do
|
2017-08-31 12:06:56 +08: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 14:39:47 +08: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 17:53:02 +08:00
|
|
|
expect(group.membership_request_template).to eq('Testing')
|
2017-07-27 14:39:47 +08:00
|
|
|
end
|
|
|
|
end
|
2017-08-02 19:58:35 +08:00
|
|
|
|
2017-08-24 11:01:11 +08:00
|
|
|
describe '#add_owners' do
|
2017-08-02 19:58:35 +08:00
|
|
|
it 'should work' do
|
2017-08-31 12:06:56 +08:00
|
|
|
put "/admin/groups/#{group.id}/owners.json", params: {
|
|
|
|
group: {
|
|
|
|
usernames: [user.username, admin.username].join(",")
|
|
|
|
}
|
2017-08-02 19:58:35 +08: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 14:39:47 +08:00
|
|
|
end
|