#465: Update specs for Projects::HooksController

This commit is contained in:
Vokhmin Alexey V 2015-04-07 00:27:15 +03:00
parent 1e2da91a98
commit 1135f10cb2
2 changed files with 20 additions and 12 deletions

View File

@ -1,8 +1,7 @@
class Projects::HooksController < Projects::BaseController
before_action :authenticate_user!
before_action -> { authorize @project, :update? }
# load_and_authorize_resource :project
# load_and_authorize_resource :hook, through: :project
before_action :load_hook, except: %i(index new create)
def index
@name = params[:name]
@ -11,12 +10,14 @@ class Projects::HooksController < Projects::BaseController
end
def new
@hook = @project.hooks.build
end
def edit
end
def create
authorize @hook = @project.hooks.build(params[:hook])
if @hook.save
redirect_to project_hooks_path(@project, name: @hook.name), notice: t('flash.hook.created')
else
@ -41,4 +42,11 @@ class Projects::HooksController < Projects::BaseController
redirect_to project_hooks_path(@project, name: @hook.name)
end
private
# Private: before_action hook which loads Hook.
def load_hook
authorize @hook = @project.hooks.find(params[:id])
end
end

View File

@ -3,54 +3,54 @@ require 'spec_helper'
shared_examples_for 'hooks user with project admin rights' do
it 'should be able to perform index action' do
get :index, {name_with_owner: "#{@project.owner.uname}/#{@project.name}"}
response.should be_success
expect(response).to be_success
end
it 'should be able to perform new action' do
get :new, { name_with_owner: @project.name_with_owner, hook: { name: 'web' }}
response.should be_success
expect(response).to be_success
end
it 'should be able to perform edit action' do
get :new, { name_with_owner: @project.name_with_owner, id: @hook.id }
response.should be_success
expect(response).to be_success
end
it 'should be able to perform update action' do
put :update, { name_with_owner: @project.name_with_owner, id: @hook.id }.merge(@update_params)
response.should redirect_to(project_hooks_path(@project, name: 'web'))
expect(response).to redirect_to(project_hooks_path(@project, name: 'web'))
end
it 'should be able to perform create action' do
post :create, { name_with_owner: @project.name_with_owner }.merge(@create_params)
response.should redirect_to(project_hooks_path(@project, name: 'web'))
expect(response).to redirect_to(project_hooks_path(@project, name: 'web'))
end
end
shared_examples_for 'hooks user without project admin rights' do
it 'should not be able to perform index action' do
get :index, { name_with_owner: @project.name_with_owner }
response.should redirect_to(forbidden_path)
expect(response).to redirect_to(forbidden_path)
end
it 'should not be able to perform new action' do
get :new, { name_with_owner: @project.name_with_owner, hook: { name: 'web' }}
response.should redirect_to(forbidden_path)
expect(response).to redirect_to(forbidden_path)
end
it 'should not be able to perform edit action' do
get :new, { name_with_owner: @project.name_with_owner, id: @hook.id }
response.should redirect_to(forbidden_path)
expect(response).to redirect_to(forbidden_path)
end
it 'should not be able to perform update action' do
put :update, { name_with_owner: @project.name_with_owner, id: @hook.id }.merge(@update_params)
response.should redirect_to(forbidden_path)
expect(response).to redirect_to(forbidden_path)
end
it 'should not be able to perform create action' do
post :create, { name_with_owner: @project.name_with_owner }.merge(@create_params)
response.should redirect_to(forbidden_path)
expect(response).to redirect_to(forbidden_path)
end
end