Commit 9b04549ca4601af47da45d2c7466aa41f99a374e
Committed by
Guilherme Rojas
1 parent
2ed4b270
Exists in
colab
and in
4 other branches
Refactoring tests for project's edition to cover ownership
PS: the tests isn't covering ownership verification in Controller.
Showing
3 changed files
with
19 additions
and
5 deletions
Show diff stats
app/views/projects/index.html.erb
... | ... | @@ -15,7 +15,9 @@ |
15 | 15 | <td><%= project.name %></td> |
16 | 16 | <td><%= project.description %></td> |
17 | 17 | <td><%= link_to 'Show', project_path(project.id) %></td> |
18 | - <td><%= link_to 'Edit', edit_project_path(project.id) %></td> | |
18 | + <% if project_owner? project.id %> | |
19 | + <td><%= link_to 'Edit', edit_project_path(project.id) %></td> | |
20 | + <% end %> | |
19 | 21 | </tr> |
20 | 22 | <% end %> |
21 | 23 | </tbody> | ... | ... |
features/project/edition.feature
... | ... | @@ -4,19 +4,27 @@ Feature: Project |
4 | 4 | I should be able to edit my projects |
5 | 5 | |
6 | 6 | @kalibro_restart |
7 | - Scenario: Going to the edit page | |
7 | + Scenario: Should go to the edit page from a project that I own | |
8 | 8 | Given I am a regular user |
9 | 9 | And I am signed in |
10 | - And I have a sample project | |
10 | + And I own a sample project | |
11 | 11 | And I am at the All Projects page |
12 | 12 | When I click the Edit link |
13 | 13 | Then I should be in the Edit Project page |
14 | + | |
15 | + @kalibro_restart | |
16 | + Scenario: Should not show edit links from projects that doesn't belongs to me | |
17 | + Given I am a regular user | |
18 | + And I am signed in | |
19 | + And I have a sample project | |
20 | + And I am at the All Projects page | |
21 | + Then I should not see Edit | |
14 | 22 | |
15 | 23 | @kalibro_restart |
16 | 24 | Scenario: Filling up the form |
17 | 25 | Given I am a regular user |
18 | 26 | And I am signed in |
19 | - And I have a sample project | |
27 | + And I own a sample project | |
20 | 28 | And I am at the All Projects page |
21 | 29 | When I click the Edit link |
22 | 30 | Then The field "project[name]" should be filled with the sample project "name" | ... | ... |
spec/controllers/projects_controller_spec.rb
... | ... | @@ -108,8 +108,12 @@ describe ProjectsController do |
108 | 108 | |
109 | 109 | describe 'edit' do |
110 | 110 | before :each do |
111 | - sign_in FactoryGirl.create(:user) | |
111 | + @user = FactoryGirl.create(:user) | |
112 | 112 | @subject = FactoryGirl.build(:project) |
113 | + FactoryGirl.create(:project_ownership, {user_id: @user.id, project_id: @subject.id}) | |
114 | + | |
115 | + sign_in @user | |
116 | + | |
113 | 117 | Project.expects(:find).with(@subject.id.to_s).returns(@subject) |
114 | 118 | get :edit, :id => @subject.id |
115 | 119 | end | ... | ... |