Commit 3090c6b1 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'ce-to-ee-2018-07-18' into 'master'

CE upstream - 2018-07-18 13:39 UTC

See merge request gitlab-org/gitlab-ee!6575
parents 4b9159b0 5850eec9
......@@ -107,7 +107,8 @@ module SearchHelper
category: "Groups",
id: group.id,
label: "#{search_result_sanitize(group.full_name)}",
url: group_path(group)
url: group_path(group),
avatar_url: group.avatar_url || ''
}
end
end
......@@ -121,7 +122,8 @@ module SearchHelper
id: p.id,
value: "#{search_result_sanitize(p.name)}",
label: "#{search_result_sanitize(p.full_name)}",
url: project_path(p)
url: project_path(p),
avatar_url: p.avatar_url || ''
}
end
end
......
......@@ -182,7 +182,7 @@ class MergeRequestDiff < ActiveRecord::Base
end
def diffs(diff_options = nil)
if without_files? && comparison = diff_refs.compare_in(project)
if without_files? && comparison = diff_refs&.compare_in(project)
# It should fetch the repository when diffs are cleaned by the system.
# We don't keep these for storage overload purposes.
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/37639
......
# frozen_string_literal: true
module Lfs
# Usage: Calling `new_file` check to see if a file should be in LFS and
# return a transformed result with `content` and `encoding` to commit.
......
# frozen_string_literal: true
module Lfs
class LockFileService < BaseService
prepend EE::Lfs::LockFileService
......
# frozen_string_literal: true
module Lfs
class LocksFinderService < BaseService
def execute
......
# frozen_string_literal: true
module Lfs
class UnlockFileService < BaseService
prepend EE::Lfs::UnlockFileService
......
# frozen_string_literal: true
module Mattermost
class CreateTeamService < ::BaseService
def initialize(group, current_user)
......
# frozen_string_literal: true
module Members
class ApproveAccessRequestService < Members::BaseService
prepend EE::Members::ApproveAccessRequestService
......
# frozen_string_literal: true
module Members
class BaseService < ::BaseService
# current_user - The user that performs the action
......
# frozen_string_literal: true
module Members
class CreateService < Members::BaseService
prepend EE::Members::CreateService
......
# frozen_string_literal: true
module Members
class DestroyService < Members::BaseService
prepend EE::Members::DestroyService
......
# frozen_string_literal: true
module Members
class RequestAccessService < Members::BaseService
def execute(source)
......
# frozen_string_literal: true
module Members
class UpdateService < Members::BaseService
prepend EE::Members::UpdateService
......
# frozen_string_literal: true
module MergeRequests
class AddTodoWhenBuildFailsService < MergeRequests::BaseService
# Adds a todo to the parent merge_request when a CI build fails
......
# frozen_string_literal: true
module MergeRequests
class AssignIssuesService < BaseService
def assignable_issues
......
# frozen_string_literal: true
module MergeRequests
class BaseService < ::IssuableBaseService
prepend EE::MergeRequests::BaseService
......
# frozen_string_literal: true
module MergeRequests
class BuildService < MergeRequests::BaseService
prepend EE::MergeRequests::BuildService
......@@ -141,7 +143,8 @@ module MergeRequests
closes_issue = "Closes #{issue.to_reference}"
if description.present?
merge_request.description += closes_issue.prepend("\n\n")
descr_parts = [merge_request.description, closes_issue]
merge_request.description = descr_parts.join("\n\n")
else
merge_request.description = closes_issue
end
......@@ -165,9 +168,11 @@ module MergeRequests
return if merge_request.title.present?
if issue_iid.present?
merge_request.title = "Resolve #{issue.to_reference}"
title_parts = ["Resolve #{issue.to_reference}"]
branch_title = source_branch.downcase.remove(issue_iid.downcase).titleize.humanize
merge_request.title += " \"#{branch_title}\"" if branch_title.present?
title_parts << "\"#{branch_title}\"" if branch_title.present?
merge_request.title = title_parts.join(' ')
end
end
......
# frozen_string_literal: true
module MergeRequests
class CloseService < MergeRequests::BaseService
def execute(merge_request, commit = nil)
......
# frozen_string_literal: true
module MergeRequests
module Conflicts
class BaseService
......
# frozen_string_literal: true
module MergeRequests
module Conflicts
class ListService < MergeRequests::Conflicts::BaseService
......
# frozen_string_literal: true
module MergeRequests
module Conflicts
class ResolveService < MergeRequests::Conflicts::BaseService
......
# frozen_string_literal: true
module MergeRequests
class CreateFromIssueService < MergeRequests::CreateService
def initialize(project, user, params)
......
# frozen_string_literal: true
module MergeRequests
class CreateService < MergeRequests::BaseService
def execute
......
# frozen_string_literal: true
module MergeRequests
class DeleteNonLatestDiffsService
BATCH_SIZE = 10
......
# frozen_string_literal: true
module MergeRequests
# MergeService class
#
......
# frozen_string_literal: true
module MergeRequests
class GetUrlsService < BaseService
attr_reader :project
......
# frozen_string_literal: true
module MergeRequests
# MergeService class
#
......
# frozen_string_literal: true
module MergeRequests
class MergeWhenPipelineSucceedsService < MergeRequests::BaseService
# Marks the passed `merge_request` to be merged when the pipeline succeeds or
......
# frozen_string_literal: true
module MergeRequests
# PostMergeService class
#
......
# frozen_string_literal: true
module MergeRequests
class RebaseService < MergeRequests::WorkingCopyBaseService
REBASE_ERROR = 'Rebase failed. Please rebase locally'.freeze
......
# frozen_string_literal: true
module MergeRequests
class RefreshService < MergeRequests::BaseService
prepend EE::MergeRequests::RefreshService
......
# frozen_string_literal: true
module MergeRequests
class ReloadDiffsService
def initialize(merge_request, current_user)
......
# frozen_string_literal: true
module MergeRequests
class ReopenService < MergeRequests::BaseService
def execute(merge_request)
......
# frozen_string_literal: true
module MergeRequests
class ResolvedDiscussionNotificationService < MergeRequests::BaseService
def execute(merge_request)
......
# frozen_string_literal: true
module MergeRequests
class SquashService < MergeRequests::WorkingCopyBaseService
def execute(merge_request)
......
# frozen_string_literal: true
module MergeRequests
class UpdateService < MergeRequests::BaseService
prepend ::EE::MergeRequests::UpdateService
......
# frozen_string_literal: true
module MergeRequests
class WorkingCopyBaseService < MergeRequests::BaseService
attr_reader :merge_request
......
# frozen_string_literal: true
module Milestones
class BaseService < ::BaseService
# Parent can either a group or a project
......
# frozen_string_literal: true
module Milestones
class CloseService < Milestones::BaseService
def execute(milestone)
......
# frozen_string_literal: true
module Milestones
class CreateService < Milestones::BaseService
def execute
......
# frozen_string_literal: true
module Milestones
class DestroyService < Milestones::BaseService
def execute(milestone)
......
# frozen_string_literal: true
module Milestones
class PromoteService < Milestones::BaseService
prepend EE::Milestones::PromoteService
......
# frozen_string_literal: true
module Milestones
class ReopenService < Milestones::BaseService
def execute(milestone)
......
# frozen_string_literal: true
module Milestones
class UpdateService < Milestones::BaseService
def execute(milestone)
......
# frozen_string_literal: true
module Notes
class BuildService < ::BaseService
prepend ::EE::Notes::BuildService
......
# frozen_string_literal: true
module Notes
class CreateService < ::BaseService
def execute
......
# frozen_string_literal: true
module Notes
class DestroyService < BaseService
def execute(note)
......
# frozen_string_literal: true
module Notes
class PostProcessService
attr_accessor :note
......
# frozen_string_literal: true
module Notes
class QuickActionsService < BaseService
UPDATE_SERVICES = {
......
# frozen_string_literal: true
module Notes
class RenderService < BaseRenderer
# Renders a collection of Note instances.
......
# frozen_string_literal: true
module Notes
class ResolveService < ::BaseService
def execute(note)
......
# frozen_string_literal: true
module Notes
class UpdateService < BaseService
def execute(note)
......
# frozen_string_literal: true
module Projects
class AfterImportService
RESERVED_REF_PREFIXES = Repository::RESERVED_REFS_NAMES.map { |n| File.join('refs', n, '/') }
......
# frozen_string_literal: true
module Projects
class AutocompleteService < BaseService
def issues
......
# frozen_string_literal: true
module Projects
class BaseMoveRelationsService < BaseService
attr_reader :source_project
......
# frozen_string_literal: true
# Service class for getting and caching the number of elements of several projects
# Warning: do not user this service with a really large set of projects
# because the service use maps to retrieve the project ids.
......
# frozen_string_literal: true
# Service class for getting and caching the number of forks of several projects
# Warning: do not user this service with a really large set of projects
# because the service use maps to retrieve the project ids
......
# frozen_string_literal: true
# Service class for getting and caching the number of issues of several projects
# Warning: do not user this service with a really large set of projects
# because the service use maps to retrieve the project ids
......
# frozen_string_literal: true
module Projects
# Base class for the various service classes that count project data (e.g.
# issues or forks).
......
# frozen_string_literal: true
module Projects
class CreateFromTemplateService < BaseService
def initialize(user, params)
......
# frozen_string_literal: true
module Projects
class CreateService < BaseService
prepend ::EE::Projects::CreateService
......
# frozen_string_literal: true
module Projects
class DestroyService < BaseService
include Gitlab::ShellAdapter
......
# frozen_string_literal: true
module Projects
class DownloadService < BaseService
WHITELIST = [
......
# frozen_string_literal: true
module Projects
class EnableDeployKeyService < BaseService
def execute
......
# frozen_string_literal: true
module Projects
class ForkService < BaseService
def execute(fork_to_project = nil)
......
# frozen_string_literal: true
module Projects
# Service class for getting and caching the number of forks of a project.
class ForksCountService < Projects::CountService
......
# frozen_string_literal: true
# This service is an adapter used to for the GitLab Import feature, and
# creating a project from a template.
# The latter will under the hood just import an archive supplied by GitLab.
......
# frozen_string_literal: true
module Projects
module GroupLinks
class CreateService < BaseService
......
# frozen_string_literal: true
module Projects
module GroupLinks
class DestroyService < BaseService
......
# frozen_string_literal: true
module Projects
module HashedStorage
AttachmentMigrationError = Class.new(StandardError)
......
# frozen_string_literal: true
module Projects
module HashedStorage
class MigrateRepositoryService < BaseService
......
# frozen_string_literal: true
module Projects
class HashedStorageMigrationService < BaseService
attr_reader :logger
......
# frozen_string_literal: true
# Projects::HousekeepingService class
#
# Used for git housekeeping
......
# frozen_string_literal: true
module Projects
module ImportExport
class ExportService < BaseService
......
# frozen_string_literal: true
module Projects
class ImportService < BaseService
include Gitlab::ShellAdapter
......
# frozen_string_literal: true
# This service lists the download link from a remote source based on the
# oids provided
module Projects
......
# frozen_string_literal: true
# This service downloads and links lfs objects from a remote URL
module Projects
module LfsPointers
......
# frozen_string_literal: true
# This service manages the whole worflow of discovering the Lfs files in a
# repository, linking them to the project and downloading (and linking) the non
# existent ones.
......
# frozen_string_literal: true
# Given a list of oids, this services links the existent Lfs Objects to the project
module Projects
module LfsPointers
......
# frozen_string_literal: true
# This service list all existent Lfs objects in a repository
module Projects
module LfsPointers
......
# frozen_string_literal: true
module Projects
class MoveAccessService < BaseMoveRelationsService
def execute(source_project, remove_remaining_elements: true)
......
# frozen_string_literal: true
module Projects
class MoveDeployKeysProjectsService < BaseMoveRelationsService
def execute(source_project, remove_remaining_elements: true)
......
# frozen_string_literal: true
module Projects
class MoveForksService < BaseMoveRelationsService
def execute(source_project, remove_remaining_elements: true)
......
# frozen_string_literal: true
module Projects
class MoveLfsObjectsProjectsService < BaseMoveRelationsService
def execute(source_project, remove_remaining_elements: true)
......
# frozen_string_literal: true
module Projects
class MoveNotificationSettingsService < BaseMoveRelationsService
def execute(source_project, remove_remaining_elements: true)
......
# frozen_string_literal: true
# NOTE: This service cannot be used directly because it is part of a
# a bigger process. Instead, use the service MoveAccessService which moves
# project memberships, project group links, authorizations and refreshes
......
# frozen_string_literal: true
# NOTE: This service cannot be used directly because it is part of a
# a bigger process. Instead, use the service MoveAccessService which moves
# project memberships, project group links, authorizations and refreshes
......
# frozen_string_literal: true
# NOTE: This service cannot be used directly because it is part of a
# a bigger process. Instead, use the service MoveAccessService which moves
# project memberships, project group links, authorizations and refreshes
......
# frozen_string_literal: true
module Projects
class MoveUsersStarProjectsService < BaseMoveRelationsService
def execute(source_project, remove_remaining_elements: true)
......
# frozen_string_literal: true
module Projects
# Service class for counting and caching the number of open issues of a
# project.
......
# frozen_string_literal: true
module Projects
# Service class for counting and caching the number of open merge requests of
# a project.
......
# frozen_string_literal: true
module Projects
class OverwriteProjectService < BaseService
def execute(source_project)
......
# frozen_string_literal: true
module Projects
class ParticipantsService < BaseService
include Users::ParticipableService
......
# frozen_string_literal: true
module Projects
class PropagateServiceTemplate
BATCH_SIZE = 100
......
# frozen_string_literal: true
# Projects::TransferService class
#
# Used for transfer project to another namespace
......
# frozen_string_literal: true
module Projects
class UnlinkForkService < BaseService
def execute
......
# frozen_string_literal: true
module Projects
class UpdatePagesConfigurationService < BaseService
attr_reader :project
......
# frozen_string_literal: true
module Projects
class UpdatePagesService < BaseService
InvalidStateError = Class.new(StandardError)
......
# frozen_string_literal: true
module Projects
class UpdateRemoteMirrorService < BaseService
attr_reader :errors
......
# frozen_string_literal: true
module Projects
class UpdateService < BaseService
include UpdateVisibilityLevel
......
- add_to_breadcrumbs "Users", admin_users_path
- add_to_breadcrumbs @user.name, admin_user_identities_path(@user)
- breadcrumb_title "Edit Identity"
- page_title _("Edit"), @identity.provider, _("Identities"), @user.name, _("Users")
%h3.page-title
= _('Edit identity for %{user_name}') % { user_name: @user.name }
......
- add_to_breadcrumbs "Users", admin_users_path
- breadcrumb_title @user.name
- page_title _("Identities"), @user.name, _("Users")
= render 'admin/users/head'
......
- add_to_breadcrumbs "Users", admin_users_path
- add_to_breadcrumbs @user.name, admin_user_identities_path(@user)
- breadcrumb_title "New Identity"
- page_title _("New Identity")
%h3.page-title= _('New identity')
%hr
......
- add_to_breadcrumbs "Users", admin_users_path
- breadcrumb_title @user.name
- page_title "Impersonation Tokens", @user.name, "Users"
= render 'admin/users/head'
......
- add_to_breadcrumbs "Users", admin_users_path
- breadcrumb_title @user.name
- page_title "SSH Keys", @user.name, "Users"
= render 'admin/users/head'
= render 'profiles/keys/key_table', admin: true
- add_to_breadcrumbs "Users", admin_users_path
- breadcrumb_title @user.name
- page_title "Groups and projects", @user.name, "Users"
= render 'admin/users/head'
......
......@@ -12,6 +12,9 @@
.project-home-desc
- if @project.description.present?
= markdown_field(@project, :description)
- if can?(current_user, :read_project, @project)
.text-secondary.prepend-top-8
= s_('ProjectPage|Project ID: %{project_id}') % { project_id: @project.id }
- if @project.forked?
%p
......
......@@ -14,16 +14,16 @@
.form-group
= f.label :scopes, class: 'label-light'
%fieldset
= f.check_box :read_repository
= label_tag ("deploy_token_read_repository"), 'read_repository'
%span= s_('DeployTokens|Allows read-only access to the repository')
%fieldset.form-group.form-check
= f.check_box :read_repository, class: 'form-check-input'
= label_tag ("deploy_token_read_repository"), 'read_repository', class: 'label-light form-check-label'
.text-secondary= s_('DeployTokens|Allows read-only access to the repository')
- if container_registry_enabled?(project)
%fieldset
= f.check_box :read_registry
= label_tag ("deploy_token_read_registry"), 'read_registry'
%span= s_('DeployTokens|Allows read-only access to the registry images')
%fieldset.form-group.form-check
= f.check_box :read_registry, class: 'form-check-input'
= label_tag ("deploy_token_read_registry"), 'read_registry', class: 'label-light form-check-label'
.text-secondary= s_('DeployTokens|Allows read-only access to the registry images')
.prepend-top-default
= f.submit s_('DeployTokens|Create deploy token'), class: 'btn btn-success'
---
title: Improve feedback when a developer is unable to push to an empty repository
merge_request: 20519
author:
type: changed
---
title: Rework some projects table indexes around repository_storage field
merge_request: 20377
author:
type: fixed
---
title: Fix breadcrumbs in Admin/User interface.
merge_request: 19608
author: Robin Naundorf
type: fixed
---
title: Show Project ID on project home panel
merge_request: 20305
author: Tuğçe Nur Taş
type: added
---
title: Enable more frozen string in app/services/**/*.rb
merge_request: 20677
author: gfyoung
type: performance
---
title: Render MR page when diffs cannot be fetched from the database or the git repository
merge_request: 20680
author:
type: fixed
---
title: "Cleans up display of Deploy Tokens to match Personal Access Tokens"
merge_request: 20578
author: Marcel Amirault
type: added
\ No newline at end of file
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class UpdateProjectIndexes < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
NEW_INDEX_NAME = 'idx_project_repository_check_partial'
disable_ddl_transaction!
def up
add_concurrent_index(:projects,
[:repository_storage, :created_at],
name: NEW_INDEX_NAME,
where: 'last_repository_check_at IS NULL'
)
end
def down
remove_concurrent_index_by_name(:projects, NEW_INDEX_NAME)
end
end
......@@ -2174,6 +2174,7 @@ ActiveRecord::Schema.define(version: 20180704204006) do
add_index "projects", ["path"], name: "index_projects_on_path", using: :btree
add_index "projects", ["path"], name: "index_projects_on_path_trigram", using: :gin, opclasses: {"path"=>"gin_trgm_ops"}
add_index "projects", ["pending_delete"], name: "index_projects_on_pending_delete", using: :btree
add_index "projects", ["repository_storage", "created_at"], name: "idx_project_repository_check_partial", where: "(last_repository_check_at IS NULL)", using: :btree
add_index "projects", ["repository_storage"], name: "index_projects_on_repository_storage", using: :btree
add_index "projects", ["runners_token"], name: "index_projects_on_runners_token", using: :btree
add_index "projects", ["star_count"], name: "index_projects_on_star_count", using: :btree
......
......@@ -64,7 +64,8 @@ Below are the current settings regarding [GitLab CI/CD](../../ci/README.md).
## Repository size limit
The maximum size your Git repository is allowed to be including LFS.
The maximum size your Git repository is allowed to be, including LFS. If you are near
or over the size limit, you can [reduce your repository size with Git](../project/repository/reducing_the_repo_size_using_git.md).
| Setting | GitLab.com | Default |
| ----------- | ----------------- | ------------- |
......
......@@ -95,7 +95,7 @@ module Gitlab
end
else
unless user_access.can_push_to_branch?(branch_name)
raise GitAccess::UnauthorizedError, ERROR_MESSAGES[:push_protected_branch]
raise GitAccess::UnauthorizedError, push_to_protected_branch_rejected_message
end
end
end
......@@ -142,6 +142,29 @@ module Gitlab
private
def push_to_protected_branch_rejected_message
if project.empty_repo?
empty_project_push_message
else
ERROR_MESSAGES[:push_protected_branch]
end
end
def empty_project_push_message
<<~MESSAGE
A default branch (e.g. master) does not yet exist for #{project.full_path}
Ask a project Owner or Maintainer to create a default branch:
#{project_members_url}
MESSAGE
end
def project_members_url
Gitlab::Routing.url_helpers.project_project_members_url(project)
end
def should_run_commit_validations?
commit_check.validate_lfs_file_locks?
end
......
......@@ -4919,6 +4919,9 @@ msgstr ""
msgid "ProjectLifecycle|Stage"
msgstr ""
msgid "ProjectPage|Project ID: %{project_id}"
msgstr ""
msgid "ProjectSettings|Contact an admin to change this setting."
msgstr ""
......
......@@ -53,6 +53,23 @@ describe Projects::MergeRequestsController do
it_behaves_like "loads labels", :show
describe 'as html' do
context 'when diff files were cleaned' do
render_views
it 'renders page when diff size is not persisted and diff_refs does not exist' do
diff = merge_request.merge_request_diff
diff.clean!
diff.update!(real_size: nil,
start_commit_sha: nil,
base_commit_sha: nil)
go(format: :html)
expect(response).to be_success
end
end
it "renders merge request page" do
go(format: :html)
......
......@@ -377,6 +377,40 @@ describe "Admin::Users" do
end
end
describe 'show breadcrumbs' do
it do
visit admin_user_path(user)
check_breadcrumb(user.name)
visit projects_admin_user_path(user)
check_breadcrumb(user.name)
visit keys_admin_user_path(user)
check_breadcrumb(user.name)
visit admin_user_impersonation_tokens_path(user)
check_breadcrumb(user.name)
visit admin_user_identities_path(user)
check_breadcrumb(user.name)
visit new_admin_user_identity_path(user)
check_breadcrumb("New Identity")
visit admin_user_identities_path(user)
find('.table').find(:link, 'Edit').click
check_breadcrumb("Edit Identity")
end
end
describe 'show user attributes' do
it do
visit admin_users_path
......@@ -471,4 +505,8 @@ describe "Admin::Users" do
expect(page).not_to have_content('twitter')
end
end
def check_breadcrumb(content)
expect(find('.breadcrumbs-sub-title')).to have_content(content)
end
end
......@@ -55,6 +55,20 @@ describe SearchHelper do
expect(search_autocomplete_opts(project.name).size).to eq(1)
end
it "includes the required project attrs" do
project = create(:project, namespace: create(:namespace, owner: user))
result = search_autocomplete_opts(project.name).first
expect(result.keys).to match_array(%i[category id value label url avatar_url])
end
it "includes the required group attrs" do
create(:group).add_owner(user)
result = search_autocomplete_opts("gro").first
expect(result.keys).to match_array(%i[category id label url avatar_url])
end
it "does not include the public group" do
group = create(:group)
expect(search_autocomplete_opts(group.name).size).to eq(0)
......
......@@ -86,7 +86,6 @@ describe('Report section', () => {
});
});
});
describe('when it is loading', () => {
it('should render loading indicator', () => {
vm = mountComponent(ReportSection, {
......
......@@ -132,6 +132,16 @@ describe Gitlab::Checks::ChangeAccess do
expect { subject.exec }.to raise_error(Gitlab::GitAccess::UnauthorizedError, 'You are not allowed to push code to protected branches on this project.')
end
context 'when project repository is empty' do
let(:project) { create(:project) }
it 'raises an error if the user is not allowed to push to protected branches' do
expect(user_access).to receive(:can_push_to_branch?).and_return(false)
expect { subject.exec }.to raise_error(Gitlab::GitAccess::UnauthorizedError, /Ask a project Owner or Maintainer to create a default branch/)
end
end
context 'branch deletion' do
let(:newrev) { '0000000000000000000000000000000000000000' }
let(:ref) { 'refs/heads/feature' }
......
......@@ -82,6 +82,14 @@ describe MergeRequestDiff do
diff.diffs
end
it 'returns persisted diffs if diff refs does not exist' do
expect(diff).to receive(:load_diffs)
diff.update!(start_commit_sha: nil, base_commit_sha: nil)
diff.diffs
end
end
end
......
require 'spec_helper'
describe 'projects/_home_panel' do
let(:group) { create(:group) }
let(:project) { create(:project, :public, namespace: group) }
context 'notifications' do
let(:project) { create(:project) }
let(:notification_settings) do
user&.notification_settings_for(project)
end
before do
assign(:project, project)
before do
assign(:project, project)
assign(:notification_setting, notification_settings)
allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:can?).with(user, :read_project, project).and_return(false)
end
allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:can?).and_return(false)
end
context 'when user is signed in' do
let(:user) { create(:user) }
context 'when user is signed in' do
let(:user) { create(:user) }
before do
notification_settings = user.notification_settings_for(project)
assign(:notification_setting, notification_settings)
end
it 'makes it possible to set notification level' do
render
it 'makes it possible to set notification level' do
render
expect(view).to render_template('shared/notifications/_button')
expect(rendered).to have_selector('.notification-dropdown')
expect(view).to render_template('shared/notifications/_button')
expect(rendered).to have_selector('.notification-dropdown')
end
end
end
context 'when user is signed out' do
let(:user) { nil }
it 'is not possible to set notification level' do
render
context 'when user is signed out' do
let(:user) { nil }
expect(rendered).not_to have_selector('.notification_dropdown')
end
end
context 'when project' do
let!(:user) { create(:user) }
let(:badges) { project.badges }
before do
assign(:notification_setting, nil)
end
context 'has no badges' do
it 'should not render any badge' do
it 'is not possible to set notification level' do
render
expect(rendered).to have_selector('.project-badges')
expect(rendered).not_to have_selector('.project-badges > a')
expect(rendered).not_to have_selector('.notification_dropdown')
end
end
end
context 'badges' do
shared_examples 'show badges' do
it 'should render the all badges' do
render
......@@ -62,7 +55,31 @@ describe 'projects/_home_panel' do
end
end
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)
end
context 'has no badges' do
let(:project) { create(:project) }
it 'should not render any badge' do
render
expect(rendered).to have_selector('.project-badges')
expect(rendered).not_to have_selector('.project-badges > a')
end
end
context 'only has group badges' do
let(:group) { create(:group) }
let(:project) { create(:project, namespace: group) }
before do
create(:group_badge, group: project.group)
end
......@@ -71,6 +88,8 @@ describe 'projects/_home_panel' do
end
context 'only has project badges' do
let(:project) { create(:project) }
before do
create(:project_badge, project: project)
end
......@@ -79,6 +98,9 @@ describe 'projects/_home_panel' do
end
context 'has both group and project badges' do
let(:group) { create(:group) }
let(:project) { create(:project, namespace: group) }
before do
create(:project_badge, project: project)
create(:group_badge, group: project.group)
......@@ -87,4 +109,35 @@ describe 'projects/_home_panel' do
it_behaves_like 'show badges'
end
end
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)
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
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment