summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOswaldo Ferreira <oswaldo@gitlab.com>2018-11-28 19:08:42 -0200
committerjerasmus <jerasmus@gitlab.com>2018-11-29 11:25:35 +0200
commit5390f67f78fb412ab3d68b7829bcd9ac1d940f24 (patch)
tree92eec2850930c3f01075896b886ea36af48af96b
parent2841ccc7dfbcddaf3c26830c26478253a4d2f5a6 (diff)
downloadgitlab-ce-suggest-diff-lines-merge.tar.gz
Introduce feature flagsuggest-diff-lines-merge
-rw-r--r--app/controllers/projects/application_controller.rb4
-rw-r--r--app/models/suggestion.rb8
-rw-r--r--lib/banzai/filter/suggestion_filter.rb2
-rw-r--r--spec/lib/banzai/filter/suggestion_filter_spec.rb11
-rw-r--r--spec/models/suggestion_spec.rb8
5 files changed, 33 insertions, 0 deletions
diff --git a/app/controllers/projects/application_controller.rb b/app/controllers/projects/application_controller.rb
index e0677ce3fbc..67b38582c9f 100644
--- a/app/controllers/projects/application_controller.rb
+++ b/app/controllers/projects/application_controller.rb
@@ -6,6 +6,10 @@ class Projects::ApplicationController < ApplicationController
include ProjectUnauthorized
include ChecksCollaboration
+ before_action do
+ push_frontend_feature_flag(Suggestion::FEATURE_FLAG)
+ end
+
skip_before_action :authenticate_user!
before_action :project
before_action :repository
diff --git a/app/models/suggestion.rb b/app/models/suggestion.rb
index 326a9f83a65..e721c5d3639 100644
--- a/app/models/suggestion.rb
+++ b/app/models/suggestion.rb
@@ -1,11 +1,17 @@
# frozen_string_literal: true
class Suggestion < ApplicationRecord
+ FEATURE_FLAG = :diff_suggestions
+
belongs_to :diff_note, inverse_of: :suggestions
validates :diff_note, presence: true
delegate :project, :position, :diff_file, :noteable, to: :diff_note
+ def self.feature_enabled?
+ Feature.enabled?(FEATURE_FLAG)
+ end
+
def from_line
position.new_line
end
@@ -19,6 +25,8 @@ class Suggestion < ApplicationRecord
alias_method :to_line_index, :from_line_index
def appliable?
+ return false unless self.class.feature_enabled?
+
!applied? &&
diff_note.active? &&
diff_file.new_blob &&
diff --git a/lib/banzai/filter/suggestion_filter.rb b/lib/banzai/filter/suggestion_filter.rb
index 7c6d8eef942..22cb41391ec 100644
--- a/lib/banzai/filter/suggestion_filter.rb
+++ b/lib/banzai/filter/suggestion_filter.rb
@@ -7,6 +7,8 @@ module Banzai
TAG_CLASS = 'js-render-suggestion'.freeze
def call
+ return doc unless Suggestion.feature_enabled?
+
doc.search('pre.suggestion > code').each do |node|
node.add_class(TAG_CLASS)
end
diff --git a/spec/lib/banzai/filter/suggestion_filter_spec.rb b/spec/lib/banzai/filter/suggestion_filter_spec.rb
index 2b1c42f846c..2d3b1297e2c 100644
--- a/spec/lib/banzai/filter/suggestion_filter_spec.rb
+++ b/spec/lib/banzai/filter/suggestion_filter_spec.rb
@@ -13,4 +13,15 @@ describe Banzai::Filter::SuggestionFilter do
expect(result[:class]).to include('js-render-suggestion')
end
+
+ it 'includes no `js-render-suggestion` when feature disabled' do
+ stub_feature_flags(diff_suggestions: false)
+
+ input = "<pre class='code highlight js-syntax-highlight suggestion'><code>foo\n</code></pre>"
+
+ doc = filter(input)
+ result = doc.css('code').first
+
+ expect(result[:class]).to be_nil
+ end
end
diff --git a/spec/models/suggestion_spec.rb b/spec/models/suggestion_spec.rb
index ea1135c64cf..ae2f851a936 100644
--- a/spec/models/suggestion_spec.rb
+++ b/spec/models/suggestion_spec.rb
@@ -14,6 +14,14 @@ describe Suggestion do
end
describe '#appliable?' do
+ context 'when feature is disabled' do
+ it 'returns false' do
+ stub_feature_flags(Suggestion::FEATURE_FLAG => false)
+
+ expect(suggestion).not_to be_appliable
+ end
+ end
+
context 'when new blob does not exists' do
it 'returns false' do
expect_next_instance_of(DiffNote) do |diff_note|