Commit 0242ec77 authored by Michelle Gill's avatar Michelle Gill

Specs for single and multi suggestions based on author

Add documentation
parent b85483e5
---
title: Commit author for suggestions is note author
merge_request: 39940
author:
type: added
......@@ -515,6 +515,9 @@ to your branch to address your reviewers' requests.
![A code change suggestion displayed, with the button to apply the batch of suggestions highlighted.](img/apply_batch_of_suggestions_v13_1.jpg "Apply a batch of suggestions")
WARNING:
Suggestions applied from multiple authors will create a commit authored by the user applying the suggestions.
## Start a thread by replying to a standard comment
> - [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/30299) in GitLab 11.9
......
......@@ -321,6 +321,73 @@ RSpec.describe Suggestions::ApplyService do
end
end
context 'single suggestion' do
let(:author) { suggestions.first.note.author }
let(:commit) { project.repository.commit }
context 'author of suggestion applies suggestion' do
before do
suggestion.note.update!(author_id: user.id)
apply(suggestions)
end
it 'created commit by same author and committer' do
expect(user.commit_email).to eq(author.commit_email)
expect(author).to eq(user)
expect(commit.author_email).to eq(author.commit_email)
expect(commit.committer_email).to eq(user.commit_email)
expect(commit.author_name).to eq(author.name)
expect(commit.committer_name).to eq(user.name)
end
end
context 'another user applies suggestion' do
before do
apply(suggestions)
end
it 'created commit has authors info and commiters info' do
expect(user.commit_email).not_to eq(user.email)
expect(author).not_to eq(user)
expect(commit.author_email).to eq(author.commit_email)
expect(commit.committer_email).to eq(user.commit_email)
expect(commit.author_name).to eq(author.name)
expect(commit.committer_name).to eq(user.name)
end
end
end
context 'multiple suggestions' do
let(:author_emails) { suggestions.map {|s| s.note.author.commit_email } }
let(:first_author) { suggestion.note.author }
let(:commit) { project.repository.commit }
context 'when all the same author' do
before do
apply(suggestions)
end
it 'uses first authors information' do
expect(author_emails).to include(first_author.commit_email).exactly(3)
expect(commit.author_email).to eq(first_author.commit_email)
end
end
context 'when all different authors' do
before do
suggestion2.note.update!(author_id: create(:user).id)
suggestion3.note.update!(author_id: create(:user).id)
apply(suggestions)
end
it 'uses committers information' do
expect(commit.author_email).to eq(user.commit_email)
expect(commit.committer_email).to eq(user.commit_email)
end
end
end
context 'multiple suggestions applied sequentially' do
def apply_suggestion(suggestion)
suggestion.reload
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment