Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/rspec/rails/view_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def method_missing(name, *args, &block)
private

def nullify_templates(collection)
if collection.is_a?(::ActionView::Template)
return EmptyTemplateResolver.nullify_template_rendering([collection]).first
end

return collection unless collection.is_a?(Enumerable)
return collection unless collection.all? { |element| element.is_a?(::ActionView::Template) }

Expand Down
19 changes: 19 additions & 0 deletions spec/rspec/rails/view_rendering_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,25 @@ def custom_method
expect(custom_method_called).to eq(true)
end

it "prevents rendering when a custom resolver returns a single template" do
template = ActionView::Template.new(
"rendered",
"custom resolver template",
ViewRendering::EmptyTemplateHandler,
virtual_path: "custom/template",
format: :html,
locals: []
)
resolver = Class.new(ActionView::Resolver) do
define_method(:find) { |*| template }
end.new

decorated_template = ViewRendering::EmptyTemplateResolver.build(resolver).find

expect(decorated_template).to be_an(ActionView::Template)
expect(decorated_template.source).to eq("")
end

it "works with strings" do
decorated = false
ActionController::Base.view_paths = ActionView::PathSet.new(['app/views', 'app/legacy_views'])
Expand Down
Loading