2011-12-07 19:51:08 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-02-19 01:12:08 +00:00
|
|
|
describe Groups::MembersController, type: :controller do
|
2011-12-09 23:40:13 +00:00
|
|
|
before(:each) do
|
2012-05-16 16:29:28 +01:00
|
|
|
stub_symlink_methods
|
2012-03-29 21:34:22 +01:00
|
|
|
@group = FactoryGirl.create(:group)
|
2011-12-09 23:40:13 +00:00
|
|
|
@user = @group.owner
|
2011-12-14 20:49:33 +00:00
|
|
|
set_session_for @user
|
2012-03-29 21:34:22 +01:00
|
|
|
@another_user = FactoryGirl.create(:user)
|
2014-11-24 21:29:21 +00:00
|
|
|
@add_params = {group_id: @group, member_id: @another_user.id}
|
|
|
|
@remove_params = {group_id: @group, members: [@group.owner.id]}
|
|
|
|
@update_params = {group_id: @group, member_id: @group.owner.id, role: :reader}
|
2011-12-09 23:40:13 +00:00
|
|
|
end
|
2011-12-07 19:51:08 +00:00
|
|
|
|
2011-12-09 23:40:13 +00:00
|
|
|
context 'for owner user' do
|
|
|
|
it 'should add member to group' do
|
|
|
|
post :add, @add_params
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(group_members_path(@group))
|
|
|
|
expect(Relation.by_target(@group).by_actor(@another_user).count).to eq 1
|
2011-12-09 23:40:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should add reader member to group' do
|
|
|
|
post :add, @add_params
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(Relation.by_target(@group).by_actor(@another_user).first.role).to eq 'reader'
|
|
|
|
expect(response).to redirect_to(group_members_path(@group))
|
2012-05-03 13:23:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not remove self from group' do
|
|
|
|
post :remove, @remove_params
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(Relation.by_target(@group).by_actor(@user).first.role).to eq 'admin'
|
|
|
|
expect(response).to redirect_to(group_members_path(@group))
|
2012-05-03 13:23:19 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for admin user' do
|
|
|
|
before(:each) do
|
|
|
|
@admin_user = FactoryGirl.create(:user)
|
2014-03-18 09:31:01 +00:00
|
|
|
create_actor_relation(@group, @admin_user, 'admin')
|
2012-05-03 13:23:19 +01:00
|
|
|
set_session_for @admin_user
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should add member to group' do
|
|
|
|
post :add, @add_params
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(Relation.by_target(@group).by_actor(@another_user).count).to eq 1
|
|
|
|
expect(response).to redirect_to(group_members_path(@group))
|
2012-05-03 13:23:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should add reader member to group' do
|
|
|
|
post :add, @add_params
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(Relation.by_target(@group).by_actor(@another_user).first.role).to eq 'reader'
|
|
|
|
expect(response).to redirect_to(group_members_path(@group))
|
2012-05-03 13:23:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not remove owner from group' do
|
|
|
|
post :remove, @remove_params
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(Relation.by_target(@group).by_actor(@user).first.role).to eq 'admin'
|
|
|
|
expect(response).to redirect_to(group_members_path(@group))
|
2012-05-03 13:23:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not set read role to owner group' do
|
|
|
|
post :update, @update_params
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(Relation.by_target(@group).by_actor(@user).first.role).to eq 'admin'
|
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2012-05-03 13:23:19 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for writer user' do
|
|
|
|
before(:each) do
|
|
|
|
@writer_user = FactoryGirl.create(:user)
|
2014-03-18 09:31:01 +00:00
|
|
|
create_actor_relation(@group, @writer_user, 'writer')
|
2012-05-03 13:23:19 +01:00
|
|
|
set_session_for @writer_user
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not add member to group' do
|
|
|
|
post :add, @add_params
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2012-05-03 13:23:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should add reader member to group' do
|
|
|
|
post :add, @add_params
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2012-05-03 13:23:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not remove owner from group' do
|
|
|
|
post :remove, @remove_params
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2012-05-03 13:23:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not set read role to owner group' do
|
|
|
|
post :update, @update_params
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2012-05-03 13:23:19 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for another user' do
|
|
|
|
before(:each) do
|
|
|
|
set_session_for @another_user
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not add member to group' do
|
|
|
|
post :add, @add_params
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2012-05-03 13:23:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should add reader member to group' do
|
|
|
|
post :add, @add_params
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2012-05-03 13:23:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not remove owner from group' do
|
|
|
|
post :remove, @remove_params
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2012-05-03 13:23:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not set read role to owner group' do
|
|
|
|
post :update, @update_params
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2011-12-09 23:40:13 +00:00
|
|
|
end
|
|
|
|
end
|
2011-12-07 19:51:08 +00:00
|
|
|
end
|