From 57c803cbd238e5e93da58c96be011d2db6de7319 Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo + Guilher Rojas V. de Lima Date: Wed, 4 Sep 2013 10:30:02 -0300 Subject: [PATCH] Covered edit method from ProjectsController with unit tests --- app/controllers/projects_controller.rb | 3 ++- spec/controllers/projects_controller_spec.rb | 32 ++++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 1a2b2b2..f1597d6 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -44,8 +44,9 @@ class ProjectsController < ApplicationController format.html { redirect_to projects_url, notice: "You shall not edit projects that aren't yours." } format.json { head :no_content } end + else + set_project end - set_project end def update diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index eb985a4..d5e2a0d 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -107,21 +107,41 @@ describe ProjectsController do end describe 'edit' do - before :each do + before do @user = FactoryGirl.create(:user) @subject = FactoryGirl.build(:project) FactoryGirl.create(:project_ownership, {user_id: @user.id, project_id: @subject.id}) sign_in @user + end - Project.expects(:find).with(@subject.id.to_s).returns(@subject) - get :edit, :id => @subject.id + context 'when the user owns the project' do + before :each do + Project.expects(:find).with(@subject.id.to_s).returns(@subject) + get :edit, :id => @subject.id + end + + it { should render_template(:edit) } + + it 'should assign to @project the @subject' do + assigns(:project).should eq(@subject) + end end - it { should render_template(:edit) } + context 'when the user does not own the project' do + before do + @subject = FactoryGirl.build(:another_project) - it 'should assign to @project the @subject' do - assigns(:project).should eq(@subject) + get :edit, :id => @subject.id + end + + it { should redirect_to(projects_path) } + + it 'should set the flash' do + pending("This ShouldaMatcher test is not compatible yet with Rails 4") do + should set_the_flash[:notice].to("You shall not edit projects that aren't yours.") + end + end end end -- libgit2 0.21.2