diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-02 00:10:20 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-02 00:10:20 +0300 |
commit | cc77bdd6f5f12bea0f50064f3feadcd9c87009a6 (patch) | |
tree | b9347c56663684eaa5939984c9a604dc767f214e /spec/models | |
parent | 9cf7b70ac7b17ea3310ebdf83e94d1d5fd248b82 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/concerns/milestoneable_spec.rb | 25 | ||||
-rw-r--r-- | spec/models/project_setting_spec.rb | 26 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 58 | ||||
-rw-r--r-- | spec/models/work_item_spec.rb | 25 |
4 files changed, 123 insertions, 11 deletions
diff --git a/spec/models/concerns/milestoneable_spec.rb b/spec/models/concerns/milestoneable_spec.rb index 961eac4710d..cbb0cbf063f 100644 --- a/spec/models/concerns/milestoneable_spec.rb +++ b/spec/models/concerns/milestoneable_spec.rb @@ -3,13 +3,14 @@ require 'spec_helper' RSpec.describe Milestoneable do - let(:user) { create(:user) } - let(:milestone) { create(:milestone, project: project) } + let_it_be(:group, reload: true) { create(:group) } + let_it_be(:project) { create(:project, :repository, group: group) } + let_it_be(:user) { create(:user) } + let_it_be(:milestone) { create(:milestone, project: project) } shared_examples_for 'an object that can be assigned a milestone' do describe 'Validation' do describe 'milestone' do - let(:project) { create(:project, :repository) } let(:milestone_id) { milestone.id } subject { milestoneable_class.new(params) } @@ -39,8 +40,6 @@ RSpec.describe Milestoneable do end describe '#milestone_available?' do - let(:group) { create(:group) } - let(:project) { create(:project, group: group) } let(:issue) { create(:issue, project: project) } def build_milestoneable(milestone_id) @@ -62,9 +61,9 @@ RSpec.describe Milestoneable do it 'returns true with a milestone from the the parent of the issue project group' do parent = create(:group) group.update!(parent: parent) - milestone = create(:milestone, group: parent) + parent_milestone = create(:milestone, group: parent) - expect(build_milestoneable(milestone.id).milestone_available?).to be(true) + expect(build_milestoneable(parent_milestone.id).milestone_available?).to be(true) end it 'returns true with a blank milestone' do @@ -86,9 +85,6 @@ RSpec.describe Milestoneable do end describe '#supports_milestone?' do - let(:group) { create(:group) } - let(:project) { create(:project, group: group) } - context "for issues" do let(:issue) { build(:issue, project: project) } @@ -215,6 +211,15 @@ RSpec.describe Milestoneable do end it_behaves_like 'an object that can be assigned a milestone' + + describe '#milestone_available?' do + it 'returns true with a milestone from the issue group' do + milestone = create(:milestone, group: group) + milestoneable = milestoneable_class.new(namespace: group, milestone_id: milestone.id) + + expect(milestoneable.milestone_available?).to be_truthy + end + end end context 'MergeRequests' do diff --git a/spec/models/project_setting_spec.rb b/spec/models/project_setting_spec.rb index ba737813859..3b890e75064 100644 --- a/spec/models/project_setting_spec.rb +++ b/spec/models/project_setting_spec.rb @@ -76,12 +76,36 @@ RSpec.describe ProjectSetting, type: :model, feature_category: :groups_and_proje expect(project_setting).not_to be_valid expect(project_setting.errors.full_messages).to include("Pages unique domain has already been taken") end + + it "validates if the pages_unique_domain already exist as a project path" do + stub_pages_setting(host: 'example.com') + + create(:project, path: "random-unique-domain.example.com") + project_setting = build(:project_setting, pages_unique_domain: "random-unique-domain") + + expect(project_setting).not_to be_valid + expect(project_setting.errors.full_messages_for(:pages_unique_domain)) + .to match(["Pages unique domain already in use"]) + end + + context "when updating" do + it "validates if the pages_unique_domain already exist as a project path" do + stub_pages_setting(host: 'example.com') + project_setting = create(:project_setting) + + create(:project, path: "random-unique-domain.example.com") + + expect(project_setting.update(pages_unique_domain: "random-unique-domain")).to eq(false) + expect(project_setting.errors.full_messages_for(:pages_unique_domain)) + .to match(["Pages unique domain already in use"]) + end + end end describe 'target_platforms=' do it 'stringifies and sorts' do project_setting = build(:project_setting, target_platforms: [:watchos, :ios]) - expect(project_setting.target_platforms).to eq %w(ios watchos) + expect(project_setting.target_platforms).to eq %w[ios watchos] end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index c9336dd04df..82cefc1a95c 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -828,6 +828,37 @@ RSpec.describe Project, factory_default: :keep, feature_category: :groups_and_pr expect(project).to be_valid end + context 'when validating if path already exist as pages unique domain' do + before do + stub_pages_setting(host: 'example.com') + end + + it 'rejects paths that match pages unique domain' do + create(:project_setting, pages_unique_domain: 'some-unique-domain') + + project = build(:project, path: 'some-unique-domain.example.com') + + expect(project).not_to be_valid + expect(project.errors.full_messages_for(:path)).to match(['Path already in use']) + end + + it 'accepts path when the host does not match' do + create(:project_setting, pages_unique_domain: 'some-unique-domain') + + project = build(:project, path: 'some-unique-domain.another-example.com') + + expect(project).to be_valid + end + + it 'accepts path when the domain does not match' do + create(:project_setting, pages_unique_domain: 'another-unique-domain') + + project = build(:project, path: 'some-unique-domain.example.com') + + expect(project).to be_valid + end + end + context 'path is unchanged' do let_it_be(:invalid_path_project) do project = create(:project, :repository, :public) @@ -4696,6 +4727,33 @@ RSpec.describe Project, factory_default: :keep, feature_category: :groups_and_pr project.update!(visibility_level: Gitlab::VisibilityLevel::INTERNAL) end + context 'when validating if path already exist as pages unique domain' do + before do + stub_pages_setting(host: 'example.com') + end + + it 'rejects paths that match pages unique domain' do + stub_pages_setting(host: 'example.com') + create(:project_setting, pages_unique_domain: 'some-unique-domain') + + expect(project.update(path: 'some-unique-domain.example.com')).to eq(false) + expect(project.errors.full_messages_for(:path)).to match(['Path already in use']) + end + + it 'accepts path when the host does not match' do + create(:project_setting, pages_unique_domain: 'some-unique-domain') + + expect(project.update(path: 'some-unique-domain.another-example.com')).to eq(true) + end + + it 'accepts path when the domain does not match' do + stub_pages_setting(host: 'example.com') + create(:project_setting, pages_unique_domain: 'another-unique-domain') + + expect(project.update(path: 'some-unique-domain.example.com')).to eq(true) + end + end + it 'does not validate the visibility' do expect(project).not_to receive(:visibility_level_allowed_as_fork).and_call_original expect(project).not_to receive(:visibility_level_allowed_by_group).and_call_original diff --git a/spec/models/work_item_spec.rb b/spec/models/work_item_spec.rb index 7963c0898b3..541199e08cb 100644 --- a/spec/models/work_item_spec.rb +++ b/spec/models/work_item_spec.rb @@ -79,6 +79,31 @@ RSpec.describe WorkItem, feature_category: :portfolio_management do end end + describe '.in_namespaces' do + let(:group) { create(:group) } + let!(:group_work_item) { create(:work_item, namespace: group) } + let!(:project_work_item) { create(:work_item, project: reusable_project) } + + subject { described_class.in_namespaces(group) } + + it { is_expected.to contain_exactly(group_work_item) } + end + + describe '.with_confidentiality_check' do + let(:user) { create(:user) } + let!(:authored_work_item) { create(:work_item, :confidential, project: reusable_project, author: user) } + let!(:assigned_work_item) { create(:work_item, :confidential, project: reusable_project, assignees: [user]) } + let!(:public_work_item) { create(:work_item, project: reusable_project) } + + before do + create(:work_item, :confidential, project: reusable_project) + end + + subject { described_class.with_confidentiality_check(user) } + + it { is_expected.to contain_exactly(public_work_item, authored_work_item, assigned_work_item) } + end + describe '#noteable_target_type_name' do it 'returns `issue` as the target name' do work_item = build(:work_item) |