Commit 5dc4bfb9e0cd66becd38a60d68695eee0b85ceaf

Authored by Guilherme Rojas V. de Lima
Committed by Guilherme Rojas
1 parent f2e23359

Acceptance tests for project's edit action

app/controllers/projects_controller.rb
@@ -39,6 +39,12 @@ class ProjectsController < ApplicationController @@ -39,6 +39,12 @@ class ProjectsController < ApplicationController
39 # GET /projects/1/edit 39 # GET /projects/1/edit
40 # GET /projects/1/edit.json 40 # GET /projects/1/edit.json
41 def edit 41 def edit
  42 + if current_user.project_ownerships.find_by_project_id(params[:id]).nil?
  43 + respond_to do |format|
  44 + format.html { redirect_to projects_url, notice: "You shall not edit projects that aren't yours." }
  45 + format.json { head :no_content }
  46 + end
  47 + end
42 set_project 48 set_project
43 end 49 end
44 50
features/project/edition.feature
@@ -21,6 +21,15 @@ Feature: Project @@ -21,6 +21,15 @@ Feature: Project
21 Then I should not see Edit 21 Then I should not see Edit
22 22
23 @kalibro_restart 23 @kalibro_restart
  24 + Scenario: Should not render the edit page if the project doesn't belongs to the current user
  25 + Given I am a regular user
  26 + And I am signed in
  27 + And I have a sample project
  28 + And I am at the All Projects page
  29 + When I visit the sample project edit page
  30 + Then I should see You shall not edit
  31 +
  32 + @kalibro_restart
24 Scenario: Filling up the form 33 Scenario: Filling up the form
25 Given I am a regular user 34 Given I am a regular user
26 And I am signed in 35 And I am signed in
@@ -34,7 +43,7 @@ Feature: Project @@ -34,7 +43,7 @@ Feature: Project
34 Scenario: With valid attributes 43 Scenario: With valid attributes
35 Given I am a regular user 44 Given I am a regular user
36 And I am signed in 45 And I am signed in
37 - And I have a sample project 46 + And I own a sample project
38 And I am at the sample project edit page 47 And I am at the sample project edit page
39 And I fill the Name field with "Kalibro" 48 And I fill the Name field with "Kalibro"
40 And I fill the Description field with "Web Service to collect metrics" 49 And I fill the Description field with "Web Service to collect metrics"
@@ -47,7 +56,7 @@ Feature: Project @@ -47,7 +56,7 @@ Feature: Project
47 Given I am a regular user 56 Given I am a regular user
48 And I am signed in 57 And I am signed in
49 And I have a project named "Qt-Calculator" 58 And I have a project named "Qt-Calculator"
50 - And I have a project named "Kalibro" 59 + And I own a project named "Kalibro"
51 And I am at the sample project edit page 60 And I am at the sample project edit page
52 And I fill the Name field with "Qt-Calculator" 61 And I fill the Name field with "Qt-Calculator"
53 When I press the Update button 62 When I press the Update button
@@ -57,7 +66,7 @@ Feature: Project @@ -57,7 +66,7 @@ Feature: Project
57 Scenario: Editing just the description 66 Scenario: Editing just the description
58 Given I am a regular user 67 Given I am a regular user
59 And I am signed in 68 And I am signed in
60 - And I have a sample project 69 + And I own a sample project
61 And I am at the sample project edit page 70 And I am at the sample project edit page
62 And I fill the Description field with "Web Service to collect metrics" 71 And I fill the Description field with "Web Service to collect metrics"
63 When I press the Update button 72 When I press the Update button
@@ -67,7 +76,7 @@ Feature: Project @@ -67,7 +76,7 @@ Feature: Project
67 Scenario: With blank project name 76 Scenario: With blank project name
68 Given I am a regular user 77 Given I am a regular user
69 And I am signed in 78 And I am signed in
70 - And I have a sample project 79 + And I own a sample project
71 And I am at the sample project edit page 80 And I am at the sample project edit page
72 And I fill the Name field with " " 81 And I fill the Name field with " "
73 When I press the Update button 82 When I press the Update button
features/step_definitions/project_steps.rb
@@ -17,6 +17,11 @@ Given(/^I own a sample project$/) do @@ -17,6 +17,11 @@ Given(/^I own a sample project$/) do
17 FactoryGirl.create(:project_ownership, {user_id: @user.id, project_id: @project.id}) 17 FactoryGirl.create(:project_ownership, {user_id: @user.id, project_id: @project.id})
18 end 18 end
19 19
  20 +Given(/^I own a project named "(.*?)"$/) do |name|
  21 + @project = FactoryGirl.create(:project, {id: nil, name: name})
  22 + FactoryGirl.create(:project_ownership, {user_id: @user.id, project_id: @project.id})
  23 +end
  24 +
20 Given(/^I am at the Sample Project page$/) do 25 Given(/^I am at the Sample Project page$/) do
21 visit project_path(@project.id) 26 visit project_path(@project.id)
22 end 27 end
@@ -25,6 +30,10 @@ Given(/^I am at the sample project edit page$/) do @@ -25,6 +30,10 @@ Given(/^I am at the sample project edit page$/) do
25 visit edit_project_path(@project.id) 30 visit edit_project_path(@project.id)
26 end 31 end
27 32
  33 +Given(/^I visit the sample project edit page$/) do
  34 + visit edit_project_path(@project.id)
  35 +end
  36 +
28 Given(/^I am at the New Project page$/) do 37 Given(/^I am at the New Project page$/) do
29 visit new_project_path 38 visit new_project_path
30 end 39 end