From f928dba99b0550cefa7534d7fd5bd1ea16609274 Mon Sep 17 00:00:00 2001 From: hhoopes Date: Thu, 25 Aug 2016 10:38:07 -0600 Subject: Change diff highlight/truncate for reusability Previously the `truncated_diff_lines` method for outputting a discussion diff took in already highlighted lines, which meant it wasn't reuseable for truncating ANY lines. In the way it was used, it also meant that for any email truncation, the whole diff was being highlighted before being truncated, meaning wasted time highlighting lines that wouldn't even be used (granted, they were being memoized, so perhaps this wasn't that great of an issue). I refactored truncation away from highlighting, in order to truncate formatted diffs for text templates in email, using `>`s to designate each line, but otherwise retaining the parsing already done to create `diff_lines`. Additionally, while notes on merge requests or commits had already been tested, there was no existing test for notes on a diff on an MR or commit. Added mailer tests for such, and a unit test for truncating diff lines. --- spec/models/discussion_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'spec/models/discussion_spec.rb') diff --git a/spec/models/discussion_spec.rb b/spec/models/discussion_spec.rb index 0142706d140..d4b1f480c56 100644 --- a/spec/models/discussion_spec.rb +++ b/spec/models/discussion_spec.rb @@ -590,4 +590,29 @@ describe Discussion, model: true do end end end + + describe "#truncated_diff_lines" do + let(:truncated_lines) { subject.truncated_diff_lines } + + context "when diff is greater than allowed number of truncated diff lines " do + let(:initial_line_count) { subject.diff_file.diff_lines.count } + let(:truncated_line_count) { truncated_lines.count } + + it "returns fewer lines" do + expect(initial_line_count).to be > described_class::NUMBER_OF_TRUNCATED_DIFF_LINES + + expect(truncated_line_count).to be <= described_class::NUMBER_OF_TRUNCATED_DIFF_LINES + end + end + + context "when some diff lines are meta" do + let(:initial_meta_lines?) { subject.diff_file.diff_lines.any?(&:meta?) } + let(:truncated_meta_lines?) { truncated_lines.any?(&:meta?) } + + it "returns no meta lines" do + expect(initial_meta_lines?).to be true + expect(truncated_meta_lines?).to be false + end + end + end end -- cgit v1.2.1 From a761c59a6bfc4d66649910d01e4c8412bb0b40ec Mon Sep 17 00:00:00 2001 From: hhoopes Date: Wed, 31 Aug 2016 10:18:26 -0600 Subject: Add keyword arguments to truncated_diff method * Added keyword arguments to truncated_diff_lines method to allow for using highlighting or not (html templates vs. text) * Tweaked templates for consistency and format appropriateness --- spec/models/discussion_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/models/discussion_spec.rb') diff --git a/spec/models/discussion_spec.rb b/spec/models/discussion_spec.rb index d4b1f480c56..187d0bc0150 100644 --- a/spec/models/discussion_spec.rb +++ b/spec/models/discussion_spec.rb @@ -595,7 +595,7 @@ describe Discussion, model: true do let(:truncated_lines) { subject.truncated_diff_lines } context "when diff is greater than allowed number of truncated diff lines " do - let(:initial_line_count) { subject.diff_file.diff_lines.count } + let(:initial_line_count) { subject.diff_lines.count } let(:truncated_line_count) { truncated_lines.count } it "returns fewer lines" do @@ -606,7 +606,7 @@ describe Discussion, model: true do end context "when some diff lines are meta" do - let(:initial_meta_lines?) { subject.diff_file.diff_lines.any?(&:meta?) } + let(:initial_meta_lines?) { subject.diff_lines.any?(&:meta?) } let(:truncated_meta_lines?) { truncated_lines.any?(&:meta?) } it "returns no meta lines" do -- cgit v1.2.1 From b8917eb75e94cb13b02534c920ee926c9e97174e Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Wed, 23 Nov 2016 16:25:31 +0000 Subject: Fix spec style --- spec/models/discussion_spec.rb | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'spec/models/discussion_spec.rb') diff --git a/spec/models/discussion_spec.rb b/spec/models/discussion_spec.rb index 187d0bc0150..2a67c60b978 100644 --- a/spec/models/discussion_spec.rb +++ b/spec/models/discussion_spec.rb @@ -595,23 +595,17 @@ describe Discussion, model: true do let(:truncated_lines) { subject.truncated_diff_lines } context "when diff is greater than allowed number of truncated diff lines " do - let(:initial_line_count) { subject.diff_lines.count } - let(:truncated_line_count) { truncated_lines.count } - it "returns fewer lines" do - expect(initial_line_count).to be > described_class::NUMBER_OF_TRUNCATED_DIFF_LINES + expect(subject.diff_lines.count).to be > described_class::NUMBER_OF_TRUNCATED_DIFF_LINES - expect(truncated_line_count).to be <= described_class::NUMBER_OF_TRUNCATED_DIFF_LINES + expect(truncated_lines.count).to be <= described_class::NUMBER_OF_TRUNCATED_DIFF_LINES end end context "when some diff lines are meta" do - let(:initial_meta_lines?) { subject.diff_lines.any?(&:meta?) } - let(:truncated_meta_lines?) { truncated_lines.any?(&:meta?) } - it "returns no meta lines" do - expect(initial_meta_lines?).to be true - expect(truncated_meta_lines?).to be false + expect(subject.diff_lines).to include(be_meta) + expect(truncated_lines).not_to include(be_meta) end end end -- cgit v1.2.1 From 1123057ab792ac73b1611f4d3a9faf79369dd6da Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Wed, 26 Oct 2016 23:21:50 +0200 Subject: Feature: delegate all open discussions to Issue When a merge request can only be merged when all discussions are resolved. This feature allows to easily delegate those discussions to a new issue, while marking them as resolved in the merge request. The user is presented with a new issue, prepared with mentions of all unresolved discussions, including the first unresolved note of the discussion, time and link to the note. When the issue is created, the discussions in the merge request will get a system note directing the user to the newly created issue. --- spec/models/discussion_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'spec/models/discussion_spec.rb') diff --git a/spec/models/discussion_spec.rb b/spec/models/discussion_spec.rb index 2a67c60b978..bc32fadd391 100644 --- a/spec/models/discussion_spec.rb +++ b/spec/models/discussion_spec.rb @@ -521,6 +521,15 @@ describe Discussion, model: true do end end + describe "#first_note_to_resolve" do + it "returns the first not that still needs to be resolved" do + allow(first_note).to receive(:to_be_resolved?).and_return(false) + allow(second_note).to receive(:to_be_resolved?).and_return(true) + + expect(subject.first_note_to_resolve).to eq(second_note) + end + end + describe "#collapsed?" do context "when a diff discussion" do before do -- cgit v1.2.1