diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
commit | 0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch) | |
tree | 4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /spec/lib/gitlab/changelog | |
parent | 744144d28e3e7fddc117924fef88de5d9674fe4c (diff) |
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'spec/lib/gitlab/changelog')
-rw-r--r-- | spec/lib/gitlab/changelog/config_spec.rb | 110 | ||||
-rw-r--r-- | spec/lib/gitlab/changelog/release_spec.rb | 24 |
2 files changed, 119 insertions, 15 deletions
diff --git a/spec/lib/gitlab/changelog/config_spec.rb b/spec/lib/gitlab/changelog/config_spec.rb index a464c1e57e5..c410ba4d116 100644 --- a/spec/lib/gitlab/changelog/config_spec.rb +++ b/spec/lib/gitlab/changelog/config_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe Gitlab::Changelog::Config do + include ProjectForksHelper + let(:project) { build_stubbed(:project) } describe '.from_git' do @@ -13,7 +15,7 @@ RSpec.describe Gitlab::Changelog::Config do expect(described_class) .to receive(:from_hash) - .with(project, 'date_format' => '%Y') + .with(project, { 'date_format' => '%Y' }, nil) described_class.from_git(project) end @@ -33,12 +35,25 @@ RSpec.describe Gitlab::Changelog::Config do describe '.from_hash' do it 'sets the configuration according to a Hash' do + user1 = create(:user) + user2 = create(:user) + user3 = create(:user) + group = create(:group, path: 'group') + group2 = create(:group, path: 'group-path') + group.add_developer(user1) + group.add_developer(user2) + group2.add_developer(user3) + config = described_class.from_hash( project, - 'date_format' => 'foo', - 'template' => 'bar', - 'categories' => { 'foo' => 'bar' }, - 'tag_regex' => 'foo' + { + 'date_format' => 'foo', + 'template' => 'bar', + 'categories' => { 'foo' => 'bar' }, + 'tag_regex' => 'foo', + 'include_groups' => %w[group group-path non-existent-group] + }, + user1 ) expect(config.date_format).to eq('foo') @@ -47,6 +62,7 @@ RSpec.describe Gitlab::Changelog::Config do expect(config.categories).to eq({ 'foo' => 'bar' }) expect(config.tag_regex).to eq('foo') + expect(config.always_credit_user_ids).to match_array([user1.id, user2.id, user3.id]) end it 'raises Error when the categories are not a Hash' do @@ -66,20 +82,33 @@ RSpec.describe Gitlab::Changelog::Config do end describe '#contributor?' do - it 'returns true if a user is a contributor' do - user = build_stubbed(:author) + let(:project) { create(:project, :public, :repository) } - allow(project.team).to receive(:contributor?).with(user).and_return(true) - - expect(described_class.new(project).contributor?(user)).to eq(true) - end + context 'when user is a member of project' do + let(:user) { create(:user) } - it "returns true if a user isn't a contributor" do - user = build_stubbed(:author) + before do + project.add_developer(user) + end - allow(project.team).to receive(:contributor?).with(user).and_return(false) + it { expect(described_class.new(project).contributor?(user)).to eq(false) } + end - expect(described_class.new(project).contributor?(user)).to eq(false) + context 'when user has at least one merge request merged into default_branch' do + let(:contributor) { create(:user) } + let(:user_without_access) { create(:user) } + let(:user_fork) { fork_project(project, contributor, repository: true) } + + before do + create(:merge_request, :merged, + author: contributor, + target_project: project, + source_project: user_fork, + target_branch: project.default_branch.to_s) + end + + it { expect(described_class.new(project).contributor?(contributor)).to eq(true) } + it { expect(described_class.new(project).contributor?(user_without_access)).to eq(false) } end end @@ -107,4 +136,55 @@ RSpec.describe Gitlab::Changelog::Config do expect(config.format_date(time)).to eq('2021-01-05') end end + + describe '#always_credit_author?' do + let_it_be(:group_member) { create(:user) } + let_it_be(:non_group_member) { create(:user) } + let_it_be(:group) { create(:group, :private, path: 'group') } + + before do + group.add_developer(group_member) + end + + context 'when include_groups is defined' do + context 'when user generating changelog has access to group' do + it 'returns whether author should always be credited' do + config = described_class.from_hash( + project, + { 'include_groups' => ['group'] }, + group_member + ) + + expect(config.always_credit_author?(group_member)).to eq(true) + expect(config.always_credit_author?(non_group_member)).to eq(false) + end + end + + context 'when user generating changelog has no access to group' do + it 'always returns false' do + config = described_class.from_hash( + project, + { 'include_groups' => ['group'] }, + non_group_member + ) + + expect(config.always_credit_author?(group_member)).to eq(false) + expect(config.always_credit_author?(non_group_member)).to eq(false) + end + end + end + + context 'when include_groups is not defined' do + it 'always returns false' do + config = described_class.from_hash( + project, + {}, + group_member + ) + + expect(config.always_credit_author?(group_member)).to eq(false) + expect(config.always_credit_author?(non_group_member)).to eq(false) + end + end + end end diff --git a/spec/lib/gitlab/changelog/release_spec.rb b/spec/lib/gitlab/changelog/release_spec.rb index f95244d6750..d8434821640 100644 --- a/spec/lib/gitlab/changelog/release_spec.rb +++ b/spec/lib/gitlab/changelog/release_spec.rb @@ -94,6 +94,30 @@ RSpec.describe Gitlab::Changelog::Release do end end + context 'when the author should always be credited' do + it 'includes the author' do + allow(config).to receive(:contributor?).with(author).and_return(false) + allow(config).to receive(:always_credit_author?).with(author).and_return(true) + + release.add_entry( + title: 'Entry title', + commit: commit, + category: 'fixed', + author: author + ) + + expect(release.to_markdown).to eq(<<~OUT) + ## 1.0.0 (2021-01-05) + + ### fixed (1 change) + + - [Entry title](#{commit.to_reference(full: true)}) \ + by #{author.to_reference(full: true)} + + OUT + end + end + context 'when a category has no entries' do it "isn't included in the output" do config.categories['kittens'] = 'Kittens' |