Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/group_spec.rb26
-rw-r--r--spec/models/notification_recipient_spec.rb44
-rw-r--r--spec/models/project_auto_devops_spec.rb121
-rw-r--r--spec/models/project_services/jira_service_spec.rb19
-rw-r--r--spec/models/project_spec.rb2
-rw-r--r--spec/models/user_spec.rb2
6 files changed, 210 insertions, 4 deletions
diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb
index f83b52e8975..9fe1186a8c9 100644
--- a/spec/models/group_spec.rb
+++ b/spec/models/group_spec.rb
@@ -67,6 +67,30 @@ describe Group do
end
end
+ describe '#notification_settings', :nested_groups do
+ let(:user) { create(:user) }
+ let(:group) { create(:group) }
+ let(:sub_group) { create(:group, parent_id: group.id) }
+
+ before do
+ group.add_developer(user)
+ sub_group.add_developer(user)
+ end
+
+ it 'also gets notification settings from parent groups' do
+ expect(sub_group.notification_settings.size).to eq(2)
+ expect(sub_group.notification_settings).to include(group.notification_settings.first)
+ end
+
+ context 'when sub group is deleted' do
+ it 'does not delete parent notification settings' do
+ expect do
+ sub_group.destroy
+ end.to change { NotificationSetting.count }.by(-1)
+ end
+ end
+ end
+
describe '#visibility_level_allowed_by_parent' do
let(:parent) { create(:group, :internal) }
let(:sub_group) { build(:group, parent_id: parent.id) }
@@ -240,7 +264,7 @@ describe Group do
it "is false if avatar is html page" do
group.update_attribute(:avatar, 'uploads/avatar.html')
- expect(group.avatar_type).to eq(["file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff"])
+ expect(group.avatar_type).to eq(["file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff, ico"])
end
end
diff --git a/spec/models/notification_recipient_spec.rb b/spec/models/notification_recipient_spec.rb
index eda0e1da835..13fe47799ed 100644
--- a/spec/models/notification_recipient_spec.rb
+++ b/spec/models/notification_recipient_spec.rb
@@ -13,4 +13,48 @@ describe NotificationRecipient do
expect(recipient.has_access?).to be_falsy
end
+
+ context '#notification_setting' do
+ context 'for child groups', :nested_groups do
+ let!(:moved_group) { create(:group) }
+ let(:group) { create(:group) }
+ let(:sub_group_1) { create(:group, parent: group) }
+ let(:sub_group_2) { create(:group, parent: sub_group_1) }
+ let(:project) { create(:project, namespace: moved_group) }
+
+ before do
+ sub_group_2.add_owner(user)
+ moved_group.add_owner(user)
+ Groups::TransferService.new(moved_group, user).execute(sub_group_2)
+
+ moved_group.reload
+ end
+
+ context 'when notification setting is global' do
+ before do
+ user.notification_settings_for(group).global!
+ user.notification_settings_for(sub_group_1).mention!
+ user.notification_settings_for(sub_group_2).global!
+ user.notification_settings_for(moved_group).global!
+ end
+
+ it 'considers notification setting from the first parent without global setting' do
+ expect(subject.notification_setting.source).to eq(sub_group_1)
+ end
+ end
+
+ context 'when notification setting is not global' do
+ before do
+ user.notification_settings_for(group).global!
+ user.notification_settings_for(sub_group_1).mention!
+ user.notification_settings_for(sub_group_2).watch!
+ user.notification_settings_for(moved_group).disabled!
+ end
+
+ it 'considers notification setting from lowest group member in hierarchy' do
+ expect(subject.notification_setting.source).to eq(moved_group)
+ end
+ end
+ end
+ end
end
diff --git a/spec/models/project_auto_devops_spec.rb b/spec/models/project_auto_devops_spec.rb
index 7545c0797e9..749b2094787 100644
--- a/spec/models/project_auto_devops_spec.rb
+++ b/spec/models/project_auto_devops_spec.rb
@@ -5,6 +5,8 @@ describe ProjectAutoDevops do
it { is_expected.to belong_to(:project) }
+ it { is_expected.to define_enum_for(:deploy_strategy) }
+
it { is_expected.to respond_to(:created_at) }
it { is_expected.to respond_to(:updated_at) }
@@ -67,8 +69,127 @@ describe ProjectAutoDevops do
end
end
+ context 'when deploy_strategy is manual' do
+ let(:domain) { 'example.com' }
+
+ before do
+ auto_devops.deploy_strategy = 'manual'
+ end
+
+ it do
+ expect(auto_devops.predefined_variables.map { |var| var[:key] })
+ .to include("STAGING_ENABLED", "INCREMENTAL_ROLLOUT_ENABLED")
+ end
+ end
+
+ context 'when deploy_strategy is continuous' do
+ let(:domain) { 'example.com' }
+
+ before do
+ auto_devops.deploy_strategy = 'continuous'
+ end
+
+ it do
+ expect(auto_devops.predefined_variables.map { |var| var[:key] })
+ .not_to include("STAGING_ENABLED", "INCREMENTAL_ROLLOUT_ENABLED")
+ end
+ end
+
def domain_variable
{ key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true }
end
end
+
+ describe '#set_gitlab_deploy_token' do
+ let(:auto_devops) { build(:project_auto_devops, project: project) }
+
+ context 'when the project is public' do
+ let(:project) { create(:project, :repository, :public) }
+
+ it 'should not create a gitlab deploy token' do
+ expect do
+ auto_devops.save
+ end.not_to change { DeployToken.count }
+ end
+ end
+
+ context 'when the project is internal' do
+ let(:project) { create(:project, :repository, :internal) }
+
+ it 'should create a gitlab deploy token' do
+ expect do
+ auto_devops.save
+ end.to change { DeployToken.count }.by(1)
+ end
+ end
+
+ context 'when the project is private' do
+ let(:project) { create(:project, :repository, :private) }
+
+ it 'should create a gitlab deploy token' do
+ expect do
+ auto_devops.save
+ end.to change { DeployToken.count }.by(1)
+ end
+ end
+
+ context 'when autodevops is enabled at project level' do
+ let(:project) { create(:project, :repository, :internal) }
+ let(:auto_devops) { build(:project_auto_devops, project: project) }
+
+ it 'should create a deploy token' do
+ expect do
+ auto_devops.save
+ end.to change { DeployToken.count }.by(1)
+ end
+ end
+
+ context 'when autodevops is enabled at instancel level' do
+ let(:project) { create(:project, :repository, :internal) }
+ let(:auto_devops) { build(:project_auto_devops, :disabled, project: project) }
+
+ it 'should create a deploy token' do
+ allow(Gitlab::CurrentSettings).to receive(:auto_devops_enabled?).and_return(true)
+
+ expect do
+ auto_devops.save
+ end.to change { DeployToken.count }.by(1)
+ end
+ end
+
+ context 'when autodevops is disabled' do
+ let(:project) { create(:project, :repository, :internal) }
+ let(:auto_devops) { build(:project_auto_devops, :disabled, project: project) }
+
+ it 'should not create a deploy token' do
+ expect do
+ auto_devops.save
+ end.not_to change { DeployToken.count }
+ end
+ end
+
+ context 'when the project already has an active gitlab-deploy-token' do
+ let(:project) { create(:project, :repository, :internal) }
+ let!(:deploy_token) { create(:deploy_token, :gitlab_deploy_token, projects: [project]) }
+ let(:auto_devops) { build(:project_auto_devops, project: project) }
+
+ it 'should not create a deploy token' do
+ expect do
+ auto_devops.save
+ end.not_to change { DeployToken.count }
+ end
+ end
+
+ context 'when the project already has a revoked gitlab-deploy-token' do
+ let(:project) { create(:project, :repository, :internal) }
+ let!(:deploy_token) { create(:deploy_token, :gitlab_deploy_token, :expired, projects: [project]) }
+ let(:auto_devops) { build(:project_auto_devops, project: project) }
+
+ it 'should not create a deploy token' do
+ expect do
+ auto_devops.save
+ end.not_to change { DeployToken.count }
+ end
+ end
+ end
end
diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb
index 54ef0be67ff..c3b4eb17a5c 100644
--- a/spec/models/project_services/jira_service_spec.rb
+++ b/spec/models/project_services/jira_service_spec.rb
@@ -2,6 +2,7 @@ require 'spec_helper'
describe JiraService do
include Gitlab::Routing
+ include AssetsHelpers
describe '#options' do
let(:service) do
@@ -164,6 +165,8 @@ describe JiraService do
it "creates Remote Link reference in JIRA for comment" do
@jira_service.close_issue(merge_request, ExternalIssue.new("JIRA-123", project))
+ favicon_path = "http://localhost/assets/#{find_asset('favicon.png').digest_path}"
+
# Creates comment
expect(WebMock).to have_requested(:post, @comment_url)
# Creates Remote Link in JIRA issue fields
@@ -173,7 +176,7 @@ describe JiraService do
object: {
url: "#{Gitlab.config.gitlab.url}/#{project.full_path}/commit/#{merge_request.diff_head_sha}",
title: "GitLab: Solved by commit #{merge_request.diff_head_sha}.",
- icon: { title: "GitLab", url16x16: "http://localhost/favicon.ico" },
+ icon: { title: "GitLab", url16x16: favicon_path },
status: { resolved: true }
}
)
@@ -464,4 +467,18 @@ describe JiraService do
end
end
end
+
+ describe 'favicon urls', :request_store do
+ it 'includes the standard favicon' do
+ props = described_class.new.send(:build_remote_link_props, url: 'http://example.com', title: 'title')
+ expect(props[:object][:icon][:url16x16]).to match %r{^http://localhost/assets/favicon(?:-\h+).png$}
+ end
+
+ it 'includes returns the custom favicon' do
+ create :appearance, favicon: fixture_file_upload(Rails.root.join('spec/fixtures/dk.png'))
+
+ props = described_class.new.send(:build_remote_link_props, url: 'http://example.com', title: 'title')
+ expect(props[:object][:icon][:url16x16]).to match %r{^http://localhost/uploads/-/system/appearance/favicon/\d+/favicon_main_dk.png$}
+ end
+ end
end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 52fc7423c26..1a6ad3edd78 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -960,7 +960,7 @@ describe Project do
it 'is false if avatar is html page' do
project.update_attribute(:avatar, 'uploads/avatar.html')
- expect(project.avatar_type).to eq(['file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff'])
+ expect(project.avatar_type).to eq(['file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff, ico'])
end
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 09dfeae6377..097144d04ce 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -1260,7 +1260,7 @@ describe User do
it 'is false if avatar is html page' do
user.update_attribute(:avatar, 'uploads/avatar.html')
- expect(user.avatar_type).to eq(['file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff'])
+ expect(user.avatar_type).to eq(['file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff, ico'])
end
end