Commit d36ae5ca authored by Luke Duncalfe's avatar Luke Duncalfe

Merge branch 'id-refactor-view-testing' into 'master'

Fix view rendering that fails in Rails 6.1

See merge request gitlab-org/gitlab!60817
parents 45fff735 6c2cfa85
...@@ -85,8 +85,7 @@ module MergeRequests ...@@ -85,8 +85,7 @@ module MergeRequests
end end
def render_template(file:, locals:) def render_template(file:, locals:)
view = ActionView::Base.new(ActionController::Base.view_paths, {}) ActionController::Base.new.render_to_string(template: file, locals: locals)
view.render(file: file, locals: locals)
end end
def can_create_merge_request?(source_branch) def can_create_merge_request?(source_branch)
......
...@@ -3,23 +3,13 @@ ...@@ -3,23 +3,13 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'admin/dev_ops_report/show.html.haml' do RSpec.describe 'admin/dev_ops_report/show.html.haml' do
include Devise::Test::ControllerHelpers
before do before do
stub_licensed_features(devops_adoption: true) stub_licensed_features(devops_adoption: true)
end end
context 'when show_adoption? returns false' do context 'when show_adoption? returns false' do
before do before do
controller.singleton_class.class_eval do allow(view).to receive(:show_adoption?).and_return(false)
protected
def show_adoption?
false
end
helper_method :show_adoption?
end
end end
it 'disables the feature' do it 'disables the feature' do
...@@ -40,19 +30,9 @@ RSpec.describe 'admin/dev_ops_report/show.html.haml' do ...@@ -40,19 +30,9 @@ RSpec.describe 'admin/dev_ops_report/show.html.haml' do
end end
context 'when show_adoption? returns true' do context 'when show_adoption? returns true' do
before do
controller.singleton_class.class_eval do
protected
def show_adoption?
true
end
helper_method :show_adoption?
end
end
it 'enables the feature' do it 'enables the feature' do
allow(view).to receive(:show_adoption?).and_return(true)
render render
expect(rendered).to have_selector('#devops-adoption') expect(rendered).to have_selector('#devops-adoption')
......
...@@ -32,7 +32,7 @@ RSpec.describe 'shared/nav/_sidebar.html.haml' do ...@@ -32,7 +32,7 @@ RSpec.describe 'shared/nav/_sidebar.html.haml' do
context 'when sidebar has a custom scope menu partial defined' do context 'when sidebar has a custom scope menu partial defined' do
it 'renders the custom partial' do it 'renders the custom partial' do
allow(sidebar).to receive(:render_raw_scope_menu_partial).and_return(scope_menu_view) allow(sidebar).to receive(:render_raw_scope_menu_partial).and_return(scope_menu_view)
allow(sidebar).to receive(:scope_menu).and_return(nil) allow(view).to receive(:scope_menu).and_return(nil)
stub_template(scope_menu_partial => content) stub_template(scope_menu_partial => content)
render render
......
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