summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/suggestions/suggestion_set_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/suggestions/suggestion_set_spec.rb')
-rw-r--r--spec/lib/gitlab/suggestions/suggestion_set_spec.rb116
1 files changed, 66 insertions, 50 deletions
diff --git a/spec/lib/gitlab/suggestions/suggestion_set_spec.rb b/spec/lib/gitlab/suggestions/suggestion_set_spec.rb
index 54d79a9d4ba..469646986e1 100644
--- a/spec/lib/gitlab/suggestions/suggestion_set_spec.rb
+++ b/spec/lib/gitlab/suggestions/suggestion_set_spec.rb
@@ -3,6 +3,9 @@
require 'spec_helper'
RSpec.describe Gitlab::Suggestions::SuggestionSet do
+ include ProjectForksHelper
+ using RSpec::Parameterized::TableSyntax
+
def create_suggestion(file_path, new_line, to_content)
position = Gitlab::Diff::Position.new(old_path: file_path,
new_path: file_path,
@@ -24,86 +27,99 @@ RSpec.describe Gitlab::Suggestions::SuggestionSet do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:forked_project) { fork_project(project, nil, repository: true) }
- let_it_be(:merge_request) do
+ let_it_be(:merge_request_same_project) do
create(:merge_request, source_project: project, target_project: project)
end
- let_it_be(:suggestion) { create(:suggestion)}
-
- let_it_be(:suggestion2) do
- create_suggestion('files/ruby/popen.rb', 13, "*** SUGGESTION 2 ***")
- end
-
- let_it_be(:suggestion3) do
- create_suggestion('files/ruby/regex.rb', 22, "*** SUGGESTION 3 ***")
+ let_it_be(:merge_request_from_fork) do
+ create(:merge_request, source_project: forked_project, target_project: project)
end
- let_it_be(:unappliable_suggestion) { create(:suggestion, :unappliable) }
+ where(:merge_request) { [ref(:merge_request_same_project), ref(:merge_request_from_fork)] }
+ with_them do
+ let(:note) { create(:diff_note_on_merge_request, project: project, noteable: merge_request) }
+ let(:suggestion) { create(:suggestion, note: note) }
- let(:suggestion_set) { described_class.new([suggestion]) }
-
- describe '#project' do
- it 'returns the project associated with the suggestions' do
- expected_project = suggestion.project
+ let(:suggestion2) do
+ create_suggestion('files/ruby/popen.rb', 13, "*** SUGGESTION 2 ***")
+ end
- expect(suggestion_set.project).to be(expected_project)
+ let(:suggestion3) do
+ create_suggestion('files/ruby/regex.rb', 22, "*** SUGGESTION 3 ***")
end
- end
- describe '#branch' do
- it 'returns the branch associated with the suggestions' do
- expected_branch = suggestion.branch
+ let(:unappliable_suggestion) { create(:suggestion, :unappliable) }
+
+ let(:suggestion_set) { described_class.new([suggestion]) }
- expect(suggestion_set.branch).to be(expected_branch)
+ describe '#source_project' do
+ it 'returns the source project associated with the suggestions' do
+ expect(suggestion_set.source_project).to be(merge_request.source_project)
+ end
end
- end
- describe '#valid?' do
- it 'returns true if no errors are found' do
- expect(suggestion_set.valid?).to be(true)
+ describe '#target_project' do
+ it 'returns the target project associated with the suggestions' do
+ expect(suggestion_set.target_project).to be(project)
+ end
end
- it 'returns false if an error is found' do
- suggestion_set = described_class.new([unappliable_suggestion])
+ describe '#branch' do
+ it 'returns the branch associated with the suggestions' do
+ expected_branch = suggestion.branch
- expect(suggestion_set.valid?).to be(false)
+ expect(suggestion_set.branch).to be(expected_branch)
+ end
end
- end
- describe '#error_message' do
- it 'returns an error message if an error is found' do
- suggestion_set = described_class.new([unappliable_suggestion])
+ describe '#valid?' do
+ it 'returns true if no errors are found' do
+ expect(suggestion_set.valid?).to be(true)
+ end
- expect(suggestion_set.error_message).to be_a(String)
+ it 'returns false if an error is found' do
+ suggestion_set = described_class.new([unappliable_suggestion])
+
+ expect(suggestion_set.valid?).to be(false)
+ end
end
- it 'returns nil if no errors are found' do
- expect(suggestion_set.error_message).to be(nil)
+ describe '#error_message' do
+ it 'returns an error message if an error is found' do
+ suggestion_set = described_class.new([unappliable_suggestion])
+
+ expect(suggestion_set.error_message).to be_a(String)
+ end
+
+ it 'returns nil if no errors are found' do
+ expect(suggestion_set.error_message).to be(nil)
+ end
end
- end
- describe '#actions' do
- it 'returns an array of hashes with proper key/value pairs' do
- first_action = suggestion_set.actions.first
+ describe '#actions' do
+ it 'returns an array of hashes with proper key/value pairs' do
+ first_action = suggestion_set.actions.first
- file_suggestion = suggestion_set.send(:suggestions_per_file).first
+ file_suggestion = suggestion_set.send(:suggestions_per_file).first
- expect(first_action[:action]).to be('update')
- expect(first_action[:file_path]).to eq(file_suggestion.file_path)
- expect(first_action[:content]).to eq(file_suggestion.new_content)
+ expect(first_action[:action]).to be('update')
+ expect(first_action[:file_path]).to eq(file_suggestion.file_path)
+ expect(first_action[:content]).to eq(file_suggestion.new_content)
+ end
end
- end
- describe '#file_paths' do
- it 'returns an array of unique file paths associated with the suggestions' do
- suggestion_set = described_class.new([suggestion, suggestion2, suggestion3])
+ describe '#file_paths' do
+ it 'returns an array of unique file paths associated with the suggestions' do
+ suggestion_set = described_class.new([suggestion, suggestion2, suggestion3])
- expected_paths = %w(files/ruby/popen.rb files/ruby/regex.rb)
+ expected_paths = %w(files/ruby/popen.rb files/ruby/regex.rb)
- actual_paths = suggestion_set.file_paths
+ actual_paths = suggestion_set.file_paths
- expect(actual_paths.sort).to eq(expected_paths)
+ expect(actual_paths.sort).to eq(expected_paths)
+ end
end
end
end