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 39 # GET /projects/1/edit
40 40 # GET /projects/1/edit.json
41 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 48 set_project
43 49 end
44 50  
... ...
features/project/edition.feature
... ... @@ -21,6 +21,15 @@ Feature: Project
21 21 Then I should not see Edit
22 22  
23 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 33 Scenario: Filling up the form
25 34 Given I am a regular user
26 35 And I am signed in
... ... @@ -34,7 +43,7 @@ Feature: Project
34 43 Scenario: With valid attributes
35 44 Given I am a regular user
36 45 And I am signed in
37   - And I have a sample project
  46 + And I own a sample project
38 47 And I am at the sample project edit page
39 48 And I fill the Name field with "Kalibro"
40 49 And I fill the Description field with "Web Service to collect metrics"
... ... @@ -47,7 +56,7 @@ Feature: Project
47 56 Given I am a regular user
48 57 And I am signed in
49 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 60 And I am at the sample project edit page
52 61 And I fill the Name field with "Qt-Calculator"
53 62 When I press the Update button
... ... @@ -57,7 +66,7 @@ Feature: Project
57 66 Scenario: Editing just the description
58 67 Given I am a regular user
59 68 And I am signed in
60   - And I have a sample project
  69 + And I own a sample project
61 70 And I am at the sample project edit page
62 71 And I fill the Description field with "Web Service to collect metrics"
63 72 When I press the Update button
... ... @@ -67,7 +76,7 @@ Feature: Project
67 76 Scenario: With blank project name
68 77 Given I am a regular user
69 78 And I am signed in
70   - And I have a sample project
  79 + And I own a sample project
71 80 And I am at the sample project edit page
72 81 And I fill the Name field with " "
73 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 17 FactoryGirl.create(:project_ownership, {user_id: @user.id, project_id: @project.id})
18 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 25 Given(/^I am at the Sample Project page$/) do
21 26 visit project_path(@project.id)
22 27 end
... ... @@ -25,6 +30,10 @@ Given(/^I am at the sample project edit page$/) do
25 30 visit edit_project_path(@project.id)
26 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 37 Given(/^I am at the New Project page$/) do
29 38 visit new_project_path
30 39 end
... ...