2019-10-08 08:06:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-13 03:38:26 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe 'projects/_home_panel' do
|
2019-11-19 11:17:35 -05:00
|
|
|
include ProjectForksHelper
|
|
|
|
|
2021-07-01 05:07:33 -04:00
|
|
|
context 'admin area link' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
assign(:project, project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders admin area link for admin' do
|
|
|
|
allow(view).to receive(:current_user).and_return(create(:admin))
|
|
|
|
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).to have_link(href: admin_project_path(project))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not render admin area link for non-admin' do
|
|
|
|
allow(view).to receive(:current_user).and_return(create(:user))
|
|
|
|
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).not_to have_link(href: admin_project_path(project))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not render admin area link for anonymous' do
|
|
|
|
allow(view).to receive(:current_user).and_return(nil)
|
|
|
|
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).not_to have_link(href: admin_project_path(project))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-18 02:58:21 -04:00
|
|
|
context 'notifications' do
|
|
|
|
let(:project) { create(:project) }
|
2017-02-13 03:38:26 -05:00
|
|
|
|
2018-07-18 02:58:21 -04:00
|
|
|
before do
|
|
|
|
assign(:project, project)
|
2017-02-13 03:38:26 -05:00
|
|
|
|
2018-07-18 02:58:21 -04:00
|
|
|
allow(view).to receive(:current_user).and_return(user)
|
|
|
|
allow(view).to receive(:can?).with(user, :read_project, project).and_return(false)
|
2018-09-06 03:27:39 -04:00
|
|
|
allow(project).to receive(:license_anchor_data).and_return(false)
|
2018-07-18 02:58:21 -04:00
|
|
|
end
|
2017-02-13 03:38:26 -05:00
|
|
|
|
2018-07-18 02:58:21 -04:00
|
|
|
context 'when user is signed in' do
|
|
|
|
let(:user) { create(:user) }
|
2017-02-13 03:38:26 -05:00
|
|
|
|
2018-07-18 02:58:21 -04:00
|
|
|
before do
|
|
|
|
notification_settings = user.notification_settings_for(project)
|
|
|
|
assign(:notification_setting, notification_settings)
|
|
|
|
end
|
2017-02-13 03:38:26 -05:00
|
|
|
|
2021-03-01 04:11:01 -05:00
|
|
|
it 'renders Vue app root' do
|
2018-07-18 02:58:21 -04:00
|
|
|
render
|
2017-02-13 03:38:26 -05:00
|
|
|
|
2021-03-01 04:11:01 -05:00
|
|
|
expect(rendered).to have_selector('.js-vue-notification-dropdown')
|
2018-07-18 02:58:21 -04:00
|
|
|
end
|
2017-02-13 03:38:26 -05:00
|
|
|
end
|
|
|
|
|
2018-07-18 02:58:21 -04:00
|
|
|
context 'when user is signed out' do
|
|
|
|
let(:user) { nil }
|
2017-02-13 03:38:26 -05:00
|
|
|
|
2018-07-18 02:58:21 -04:00
|
|
|
before do
|
|
|
|
assign(:notification_setting, nil)
|
|
|
|
end
|
2018-03-05 12:51:40 -05:00
|
|
|
|
2021-03-01 04:11:01 -05:00
|
|
|
it 'does not render Vue app root' do
|
2018-03-05 12:51:40 -05:00
|
|
|
render
|
|
|
|
|
2021-03-01 04:11:01 -05:00
|
|
|
expect(rendered).not_to have_selector('.js-vue-notification-dropdown')
|
2018-03-05 12:51:40 -05:00
|
|
|
end
|
|
|
|
end
|
2018-07-18 02:58:21 -04:00
|
|
|
end
|
2018-03-05 12:51:40 -05:00
|
|
|
|
2018-07-18 02:58:21 -04:00
|
|
|
context 'badges' do
|
2018-03-05 12:51:40 -05:00
|
|
|
shared_examples 'show badges' do
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'renders the all badges' do
|
2018-03-05 12:51:40 -05:00
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).to have_selector('.project-badges a')
|
|
|
|
|
|
|
|
badges.each do |badge|
|
|
|
|
expect(rendered).to have_link(href: badge.rendered_link_url)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-18 02:58:21 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:badges) { project.badges }
|
|
|
|
|
|
|
|
before do
|
|
|
|
assign(:project, project)
|
|
|
|
|
|
|
|
allow(view).to receive(:current_user).and_return(user)
|
|
|
|
allow(view).to receive(:can?).with(user, :read_project, project).and_return(false)
|
2018-09-06 03:27:39 -04:00
|
|
|
allow(project).to receive(:license_anchor_data).and_return(false)
|
2018-07-18 02:58:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'has no badges' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'does not render any badge' do
|
2018-07-18 02:58:21 -04:00
|
|
|
render
|
|
|
|
|
2018-09-06 03:27:39 -04:00
|
|
|
expect(rendered).not_to have_selector('.project-badges')
|
2018-07-18 02:58:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-05 12:51:40 -05:00
|
|
|
context 'only has group badges' do
|
2018-07-18 02:58:21 -04:00
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:project) { create(:project, namespace: group) }
|
|
|
|
|
2018-03-05 12:51:40 -05:00
|
|
|
before do
|
|
|
|
create(:group_badge, group: project.group)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'show badges'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'only has project badges' do
|
2018-07-18 02:58:21 -04:00
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
2018-03-05 12:51:40 -05:00
|
|
|
before do
|
|
|
|
create(:project_badge, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'show badges'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'has both group and project badges' do
|
2018-07-18 02:58:21 -04:00
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:project) { create(:project, namespace: group) }
|
|
|
|
|
2018-03-05 12:51:40 -05:00
|
|
|
before do
|
|
|
|
create(:project_badge, project: project)
|
|
|
|
create(:group_badge, group: project.group)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'show badges'
|
|
|
|
end
|
|
|
|
end
|
2018-07-18 02:58:21 -04:00
|
|
|
|
|
|
|
context 'project id' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
assign(:project, project)
|
|
|
|
|
|
|
|
allow(view).to receive(:current_user).and_return(user)
|
2018-09-06 03:27:39 -04:00
|
|
|
allow(project).to receive(:license_anchor_data).and_return(false)
|
2018-07-18 02:58:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'user can read project' do
|
|
|
|
it 'is shown' do
|
|
|
|
allow(view).to receive(:can?).with(user, :read_project, project).and_return(true)
|
|
|
|
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).to have_content("Project ID: #{project.id}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user cannot read project' do
|
|
|
|
it 'is not shown' do
|
|
|
|
allow(view).to receive(:can?).with(user, :read_project, project).and_return(false)
|
|
|
|
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).not_to have_content("Project ID: #{project.id}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-11-19 11:17:35 -05:00
|
|
|
|
|
|
|
context 'forks' do
|
|
|
|
let(:source_project) { create(:project, :repository) }
|
|
|
|
let(:project) { fork_project(source_project) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
assign(:project, project)
|
|
|
|
|
|
|
|
allow(view).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user can read fork source' do
|
|
|
|
it 'shows the forked-from project' do
|
|
|
|
allow(view).to receive(:can?).with(user, :read_project, source_project).and_return(true)
|
|
|
|
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).to have_content("Forked from #{source_project.full_name}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user cannot read fork source' do
|
|
|
|
it 'does not show the forked-from project' do
|
|
|
|
allow(view).to receive(:can?).with(user, :read_project, source_project).and_return(false)
|
|
|
|
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).to have_content("Forked from an inaccessible project")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-02-13 03:38:26 -05:00
|
|
|
end
|