#465: Update specs for Groups::*Controller

This commit is contained in:
Vokhmin Alexey V 2015-04-03 00:27:27 +03:00
parent 69690024af
commit 60a97a44e2
4 changed files with 50 additions and 51 deletions

View File

@ -11,6 +11,7 @@ class Groups::ProfileController < Groups::BaseController
end end
def show def show
authorize @group
respond_to do |format| respond_to do |format|
format.html do format.html do
@members = @group.members.order(:uname) @members = @group.members.order(:uname)

View File

@ -33,4 +33,3 @@ hr
p p
=> image_tag avatar_url(member, :micro), alt: member.uname, height: size, width: size => image_tag avatar_url(member, :micro), alt: member.uname, height: size, width: size
= link_to member.uname.truncate(20), member = link_to member.uname.truncate(20), member

View File

@ -15,20 +15,20 @@ describe Groups::MembersController, type: :controller do
context 'for owner user' do context 'for owner user' do
it 'should add member to group' do it 'should add member to group' do
post :add, @add_params post :add, @add_params
response.should redirect_to(group_members_path(@group)) expect(response).to redirect_to(group_members_path(@group))
Relation.by_target(@group).by_actor(@another_user).count.should eql(1) expect(Relation.by_target(@group).by_actor(@another_user).count).to eq 1
end end
it 'should add reader member to group' do it 'should add reader member to group' do
post :add, @add_params post :add, @add_params
Relation.by_target(@group).by_actor(@another_user).first.role.should eql('reader') expect(Relation.by_target(@group).by_actor(@another_user).first.role).to eq 'reader'
response.should redirect_to(group_members_path(@group)) expect(response).to redirect_to(group_members_path(@group))
end end
it 'should not remove self from group' do it 'should not remove self from group' do
post :remove, @remove_params post :remove, @remove_params
Relation.by_target(@group).by_actor(@user).first.role.should eql('admin') expect(Relation.by_target(@group).by_actor(@user).first.role).to eq 'admin'
response.should redirect_to(group_members_path(@group)) expect(response).to redirect_to(group_members_path(@group))
end end
end end
@ -41,27 +41,26 @@ describe Groups::MembersController, type: :controller do
it 'should add member to group' do it 'should add member to group' do
post :add, @add_params post :add, @add_params
response.should redirect_to(group_members_path(@group)) expect(Relation.by_target(@group).by_actor(@another_user).count).to eq 1
Relation.by_target(@group).by_actor(@another_user).count.should eql(1) expect(response).to redirect_to(group_members_path(@group))
response.should redirect_to(group_members_path(@group))
end end
it 'should add reader member to group' do it 'should add reader member to group' do
post :add, @add_params post :add, @add_params
Relation.by_target(@group).by_actor(@another_user).first.role.should eql('reader') expect(Relation.by_target(@group).by_actor(@another_user).first.role).to eq 'reader'
response.should redirect_to(group_members_path(@group)) expect(response).to redirect_to(group_members_path(@group))
end end
it 'should not remove owner from group' do it 'should not remove owner from group' do
post :remove, @remove_params post :remove, @remove_params
Relation.by_target(@group).by_actor(@user).first.role.should eql('admin') expect(Relation.by_target(@group).by_actor(@user).first.role).to eq 'admin'
response.should redirect_to(group_members_path(@group)) expect(response).to redirect_to(group_members_path(@group))
end end
it 'should not set read role to owner group' do it 'should not set read role to owner group' do
post :update, @update_params post :update, @update_params
Relation.by_target(@group).by_actor(@user).first.role.should eql('admin') expect(Relation.by_target(@group).by_actor(@user).first.role).to eq 'admin'
response.should redirect_to(forbidden_path) expect(response).to redirect_to(forbidden_path)
end end
end end
@ -74,22 +73,22 @@ describe Groups::MembersController, type: :controller do
it 'should not add member to group' do it 'should not add member to group' do
post :add, @add_params post :add, @add_params
response.should redirect_to(forbidden_path) expect(response).to redirect_to(forbidden_path)
end end
it 'should add reader member to group' do it 'should add reader member to group' do
post :add, @add_params post :add, @add_params
response.should redirect_to(forbidden_path) expect(response).to redirect_to(forbidden_path)
end end
it 'should not remove owner from group' do it 'should not remove owner from group' do
post :remove, @remove_params post :remove, @remove_params
response.should redirect_to(forbidden_path) expect(response).to redirect_to(forbidden_path)
end end
it 'should not set read role to owner group' do it 'should not set read role to owner group' do
post :update, @update_params post :update, @update_params
response.should redirect_to(forbidden_path) expect(response).to redirect_to(forbidden_path)
end end
end end
@ -100,22 +99,22 @@ describe Groups::MembersController, type: :controller do
it 'should not add member to group' do it 'should not add member to group' do
post :add, @add_params post :add, @add_params
response.should redirect_to(forbidden_path) expect(response).to redirect_to(forbidden_path)
end end
it 'should add reader member to group' do it 'should add reader member to group' do
post :add, @add_params post :add, @add_params
response.should redirect_to(forbidden_path) expect(response).to redirect_to(forbidden_path)
end end
it 'should not remove owner from group' do it 'should not remove owner from group' do
post :remove, @remove_params post :remove, @remove_params
response.should redirect_to(forbidden_path) expect(response).to redirect_to(forbidden_path)
end end
it 'should not set read role to owner group' do it 'should not set read role to owner group' do
post :update, @update_params post :update, @update_params
response.should redirect_to(forbidden_path) expect(response).to redirect_to(forbidden_path)
end end
end end
end end

