2011-12-07 19:51:08 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2012-10-02 16:32:13 +01:00
|
|
|
shared_examples_for 'group user with project show rights' do
|
2012-10-02 13:14:43 +01:00
|
|
|
it 'should be able to perform show action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :show, uname: @group.uname
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to render_template(:show)
|
2012-10-02 13:14:43 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-20 15:40:49 +00:00
|
|
|
shared_examples_for 'group user without update rights' do
|
|
|
|
it 'should be not able to perform update action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, {id: @group}.merge(@update_params)
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
|
|
|
expect(@group.reload.description).to_not eq 'grp2'
|
2012-03-20 15:40:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'group user without destroy rights' do
|
|
|
|
it 'should not be able to destroy group' do
|
2014-01-21 04:51:49 +00:00
|
|
|
delete :destroy, id: @group
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2012-03-20 15:40:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not change groups count after destroy action' do
|
2015-04-02 22:27:27 +01:00
|
|
|
expect do
|
|
|
|
delete :destroy, id: @group
|
|
|
|
end.to_not change(Group, :count)
|
2012-03-20 15:40:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'group admin' do
|
|
|
|
it_should_behave_like 'no group user'
|
|
|
|
|
|
|
|
it 'should be able to perform update action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, {id: @group}.merge(@update_params)
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(group_path(@group))
|
|
|
|
expect(@group.reload.description).to eq 'grp2'
|
2012-03-20 15:40:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'no group user' do
|
|
|
|
it 'should be able to perform create action' do
|
|
|
|
post :create, @create_params
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(group_path(Group.last))
|
2012-03-20 15:40:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should change objects count on create' do
|
2015-04-02 22:27:27 +01:00
|
|
|
expect do
|
|
|
|
post :create, @create_params
|
|
|
|
end.to change(Group, :count).by(1)
|
2012-03-20 15:40:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'group owner' do
|
|
|
|
it_should_behave_like 'group admin'
|
|
|
|
|
|
|
|
it 'should be able to destroy group' do
|
2014-01-21 04:51:49 +00:00
|
|
|
delete :destroy, id: @group
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(groups_path)
|
2012-03-20 15:40:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should change groups count after destroy action' do
|
2015-04-02 22:27:27 +01:00
|
|
|
expect do
|
|
|
|
delete :destroy, id: @group
|
|
|
|
end.to change(Group, :count).by(-1)
|
2012-03-20 15:40:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-19 01:12:08 +00:00
|
|
|
describe Groups::ProfileController, type: :controller do
|
2011-12-07 19:51:08 +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)
|
|
|
|
@another_user = FactoryGirl.create(:user)
|
2014-01-21 04:51:49 +00:00
|
|
|
@create_params = {group: {description: 'grp1', uname: 'un_grp1'}}
|
|
|
|
@update_params = {group: {description: 'grp2'}}
|
2011-12-07 19:51:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for guest' do
|
2012-10-02 16:32:13 +01:00
|
|
|
|
|
|
|
if APP_CONFIG['anonymous_access']
|
|
|
|
it_should_behave_like 'group user with project show rights'
|
|
|
|
else
|
|
|
|
it 'should not be able to perform show action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :show, id: @group
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
2012-10-02 16:32:13 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-07 19:51:08 +00:00
|
|
|
it 'should not be able to perform index action' do
|
|
|
|
get :index
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
2011-12-07 19:51:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform update action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, {id: @group}.merge(@update_params)
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
2011-12-07 19:51:08 +00:00
|
|
|
end
|
2012-03-21 13:52:35 +00:00
|
|
|
|
|
|
|
it 'should not be able to perform create action' do
|
|
|
|
post :create, @create_params
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
2012-03-21 13:52:35 +00:00
|
|
|
end
|
2011-12-07 19:51:08 +00:00
|
|
|
end
|
|
|
|
|
2012-03-20 15:40:49 +00:00
|
|
|
context 'for global admin' do
|
2011-12-07 19:51:08 +00:00
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@admin = FactoryGirl.create(:admin)
|
2011-12-07 19:51:08 +00:00
|
|
|
set_session_for(@admin)
|
|
|
|
end
|
|
|
|
|
2012-10-02 16:32:13 +01:00
|
|
|
it_should_behave_like 'group user with project show rights'
|
2011-12-07 19:51:08 +00:00
|
|
|
it_should_behave_like 'update_member_relation'
|
2012-03-20 15:40:49 +00:00
|
|
|
it_should_behave_like 'group owner'
|
2011-12-07 19:51:08 +00:00
|
|
|
|
2011-12-15 09:38:40 +00:00
|
|
|
it 'should be able to perform index action' do
|
|
|
|
get :index
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to render_template(:index)
|
2011-12-15 09:38:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform update action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, {id: @group}.merge(@update_params)
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(group_path(@group))
|
2011-12-15 09:38:40 +00:00
|
|
|
end
|
2012-03-20 15:40:49 +00:00
|
|
|
end
|
2011-12-15 09:38:40 +00:00
|
|
|
|
2012-03-20 15:40:49 +00:00
|
|
|
context 'for group admin' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
2012-03-20 15:40:49 +00:00
|
|
|
set_session_for(@user)
|
2014-03-18 09:31:01 +00:00
|
|
|
create_actor_relation(@group, @user, 'admin')
|
2011-12-07 19:51:08 +00:00
|
|
|
end
|
|
|
|
|
2012-10-02 16:32:13 +01:00
|
|
|
it_should_behave_like 'group user with project show rights'
|
2012-03-20 15:40:49 +00:00
|
|
|
it_should_behave_like 'update_member_relation'
|
|
|
|
it_should_behave_like 'group admin'
|
|
|
|
it_should_behave_like 'group user without destroy rights'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for group owner' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
2012-03-20 15:40:49 +00:00
|
|
|
set_session_for(@user)
|
2012-09-06 11:53:03 +01:00
|
|
|
@group.owner = @user
|
|
|
|
@group.save
|
2014-03-18 09:31:01 +00:00
|
|
|
create_actor_relation(@group, @user, 'admin')
|
2011-12-07 19:51:08 +00:00
|
|
|
end
|
2012-03-20 15:40:49 +00:00
|
|
|
|
2012-10-02 16:32:13 +01:00
|
|
|
it_should_behave_like 'group user with project show rights'
|
2012-03-20 15:40:49 +00:00
|
|
|
it_should_behave_like 'update_member_relation'
|
|
|
|
it_should_behave_like 'group owner'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for group reader and writer user' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
2012-03-20 15:40:49 +00:00
|
|
|
set_session_for(@user)
|
2014-03-18 09:31:01 +00:00
|
|
|
create_actor_relation(@group, @user, 'reader')
|
2012-03-20 15:40:49 +00:00
|
|
|
end
|
|
|
|
|
2012-07-27 14:17:37 +01:00
|
|
|
it "should remove user from groups" do
|
2014-01-21 04:51:49 +00:00
|
|
|
delete :remove_user, id: @group
|
2015-04-02 22:27:27 +01:00
|
|
|
expect(response).to redirect_to(groups_path)
|
2012-07-27 14:17:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should change relations count" do
|
2015-04-02 22:27:27 +01:00
|
|
|
expect do
|
|
|
|
delete :remove_user, id: @group
|
|
|
|
end.to change(Relation, :count).by(-1)
|
2012-07-27 14:17:37 +01:00
|
|
|
end
|
|
|
|
|
2012-10-02 16:32:13 +01:00
|
|
|
it_should_behave_like 'group user with project show rights'
|
2012-03-20 15:40:49 +00:00
|
|
|
it_should_behave_like 'no group user'
|
|
|
|
it_should_behave_like 'group user without destroy rights'
|
|
|
|
it_should_behave_like 'group user without update rights'
|
2011-12-07 19:51:08 +00:00
|
|
|
end
|
|
|
|
end
|