Commit 30f59e8c authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'render_super-ee' into 'master'

Add render_ce to render CE partial in EE partial

See merge request gitlab-org/gitlab-ee!5856
parents 63749fae c1847dd3
%p.form-text.text-muted
Add
= link_to 'description templates', help_page_path('user/project/description_templates'), tabindex: -1
to help your contributors communicate effectively!
......@@ -30,10 +30,4 @@
merge request from being merged before it's ready.
- if no_issuable_templates && can?(current_user, :push_code, issuable.project)
- if @project.feature_available?(:issuable_default_templates)
%p.form-text.text-muted
Add
= link_to 'description templates', help_page_path('user/project/description_templates'), tabindex: -1
to help your contributors communicate effectively!
- elsif show_promotions?
= render 'shared/promotions/promote_issue_templates'
= render 'shared/issuable/form/default_templates'
......@@ -10,6 +10,30 @@ module EE
{ primary_node: link_to('primary node', ::Gitlab::Geo.primary_node.url) }).html_safe
end
def render_ce(partial)
render template: find_ce_partial(partial)
end
def find_ce_partial(partial)
ce_lookup_context.find(partial, [], true)
end
def ce_lookup_context
@ce_lookup_context ||= begin
context = lookup_context.dup
# This could duplicate the paths we're going to modify
context.view_paths = lookup_context.view_paths.paths
# Discard lookup path ee/ for the new paths
context.view_paths.paths.delete_if do |resolver|
resolver.to_path.start_with?("#{Rails.root}/ee")
end
context
end
end
def page_class
class_names = super
class_names += system_message_class
......
- if @project.feature_available?(:issuable_default_templates)
= render_ce 'shared/issuable/form/default_templates'
- elsif show_promotions?
= render 'shared/promotions/promote_issue_templates'
......@@ -12,4 +12,39 @@ describe ApplicationHelper do
end
end
end
context 'when both CE and EE has partials with the same name' do
let(:partial) { 'shared/issuable/form/default_templates' }
let(:project) { build_stubbed(:project) }
describe '#render_ce' do
before do
helper.instance_variable_set(:@project, project)
allow(project).to receive(:feature_available?)
end
it 'renders the CE partial' do
helper.render_ce(partial)
expect(project).not_to receive(:feature_available?)
end
end
describe '#find_ce_partial' do
let(:expected_partial_path) do
"app/views/#{File.dirname(partial)}/_#{File.basename(partial)}.html.haml"
end
it 'finds the CE partial' do
ce_partial = helper.find_ce_partial(partial)
expect(ce_partial.inspect).to eq(expected_partial_path)
# And it could still find the EE partial
ee_partial = helper.lookup_context.find(partial, [], true)
expect(ee_partial.inspect).to eq("ee/#{expected_partial_path}")
end
end
end
end
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