Commit 57c803cbd238e5e93da58c96be011d2db6de7319

Authored by Rafael Manzo
Committed by Rafael Manzo
1 parent 5dc4bfb9

Covered edit method from ProjectsController with unit tests

app/controllers/projects_controller.rb
@@ -44,8 +44,9 @@ class ProjectsController < ApplicationController @@ -44,8 +44,9 @@ class ProjectsController < ApplicationController
44 format.html { redirect_to projects_url, notice: "You shall not edit projects that aren't yours." } 44 format.html { redirect_to projects_url, notice: "You shall not edit projects that aren't yours." }
45 format.json { head :no_content } 45 format.json { head :no_content }
46 end 46 end
  47 + else
  48 + set_project
47 end 49 end
48 - set_project  
49 end 50 end
50 51
51 def update 52 def update
spec/controllers/projects_controller_spec.rb
@@ -107,21 +107,41 @@ describe ProjectsController do @@ -107,21 +107,41 @@ describe ProjectsController do
107 end 107 end
108 108
109 describe 'edit' do 109 describe 'edit' do
110 - before :each do 110 + before do
111 @user = FactoryGirl.create(:user) 111 @user = FactoryGirl.create(:user)
112 @subject = FactoryGirl.build(:project) 112 @subject = FactoryGirl.build(:project)
113 FactoryGirl.create(:project_ownership, {user_id: @user.id, project_id: @subject.id}) 113 FactoryGirl.create(:project_ownership, {user_id: @user.id, project_id: @subject.id})
114 114
115 sign_in @user 115 sign_in @user
  116 + end
116 117
117 - Project.expects(:find).with(@subject.id.to_s).returns(@subject)  
118 - get :edit, :id => @subject.id 118 + context 'when the user owns the project' do
  119 + before :each do
  120 + Project.expects(:find).with(@subject.id.to_s).returns(@subject)
  121 + get :edit, :id => @subject.id
  122 + end
  123 +
  124 + it { should render_template(:edit) }
  125 +
  126 + it 'should assign to @project the @subject' do
  127 + assigns(:project).should eq(@subject)
  128 + end
119 end 129 end
120 130
121 - it { should render_template(:edit) } 131 + context 'when the user does not own the project' do
  132 + before do
  133 + @subject = FactoryGirl.build(:another_project)
122 134
123 - it 'should assign to @project the @subject' do  
124 - assigns(:project).should eq(@subject) 135 + get :edit, :id => @subject.id
  136 + end
  137 +
  138 + it { should redirect_to(projects_path) }
  139 +
  140 + it 'should set the flash' do
  141 + pending("This ShouldaMatcher test is not compatible yet with Rails 4") do
  142 + should set_the_flash[:notice].to("You shall not edit projects that aren't yours.")
  143 + end
  144 + end
125 end 145 end
126 end 146 end
127 147