Commit aae03f0e authored by Thomas Randolph's avatar Thomas Randolph Committed by Mayra Cabrera

Pass project into predicates for feature flags

We've added a pair of feature flag checks that are gated on project, but
in order to get at the project object. we have to go through the
diff_file object because of the Grape abstractions in play..
parent 706d0904
...@@ -53,7 +53,7 @@ class DiffFileEntity < DiffFileBaseEntity ...@@ -53,7 +53,7 @@ class DiffFileEntity < DiffFileBaseEntity
end end
# Used for inline diffs # Used for inline diffs
expose :highlighted_diff_lines, using: DiffLineEntity, if: -> (diff_file, options) { inline_diff_view?(options) && diff_file.text? } do |diff_file| expose :highlighted_diff_lines, using: DiffLineEntity, if: -> (diff_file, options) { inline_diff_view?(options, diff_file) && diff_file.text? } do |diff_file|
diff_file.diff_lines_for_serializer diff_file.diff_lines_for_serializer
end end
...@@ -62,19 +62,19 @@ class DiffFileEntity < DiffFileBaseEntity ...@@ -62,19 +62,19 @@ class DiffFileEntity < DiffFileBaseEntity
end end
# Used for parallel diffs # Used for parallel diffs
expose :parallel_diff_lines, using: DiffLineParallelEntity, if: -> (diff_file, options) { parallel_diff_view?(options) && diff_file.text? } expose :parallel_diff_lines, using: DiffLineParallelEntity, if: -> (diff_file, options) { parallel_diff_view?(options, diff_file) && diff_file.text? }
private private
def parallel_diff_view?(options) def parallel_diff_view?(options, diff_file)
return true unless Feature.enabled?(:single_mr_diff_view) return true unless Feature.enabled?(:single_mr_diff_view, diff_file.repository.project)
# If we're not rendering inline, we must be rendering parallel # If we're not rendering inline, we must be rendering parallel
!inline_diff_view?(options) !inline_diff_view?(options, diff_file)
end end
def inline_diff_view?(options) def inline_diff_view?(options, diff_file)
return true unless Feature.enabled?(:single_mr_diff_view) return true unless Feature.enabled?(:single_mr_diff_view, diff_file.repository.project)
# If nothing is present, inline will be the default. # If nothing is present, inline will be the default.
options.fetch(:diff_view, :inline).to_sym == :inline options.fetch(:diff_view, :inline).to_sym == :inline
......
...@@ -20,7 +20,7 @@ describe 'a maintainer edits files on a source-branch of an MR from a fork', :js ...@@ -20,7 +20,7 @@ describe 'a maintainer edits files on a source-branch of an MR from a fork', :js
end end
before do before do
stub_feature_flags(web_ide_default: false, single_mr_diff_view: false, code_navigation: false) stub_feature_flags(web_ide_default: false, single_mr_diff_view: { enabled: false, thing: target_project }, code_navigation: false)
target_project.add_maintainer(user) target_project.add_maintainer(user)
sign_in(user) sign_in(user)
......
...@@ -10,7 +10,7 @@ describe 'Batch diffs', :js do ...@@ -10,7 +10,7 @@ describe 'Batch diffs', :js do
let(:merge_request) { create(:merge_request, source_project: project, source_branch: 'master', target_branch: 'empty-branch') } let(:merge_request) { create(:merge_request, source_project: project, source_branch: 'master', target_branch: 'empty-branch') }
before do before do
stub_feature_flags(single_mr_diff_view: true) stub_feature_flags(single_mr_diff_view: { enabled: true, thing: project })
stub_feature_flags(diffs_batch_load: true) stub_feature_flags(diffs_batch_load: true)
sign_in(project.owner) sign_in(project.owner)
......
...@@ -60,7 +60,7 @@ RSpec.shared_examples 'diff file entity' do ...@@ -60,7 +60,7 @@ RSpec.shared_examples 'diff file entity' do
context 'when the `single_mr_diff_view` feature is disabled' do context 'when the `single_mr_diff_view` feature is disabled' do
before do before do
stub_feature_flags(single_mr_diff_view: false) stub_feature_flags(single_mr_diff_view: { enabled: false, thing: project })
end end
it 'contains both kinds of diffs' do it 'contains both kinds of diffs' do
......
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