View File

@ -3,55 +3,51 @@ require 'spec_helper'
shared_examples_for 'group user with project show rights' do shared_examples_for 'group user with project show rights' do
it 'should be able to perform show action' do it 'should be able to perform show action' do
get :show, uname: @group.uname get :show, uname: @group.uname
response.should render_template(:show) expect(response).to render_template(:show)
end end
end end
shared_examples_for 'group user without update rights' do shared_examples_for 'group user without update rights' do
it 'should be not able to perform update action' do it 'should be not able to perform update action' do
put :update, {id: @group}.merge(@update_params) put :update, {id: @group}.merge(@update_params)
response.should redirect_to(forbidden_path) expect(response).to redirect_to(forbidden_path)
end expect(@group.reload.description).to_not eq 'grp2'
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'
end end
end end
shared_examples_for 'group user without destroy rights' do shared_examples_for 'group user without destroy rights' do
it 'should not be able to destroy group' do it 'should not be able to destroy group' do
delete :destroy, id: @group delete :destroy, id: @group
response.should redirect_to(forbidden_path) expect(response).to redirect_to(forbidden_path)
end end
it 'should not change groups count after destroy action' do 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
end end
shared_examples_for 'group admin' do shared_examples_for 'group admin' do
it_should_behave_like 'no group user' 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 it 'should be able to perform update action' do
put :update, {id: @group}.merge(@update_params) 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
end end
shared_examples_for 'no group user' do shared_examples_for 'no group user' do
it 'should be able to perform create action' do it 'should be able to perform create action' do
post :create, @create_params post :create, @create_params
response.should redirect_to(group_path(Group.last)) expect(response).to redirect_to(group_path(Group.last))
end end
it 'should change objects count on create' do 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
end end
@ -60,11 +56,13 @@ shared_examples_for 'group owner' do
it 'should be able to destroy group' do it 'should be able to destroy group' do
delete :destroy, id: @group delete :destroy, id: @group
response.should redirect_to(groups_path) expect(response).to redirect_to(groups_path)
end end
it 'should change groups count after destroy action' do 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
end end
@ -84,23 +82,23 @@ describe Groups::ProfileController, type: :controller do
else else
it 'should not be able to perform show action' do it 'should not be able to perform show action' do
get :show, id: @group get :show, id: @group
response.should redirect_to(new_user_session_path) expect(response).to redirect_to(new_user_session_path)
end end
end end
it 'should not be able to perform index action' do it 'should not be able to perform index action' do
get :index get :index
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 update action' do it 'should not be able to perform update action' do
put :update, {id: @group}.merge(@update_params) 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 end
it 'should not be able to perform create action' do it 'should not be able to perform create action' do
post :create, @create_params post :create, @create_params
response.should redirect_to(new_user_session_path) expect(response).to redirect_to(new_user_session_path)
end end
end end
@ -116,12 +114,12 @@ describe Groups::ProfileController, type: :controller do
it 'should be able to perform index action' do it 'should be able to perform index action' do
get :index get :index
response.should render_template(:index) expect(response).to render_template(:index)
end end
it 'should be able to perform update action' do it 'should be able to perform update action' do
put :update, {id: @group}.merge(@update_params) put :update, {id: @group}.merge(@update_params)
response.should redirect_to(group_path(@group)) expect(response).to redirect_to(group_path(@group))
end end
end end
@ -161,11 +159,13 @@ describe Groups::ProfileController, type: :controller do
it "should remove user from groups" do it "should remove user from groups" do
delete :remove_user, id: @group delete :remove_user, id: @group
response.should redirect_to(groups_path) expect(response).to redirect_to(groups_path)
end end
it "should change relations count" do 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 end
it_should_behave_like 'group user with project show rights' it_should_behave_like 'group user with project show rights'