From 60a97a44e23012efa037583ea4570b9aa1ee3314 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 3 Apr 2015 00:27:27 +0300 Subject: [PATCH] #465: Update specs for Groups::*Controller --- app/controllers/groups/profile_controller.rb | 1 + app/views/groups/profile/show.html.slim | 1 - .../groups/members_controller_spec.rb | 45 ++++++++-------- .../groups/profile_controller_spec.rb | 54 +++++++++---------- 4 files changed, 50 insertions(+), 51 deletions(-) diff --git a/app/controllers/groups/profile_controller.rb b/app/controllers/groups/profile_controller.rb index 57bd83abc..27cbce4c9 100644 --- a/app/controllers/groups/profile_controller.rb +++ b/app/controllers/groups/profile_controller.rb @@ -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) diff --git a/app/views/groups/profile/show.html.slim b/app/views/groups/profile/show.html.slim index 637a25975..5f94992ce 100644 --- a/app/views/groups/profile/show.html.slim +++ b/app/views/groups/profile/show.html.slim @@ -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 - diff --git a/spec/controllers/groups/members_controller_spec.rb b/spec/controllers/groups/members_controller_spec.rb index 27f8f03af..f1341f466 100644 --- a/spec/controllers/groups/members_controller_spec.rb +++ b/spec/controllers/groups/members_controller_spec.rb @@ -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 diff --git a/spec/controllers/groups/profile_controller_spec.rb b/spec/controllers/groups/profile_controller_spec.rb index 62e13ff10..c03204d3b 100644 --- a/spec/controllers/groups/profile_controller_spec.rb +++ b/spec/controllers/groups/profile_controller_spec.rb @@ -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'