#465: Update specs for Groups::*Controller
This commit is contained in:
parent
69690024af
commit
60a97a44e2
|
@ -11,6 +11,7 @@ class Groups::ProfileController < Groups::BaseController
|
|||
end
|
||||
|
||||
def show
|
||||
authorize @group
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
@members = @group.members.order(:uname)
|
||||
|
|
|
@ -33,4 +33,3 @@ hr
|
|||
p
|
||||
=> image_tag avatar_url(member, :micro), alt: member.uname, height: size, width: size
|
||||
= link_to member.uname.truncate(20), member
|
||||
|
||||
|
|
|
@ -15,20 +15,20 @@ describe Groups::MembersController, type: :controller do
|
|||
context 'for owner user' do
|
||||
it 'should add member to group' do
|
||||
post :add, @add_params
|
||||
response.should redirect_to(group_members_path(@group))
|
||||
Relation.by_target(@group).by_actor(@another_user).count.should eql(1)
|
||||
expect(response).to redirect_to(group_members_path(@group))
|
||||
expect(Relation.by_target(@group).by_actor(@another_user).count).to eq 1
|
||||
end
|
||||
|
||||
it 'should add reader member to group' do
|
||||
post :add, @add_params
|
||||
Relation.by_target(@group).by_actor(@another_user).first.role.should eql('reader')
|
||||
response.should redirect_to(group_members_path(@group))
|
||||
expect(Relation.by_target(@group).by_actor(@another_user).first.role).to eq 'reader'
|
||||
expect(response).to redirect_to(group_members_path(@group))
|
||||
end
|
||||
|
||||
it 'should not remove self from group' do
|
||||
post :remove, @remove_params
|
||||
Relation.by_target(@group).by_actor(@user).first.role.should eql('admin')
|
||||
response.should redirect_to(group_members_path(@group))
|
||||
expect(Relation.by_target(@group).by_actor(@user).first.role).to eq 'admin'
|
||||
expect(response).to redirect_to(group_members_path(@group))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -41,27 +41,26 @@ describe Groups::MembersController, type: :controller do
|
|||
|
||||
it 'should add member to group' do
|
||||
post :add, @add_params
|
||||
response.should redirect_to(group_members_path(@group))
|
||||
Relation.by_target(@group).by_actor(@another_user).count.should eql(1)
|
||||
response.should redirect_to(group_members_path(@group))
|
||||
expect(Relation.by_target(@group).by_actor(@another_user).count).to eq 1
|
||||
expect(response).to redirect_to(group_members_path(@group))
|
||||
end
|
||||
|
||||
it 'should add reader member to group' do
|
||||
post :add, @add_params
|
||||
Relation.by_target(@group).by_actor(@another_user).first.role.should eql('reader')
|
||||
response.should redirect_to(group_members_path(@group))
|
||||
expect(Relation.by_target(@group).by_actor(@another_user).first.role).to eq 'reader'
|
||||
expect(response).to redirect_to(group_members_path(@group))
|
||||
end
|
||||
|
||||
it 'should not remove owner from group' do
|
||||
post :remove, @remove_params
|
||||
Relation.by_target(@group).by_actor(@user).first.role.should eql('admin')
|
||||
response.should redirect_to(group_members_path(@group))
|
||||
expect(Relation.by_target(@group).by_actor(@user).first.role).to eq 'admin'
|
||||
expect(response).to redirect_to(group_members_path(@group))
|
||||
end
|
||||
|
||||
it 'should not set read role to owner group' do
|
||||
post :update, @update_params
|
||||
Relation.by_target(@group).by_actor(@user).first.role.should eql('admin')
|
||||
response.should redirect_to(forbidden_path)
|
||||
expect(Relation.by_target(@group).by_actor(@user).first.role).to eq 'admin'
|
||||
expect(response).to redirect_to(forbidden_path)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -74,22 +73,22 @@ describe Groups::MembersController, type: :controller do
|
|||
|
||||
it 'should not add member to group' do
|
||||
post :add, @add_params
|
||||
response.should redirect_to(forbidden_path)
|
||||
expect(response).to redirect_to(forbidden_path)
|
||||
end
|
||||
|
||||
it 'should add reader member to group' do
|
||||
post :add, @add_params
|
||||
response.should redirect_to(forbidden_path)
|
||||
expect(response).to redirect_to(forbidden_path)
|
||||
end
|
||||
|
||||
it 'should not remove owner from group' do
|
||||
post :remove, @remove_params
|
||||
response.should redirect_to(forbidden_path)
|
||||
expect(response).to redirect_to(forbidden_path)
|
||||
end
|
||||
|
||||
it 'should not set read role to owner group' do
|
||||
post :update, @update_params
|
||||
response.should redirect_to(forbidden_path)
|
||||
expect(response).to redirect_to(forbidden_path)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -100,22 +99,22 @@ describe Groups::MembersController, type: :controller do
|
|||
|
||||
it 'should not add member to group' do
|
||||
post :add, @add_params
|
||||
response.should redirect_to(forbidden_path)
|
||||
expect(response).to redirect_to(forbidden_path)
|
||||
end
|
||||
|
||||
it 'should add reader member to group' do
|
||||
post :add, @add_params
|
||||
response.should redirect_to(forbidden_path)
|
||||
expect(response).to redirect_to(forbidden_path)
|
||||
end
|
||||
|
||||
it 'should not remove owner from group' do
|
||||
post :remove, @remove_params
|
||||
response.should redirect_to(forbidden_path)
|
||||
expect(response).to redirect_to(forbidden_path)
|
||||
end
|
||||
|
||||
it 'should not set read role to owner group' do
|
||||
post :update, @update_params
|
||||
response.should redirect_to(forbidden_path)
|
||||
expect(response).to redirect_to(forbidden_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,55 +3,51 @@ require 'spec_helper'
|
|||
shared_examples_for 'group user with project show rights' do
|
||||
it 'should be able to perform show action' do
|
||||
get :show, uname: @group.uname
|
||||
response.should render_template(:show)
|
||||
expect(response).to render_template(:show)
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for 'group user without update rights' do
|
||||
it 'should be not able to perform update action' do
|
||||
put :update, {id: @group}.merge(@update_params)
|
||||
response.should redirect_to(forbidden_path)
|
||||
end
|
||||
|
||||
it 'should not be able to update group data' do
|
||||
put :update, id: @group, group: {description: 'new description'}
|
||||
@group.reload.description.should_not == 'new description'
|
||||
expect(response).to redirect_to(forbidden_path)
|
||||
expect(@group.reload.description).to_not eq 'grp2'
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for 'group user without destroy rights' do
|
||||
it 'should not be able to destroy group' do
|
||||
delete :destroy, id: @group
|
||||
response.should redirect_to(forbidden_path)
|
||||
expect(response).to redirect_to(forbidden_path)
|
||||
end
|
||||
|
||||
it 'should not change groups count after destroy action' do
|
||||
lambda { delete :destroy, id: @group }.should change{ Group.count }.by(0)
|
||||
expect do
|
||||
delete :destroy, id: @group
|
||||
end.to_not change(Group, :count)
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for 'group admin' do
|
||||
it_should_behave_like 'no group user'
|
||||
|
||||
it 'should be able to update group data' do
|
||||
put :update, id: @group, group: {description: 'new description'}
|
||||
@group.reload.description.should == 'new description'
|
||||
end
|
||||
|
||||
it 'should be able to perform update action' do
|
||||
put :update, {id: @group}.merge(@update_params)
|
||||
response.should redirect_to(group_path(@group))
|
||||
expect(response).to redirect_to(group_path(@group))
|
||||
expect(@group.reload.description).to eq 'grp2'
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for 'no group user' do
|
||||
it 'should be able to perform create action' do
|
||||
post :create, @create_params
|
||||
response.should redirect_to(group_path(Group.last))
|
||||
expect(response).to redirect_to(group_path(Group.last))
|
||||
end
|
||||
|
||||
it 'should change objects count on create' do
|
||||
lambda { post :create, @create_params }.should change{ Group.count }.by(1)
|
||||
expect do
|
||||
post :create, @create_params
|
||||
end.to change(Group, :count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -60,11 +56,13 @@ shared_examples_for 'group owner' do
|
|||
|
||||
it 'should be able to destroy group' do
|
||||
delete :destroy, id: @group
|
||||
response.should redirect_to(groups_path)
|
||||
expect(response).to redirect_to(groups_path)
|
||||
end
|
||||
|
||||
it 'should change groups count after destroy action' do
|
||||
lambda { delete :destroy, id: @group }.should change{ Group.count }.by(-1)
|
||||
expect do
|
||||
delete :destroy, id: @group
|
||||
end.to change(Group, :count).by(-1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -84,23 +82,23 @@ describe Groups::ProfileController, type: :controller do
|
|||
else
|
||||
it 'should not be able to perform show action' do
|
||||
get :show, id: @group
|
||||
response.should redirect_to(new_user_session_path)
|
||||
expect(response).to redirect_to(new_user_session_path)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should not be able to perform index action' do
|
||||
get :index
|
||||
response.should redirect_to(new_user_session_path)
|
||||
expect(response).to redirect_to(new_user_session_path)
|
||||
end
|
||||
|
||||
it 'should not be able to perform update action' do
|
||||
put :update, {id: @group}.merge(@update_params)
|
||||
response.should redirect_to(new_user_session_path)
|
||||
expect(response).to redirect_to(new_user_session_path)
|
||||
end
|
||||
|
||||
it 'should not be able to perform create action' do
|
||||
post :create, @create_params
|
||||
response.should redirect_to(new_user_session_path)
|
||||
expect(response).to redirect_to(new_user_session_path)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -116,12 +114,12 @@ describe Groups::ProfileController, type: :controller do
|
|||
|
||||
it 'should be able to perform index action' do
|
||||
get :index
|
||||
response.should render_template(:index)
|
||||
expect(response).to render_template(:index)
|
||||
end
|
||||
|
||||
it 'should be able to perform update action' do
|
||||
put :update, {id: @group}.merge(@update_params)
|
||||
response.should redirect_to(group_path(@group))
|
||||
expect(response).to redirect_to(group_path(@group))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -161,11 +159,13 @@ describe Groups::ProfileController, type: :controller do
|
|||
|
||||
it "should remove user from groups" do
|
||||
delete :remove_user, id: @group
|
||||
response.should redirect_to(groups_path)
|
||||
expect(response).to redirect_to(groups_path)
|
||||
end
|
||||
|
||||
it "should change relations count" do
|
||||
lambda { delete :remove_user, id: @group }.should change{ Relation.count }.by(-1)
|
||||
expect do
|
||||
delete :remove_user, id: @group
|
||||
end.to change(Relation, :count).by(-1)
|
||||
end
|
||||
|
||||
it_should_behave_like 'group user with project show rights'
|
||||
|
|
Loading…
Reference in New Issue