Commit 57c803cbd238e5e93da58c96be011d2db6de7319
Committed by
Rafael Manzo
1 parent
5dc4bfb9
Exists in
colab
and in
4 other branches
Covered edit method from ProjectsController with unit tests
Showing
2 changed files
with
28 additions
and
7 deletions
Show diff stats
app/controllers/projects_controller.rb
| ... | ... | @@ -44,8 +44,9 @@ class ProjectsController < ApplicationController |
| 44 | 44 | format.html { redirect_to projects_url, notice: "You shall not edit projects that aren't yours." } |
| 45 | 45 | format.json { head :no_content } |
| 46 | 46 | end |
| 47 | + else | |
| 48 | + set_project | |
| 47 | 49 | end |
| 48 | - set_project | |
| 49 | 50 | end |
| 50 | 51 | |
| 51 | 52 | def update | ... | ... |
spec/controllers/projects_controller_spec.rb
| ... | ... | @@ -107,21 +107,41 @@ describe ProjectsController do |
| 107 | 107 | end |
| 108 | 108 | |
| 109 | 109 | describe 'edit' do |
| 110 | - before :each do | |
| 110 | + before do | |
| 111 | 111 | @user = FactoryGirl.create(:user) |
| 112 | 112 | @subject = FactoryGirl.build(:project) |
| 113 | 113 | FactoryGirl.create(:project_ownership, {user_id: @user.id, project_id: @subject.id}) |
| 114 | 114 | |
| 115 | 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 | 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 | 145 | end |
| 126 | 146 | end |
| 127 | 147 | ... | ... |