diff --git a/lib/gitlab/changelog/config.rb b/lib/gitlab/changelog/config.rb index 0538fe68474224e4de0e483acd71beae874aa63a..d25094d9b372af56cdf56c5b3de520055e7002e8 100644 --- a/lib/gitlab/changelog/config.rb +++ b/lib/gitlab/changelog/config.rb @@ -89,7 +89,7 @@ def initialize(project) end def contributor?(user) - @project.team.contributor?(user) + @project.team.contributor?(user&.id) end def category(name) diff --git a/spec/lib/gitlab/changelog/config_spec.rb b/spec/lib/gitlab/changelog/config_spec.rb index a464c1e57e5b1347ef2827c84c7c232c4996fb03..ff5a084bb867efac65a7b68a95b4ba5aeb795d62 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 @@ -66,20 +68,33 @@ end describe '#contributor?' do - it 'returns true if a user is a contributor' do - user = build_stubbed(:author) - - allow(project.team).to receive(:contributor?).with(user).and_return(true) + let(:project) { create(:project, :public, :repository) } - 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 diff --git a/spec/services/repositories/changelog_service_spec.rb b/spec/services/repositories/changelog_service_spec.rb index 02d60f076ca85a4fd3d77951aabad3b1725750b5..b547ae17317b93d3327bf3cae357d42ccf196e62 100644 --- a/spec/services/repositories/changelog_service_spec.rb +++ b/spec/services/repositories/changelog_service_spec.rb @@ -76,7 +76,7 @@ recorder = ActiveRecord::QueryRecorder.new { service.execute } changelog = project.repository.blob_at('master', 'CHANGELOG.md')&.data - expect(recorder.count).to eq(11) + expect(recorder.count).to eq(9) expect(changelog).to include('Title 1', 'Title 2') end