diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-09-18 12:07:52 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-09-18 12:07:52 +0000 |
commit | a2a00a5e6d1ba3d2ebfafcff57e211cb1b65c00a (patch) | |
tree | d6b3b50fe16d2c7125f6a95a651c542cfd2e2d91 /spec | |
parent | 139a14b6dfc9862771d52091d16031f9e03ca192 (diff) | |
parent | 5a883915793f0f89f850d5393dce497ff9c5f893 (diff) | |
download | gitlab-ce-a2a00a5e6d1ba3d2ebfafcff57e211cb1b65c00a.tar.gz |
Merge branch '51564-fix-commit-email-usage' into 'master'
Respect the user commit email in more places
Closes #51564
See merge request gitlab-org/gitlab-ce!21773
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/users.rb | 8 | ||||
-rw-r--r-- | spec/models/project_wiki_spec.rb | 29 | ||||
-rw-r--r-- | spec/services/files/create_service_spec.rb | 16 | ||||
-rw-r--r-- | spec/services/files/delete_service_spec.rb | 11 | ||||
-rw-r--r-- | spec/services/files/update_service_spec.rb | 11 |
5 files changed, 69 insertions, 6 deletions
diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 59db8cdc34b..a47bd7cafca 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -58,6 +58,14 @@ FactoryBot.define do project_view :readme end + trait :commit_email do + after(:create) do |user, evaluator| + additional = create(:email, :confirmed, user: user, email: "commit-#{user.email}") + + user.update!(commit_email: additional.email) + end + end + factory :omniauth_user do transient do extern_uid '123456' diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb index 528f5b610d7..f38fc191943 100644 --- a/spec/models/project_wiki_spec.rb +++ b/spec/models/project_wiki_spec.rb @@ -2,12 +2,13 @@ require "spec_helper" describe ProjectWiki do - let(:project) { create(:project, :wiki_repo) } + let(:user) { create(:user, :commit_email) } + let(:project) { create(:project, :wiki_repo, namespace: user.namespace) } let(:repository) { project.repository } - let(:user) { project.owner } let(:gitlab_shell) { Gitlab::Shell.new } let(:project_wiki) { described_class.new(project, user) } let(:raw_repository) { Gitlab::Git::Repository.new(project.repository_storage, subject.disk_path + '.git', 'foo') } + let(:commit) { project_wiki.repository.head_commit } subject { project_wiki } @@ -276,6 +277,14 @@ describe ProjectWiki do expect(subject.pages.first.page.version.message).to eq("commit message") end + it 'sets the correct commit email' do + subject.create_page('test page', 'content') + + expect(user.commit_email).not_to eq(user.email) + expect(commit.author_email).to eq(user.commit_email) + expect(commit.committer_email).to eq(user.commit_email) + end + it 'updates project activity' do subject.create_page('Test Page', 'This is content') @@ -320,6 +329,12 @@ describe ProjectWiki do expect(@page.version.message).to eq("updated page") end + it 'sets the correct commit email' do + expect(user.commit_email).not_to eq(user.email) + expect(commit.author_email).to eq(user.commit_email) + expect(commit.committer_email).to eq(user.commit_email) + end + it 'updates project activity' do subject.update_page( @gitlab_git_wiki_page, @@ -347,6 +362,14 @@ describe ProjectWiki do expect(subject.pages.count).to eq(0) end + it 'sets the correct commit email' do + subject.delete_page(@page) + + expect(user.commit_email).not_to eq(user.email) + expect(commit.author_email).to eq(user.commit_email) + expect(commit.committer_email).to eq(user.commit_email) + end + it 'updates project activity' do subject.delete_page(@page) @@ -420,7 +443,7 @@ describe ProjectWiki do end def commit_details - Gitlab::Git::Wiki::CommitDetails.new(user.id, user.username, user.name, user.email, "test commit") + Gitlab::Git::Wiki::CommitDetails.new(user.id, user.username, user.name, user.commit_email, "test commit") end def create_page(name, content) diff --git a/spec/services/files/create_service_spec.rb b/spec/services/files/create_service_spec.rb index 30d94e4318d..751b7160276 100644 --- a/spec/services/files/create_service_spec.rb +++ b/spec/services/files/create_service_spec.rb @@ -3,7 +3,7 @@ require "spec_helper" describe Files::CreateService do let(:project) { create(:project, :repository) } let(:repository) { project.repository } - let(:user) { create(:user) } + let(:user) { create(:user, :commit_email) } let(:file_content) { 'Test file content' } let(:branch_name) { project.default_branch } let(:start_branch) { branch_name } @@ -20,6 +20,8 @@ describe Files::CreateService do } end + let(:commit) { repository.head_commit } + subject { described_class.new(project, user, commit_params) } before do @@ -75,4 +77,16 @@ describe Files::CreateService do end end end + + context 'commit attribute' do + let(:file_path) { 'test-commit-attributes.txt' } + + it 'uses the commit email' do + subject.execute + + expect(user.commit_email).not_to eq(user.email) + expect(commit.author_email).to eq(user.commit_email) + expect(commit.committer_email).to eq(user.commit_email) + end + end end diff --git a/spec/services/files/delete_service_spec.rb b/spec/services/files/delete_service_spec.rb index 73566afe8c8..309802ce733 100644 --- a/spec/services/files/delete_service_spec.rb +++ b/spec/services/files/delete_service_spec.rb @@ -4,10 +4,11 @@ describe Files::DeleteService do subject { described_class.new(project, user, commit_params) } let(:project) { create(:project, :repository) } - let(:user) { create(:user) } + let(:user) { create(:user, :commit_email) } let(:file_path) { 'files/ruby/popen.rb' } let(:branch_name) { project.default_branch } let(:last_commit_sha) { nil } + let(:commit) { project.repository.head_commit } let(:commit_params) do { @@ -34,6 +35,14 @@ describe Files::DeleteService do expect(blob).to be_nil end + + it 'uses the commit email' do + subject.execute + + expect(user.commit_email).not_to eq(user.email) + expect(commit.author_email).to eq(user.commit_email) + expect(commit.committer_email).to eq(user.commit_email) + end end before do diff --git a/spec/services/files/update_service_spec.rb b/spec/services/files/update_service_spec.rb index e01fe487ffa..23db35c2418 100644 --- a/spec/services/files/update_service_spec.rb +++ b/spec/services/files/update_service_spec.rb @@ -4,11 +4,12 @@ describe Files::UpdateService do subject { described_class.new(project, user, commit_params) } let(:project) { create(:project, :repository) } - let(:user) { create(:user) } + let(:user) { create(:user, :commit_email) } let(:file_path) { 'files/ruby/popen.rb' } let(:new_contents) { 'New Content' } let(:branch_name) { project.default_branch } let(:last_commit_sha) { nil } + let(:commit) { project.repository.commit } let(:commit_params) do { @@ -54,6 +55,14 @@ describe Files::UpdateService do expect(results.data).to eq(new_contents) end + + it 'uses the commit email' do + subject.execute + + expect(user.commit_email).not_to eq(user.email) + expect(commit.author_email).to eq(user.commit_email) + expect(commit.committer_email).to eq(user.commit_email) + end end context "when the last_commit_sha is not supplied" do |