summaryrefslogtreecommitdiff
path: root/spec/controllers/users_controller_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-12-07 21:10:08 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-12-07 21:10:08 +0000
commit3a966afb3ea2ef7a98bdc389e0dc906ef4bf0273 (patch)
treee22ca72e41a6d2eaca58ac9cc1390e5f8114ac1f /spec/controllers/users_controller_spec.rb
parent39d41e02dca2139d0bbd88165affd818c9c82fb6 (diff)
downloadgitlab-ce-3a966afb3ea2ef7a98bdc389e0dc906ef4bf0273.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/controllers/users_controller_spec.rb')
-rw-r--r--spec/controllers/users_controller_spec.rb89
1 files changed, 78 insertions, 11 deletions
diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb
index cabd01bcae1..8b89ced3031 100644
--- a/spec/controllers/users_controller_spec.rb
+++ b/spec/controllers/users_controller_spec.rb
@@ -354,32 +354,99 @@ RSpec.describe UsersController do
describe 'GET #contributed' do
let(:project) { create(:project, :public) }
- let(:current_user) { create(:user) }
+
+ subject do
+ get :contributed, params: { username: author.username }, format: format
+ end
before do
- sign_in(current_user)
+ sign_in(user)
project.add_developer(public_user)
project.add_developer(private_user)
+ create(:push_event, project: project, author: author)
+
+ subject
end
- context 'with public profile' do
+ shared_examples_for 'renders contributed projects' do
it 'renders contributed projects' do
- create(:push_event, project: project, author: public_user)
+ expect(assigns[:contributed_projects]).not_to be_empty
+ expect(response).to have_gitlab_http_status(:ok)
+ end
+ end
- get :contributed, params: { username: public_user.username }
+ %i(html json).each do |format|
+ context "format: #{format}" do
+ let(:format) { format }
- expect(assigns[:contributed_projects]).not_to be_empty
+ context 'with public profile' do
+ let(:author) { public_user }
+
+ it_behaves_like 'renders contributed projects'
+ end
+
+ context 'with private profile' do
+ let(:author) { private_user }
+
+ it 'returns 404' do
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+
+ context 'with a user that has the ability to read private profiles', :enable_admin_mode do
+ let(:user) { create(:admin) }
+
+ it_behaves_like 'renders contributed projects'
+ end
+ end
+ end
+ end
+ end
+
+ describe 'GET #starred' do
+ let(:project) { create(:project, :public) }
+
+ subject do
+ get :starred, params: { username: author.username }, format: format
+ end
+
+ before do
+ author.toggle_star(project)
+
+ sign_in(user)
+ subject
+ end
+
+ shared_examples_for 'renders starred projects' do
+ it 'renders starred projects' do
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(assigns[:starred_projects]).not_to be_empty
end
end
- context 'with private profile' do
- it 'does not render contributed projects' do
- create(:push_event, project: project, author: private_user)
+ %i(html json).each do |format|
+ context "format: #{format}" do
+ let(:format) { format }
+
+ context 'with public profile' do
+ let(:author) { public_user }
+
+ it_behaves_like 'renders starred projects'
+ end
+
+ context 'with private profile' do
+ let(:author) { private_user }
+
+ it 'returns 404' do
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
- get :contributed, params: { username: private_user.username }
+ context 'with a user that has the ability to read private profiles', :enable_admin_mode do
+ let(:user) { create(:admin) }
- expect(assigns[:contributed_projects]).to be_empty
+ it_behaves_like 'renders starred projects'
+ end
+ end
end
end
end