#465: Update specs for Projects::SubscribesController

This commit is contained in:
Vokhmin Alexey V 2015-04-07 01:44:05 +03:00
parent 0b41c1459b
commit 81278e3e38
2 changed files with 26 additions and 12 deletions

View File

@ -1,12 +1,10 @@
class Projects::SubscribesController < Projects::BaseController
before_action :authenticate_user!
load_and_authorize_resource :project
load_and_authorize_resource :issue, through: :project, find_by: :serial_id
load_and_authorize_resource :subscribe, through: :issue, find_by: :user_id
before_action :load_issue
def create
@subscribe = @issue.subscribes.build(user_id: current_user.id)
authorize @subscribe = @issue.subscribes.build(user_id: current_user.id)
if @subscribe.save
flash[:notice] = I18n.t("flash.subscribe.saved")
redirect_to :back
@ -17,9 +15,17 @@ class Projects::SubscribesController < Projects::BaseController
end
def destroy
authorize @subscribe = @issue.subscribes.find_by(user_id: current_user.id)
@subscribe.destroy
flash[:notice] = t("flash.subscribe.destroyed")
redirect_to :back
end
private
# Private: before_action hook which loads Issue.
def load_issue
authorize @issue = @project.issues.find_by!(serial_id: params[:issue_id]), :show?
end
end

View File

@ -3,22 +3,26 @@ require 'spec_helper'
shared_examples_for 'can subscribe' do
it 'should be able to perform create action' do
post :create, @create_params
response.should redirect_to(project_issue_path(@project, @issue))
expect(response).to redirect_to(project_issue_path(@project, @issue))
end
it 'should create subscribe object into db' do
lambda{ post :create, @create_params }.should change{ Subscribe.count }.by(1)
expect do
post :create, @create_params
end.to change(Subscribe, :count).by(1)
end
end
shared_examples_for 'can not subscribe' do
it 'should not be able to perform create action' do
post :create, @create_params
response.should redirect_to(forbidden_path)
expect(response).to redirect_to(forbidden_path)
end
it 'should not create subscribe object into db' do
lambda{ post :create, @create_params }.should change{ Subscribe.count }.by(0)
expect do
post :create, @create_params
end.to_not change(Subscribe, :count)
end
end
@ -26,11 +30,13 @@ shared_examples_for 'can unsubscribe' do
it 'should be able to perform destroy action' do
delete :destroy, @destroy_params
response.should redirect_to([@project, @issue])
expect(response).to redirect_to([@project, @issue])
end
it 'should reduce subscribes count' do
lambda{ delete :destroy, @destroy_params }.should change{ Subscribe.count }.by(-1)
expect do
delete :destroy, @destroy_params
end.to change(Subscribe, :count).by(-1)
end
end
@ -38,11 +44,13 @@ shared_examples_for 'can not unsubscribe' do
it 'should not be able to perform destroy action' do
delete :destroy, @destroy_params
response.should redirect_to(forbidden_path)
expect(response).to redirect_to(forbidden_path)
end
it 'should not reduce subscribes count' do
lambda{ delete :destroy, @destroy_params }.should change{ Subscribe.count }.by(0)
expect do
delete :destroy, @destroy_params
end.to_not change(Subscribe, :count)
end
end