Commit e9de569458b55b43a0d09dceef07c3c5d583af24

Authored by Dmitriy Zaporozhets
1 parent 72b29525

Fix tests for user page

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
app/controllers/users_controller.rb
... ... @@ -6,7 +6,7 @@ class UsersController &lt; ApplicationController
6 6 @user = User.find_by_username!(params[:username])
7 7 @projects = Project.personal(@user).accessible_to(current_user)
8 8  
9   - if !current_user && @projects.empty?
  9 + unless current_user || @user.public_profile?
10 10 return authenticate_user!
11 11 end
12 12  
... ...
app/models/user.rb
... ... @@ -478,4 +478,8 @@ class User &lt; ActiveRecord::Base
478 478 def generate_tmp_oauth_email
479 479 self.email = "temp-email-for-oauth-#{username}@gitlab.localhost"
480 480 end
  481 +
  482 + def public_profile?
  483 + authorized_projects.public_only.any?
  484 + end
481 485 end
... ...
features/steps/shared/project.rb
... ... @@ -102,24 +102,24 @@ module SharedProject
102 102 page.should_not have_content "Community"
103 103 end
104 104  
105   - step '"John Doe" is authorized to private project "Enterprise"' do
  105 + step '"John Doe" owns private project "Enterprise"' do
106 106 user = user_exists("John Doe", username: "john_doe")
107 107 project = Project.find_by(name: "Enterprise")
108   - project ||= create(:project, name: "Enterprise", namespace: user.namespace)
  108 + project ||= create(:empty_project, name: "Enterprise", namespace: user.namespace)
109 109 project.team << [user, :master]
110 110 end
111 111  
112   - step '"John Doe" is authorized to internal project "Internal"' do
  112 + step '"John Doe" owns internal project "Internal"' do
113 113 user = user_exists("John Doe", username: "john_doe")
114 114 project = Project.find_by(name: "Internal")
115   - project ||= create :project, :internal, name: 'Internal'
  115 + project ||= create :empty_project, :internal, name: 'Internal', namespace: user.namespace
116 116 project.team << [user, :master]
117 117 end
118 118  
119   - step '"John Doe" is authorized to public project "Community"' do
  119 + step '"John Doe" owns public project "Community"' do
120 120 user = user_exists("John Doe", username: "john_doe")
121 121 project = Project.find_by(name: "Community")
122   - project ||= create :project, :public, name: 'Community'
  122 + project ||= create :empty_project, :public, name: 'Community', namespace: user.namespace
123 123 project.team << [user, :master]
124 124 end
125 125 end
... ...
features/user.feature
1 1 Feature: User
2 2 Background:
3 3 Given User "John Doe" exists
4   - And "John Doe" is authorized to private project "Enterprise"
  4 + And "John Doe" owns private project "Enterprise"
5 5  
6 6 # Signed out
7 7  
8   - Scenario: I visit user "John Doe" page while not signed in when he is authorized to a public project
9   - Given "John Doe" is authorized to internal project "Internal"
10   - And "John Doe" is authorized to public project "Community"
  8 + Scenario: I visit user "John Doe" page while not signed in when he owns a public project
  9 + Given "John Doe" owns internal project "Internal"
  10 + And "John Doe" owns public project "Community"
11 11 When I visit user "John Doe" page
12 12 Then I should see user "John Doe" page
13 13 And I should not see project "Enterprise"
... ... @@ -15,15 +15,15 @@ Feature: User
15 15 And I should see project "Community"
16 16  
17 17 Scenario: I visit user "John Doe" page while not signed in when he is not authorized to a public project
18   - Given "John Doe" is authorized to internal project "Internal"
  18 + Given "John Doe" owns internal project "Internal"
19 19 When I visit user "John Doe" page
20 20 Then I should be redirected to sign in page
21 21  
22 22 # Signed in as someone else
23 23  
24   - Scenario: I visit user "John Doe" page while signed in as someone else when he is authorized to a public project
25   - Given "John Doe" is authorized to public project "Community"
26   - And "John Doe" is authorized to internal project "Internal"
  24 + Scenario: I visit user "John Doe" page while signed in as someone else when he owns a public project
  25 + Given "John Doe" owns public project "Community"
  26 + And "John Doe" owns internal project "Internal"
27 27 And I sign in as a user
28 28 When I visit user "John Doe" page
29 29 Then I should see user "John Doe" page
... ... @@ -32,7 +32,7 @@ Feature: User
32 32 And I should see project "Community"
33 33  
34 34 Scenario: I visit user "John Doe" page while signed in as someone else when he is not authorized to a public project
35   - Given "John Doe" is authorized to internal project "Internal"
  35 + Given "John Doe" owns internal project "Internal"
36 36 And I sign in as a user
37 37 When I visit user "John Doe" page
38 38 Then I should see user "John Doe" page
... ... @@ -51,8 +51,8 @@ Feature: User
51 51 # Signed in as the user himself
52 52  
53 53 Scenario: I visit user "John Doe" page while signed in as "John Doe" when he has a public project
54   - Given "John Doe" is authorized to internal project "Internal"
55   - And "John Doe" is authorized to public project "Community"
  54 + Given "John Doe" owns internal project "Internal"
  55 + And "John Doe" owns public project "Community"
56 56 And I sign in as "John Doe"
57 57 When I visit user "John Doe" page
58 58 Then I should see user "John Doe" page
... ...