Skip to content

Commit 27174d2

Browse files
committed
Hack: check return values in ResolverDecorator
The alternative is to implement both `find_all` and `find_all_anywhere`. The latter is only present since Rails 4.2.5.1, and the former has different arity in different Rails versions. So either we have a version check, or we just check the types of whatever is returned from the methods called in ResolverDecorator.
1 parent 2158073 commit 27174d2

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

lib/rspec/rails/view_rendering.rb

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ def self.nullify_template_rendering(templates)
6161
end
6262
end
6363

64-
# Delegates find_templates to the submitted resolver and then returns templates
65-
# with modified source
64+
# Delegates all methods to the submitted resolver and for all methods
65+
# that return a collection of `ActionView::Template` instances, return
66+
# templates with modified source
6667
#
6768
# @private
6869
class ResolverDecorator
@@ -71,17 +72,17 @@ def initialize(resolver)
7172
end
7273

7374
def method_missing(name, *args, &block)
74-
@resolver.send(name, *args, &block)
75+
result = @resolver.send(name, *args, &block)
76+
nullify_templates(result)
7577
end
7678

77-
def find_all(name, prefix = nil, partial = false, details = {}, _key = nil, _locals = []) # rubocop:disable Style/ParameterLists
78-
templates = find_templates(name, prefix, partial, details)
79-
EmptyTemplateResolver.nullify_template_rendering(templates)
80-
end
79+
private
8180

82-
def find_all_anywhere(name, prefix, partial = false, details = {}, _key = nil, _locals = []) # rubocop:disable Style/ParameterLists
83-
templates = find_templates(name, prefix, partial, details, true)
84-
EmptyTemplateResolver.nullify_template_rendering(templates)
81+
def nullify_templates(collection)
82+
return collection unless collection.is_a?(Enumerable)
83+
return collection unless collection.all? { |element| element.is_a?(::ActionView::Template) }
84+
85+
EmptyTemplateResolver.nullify_template_rendering(collection)
8586
end
8687
end
8788

@@ -90,12 +91,9 @@ def find_all_anywhere(name, prefix, partial = false, details = {}, _key = nil, _
9091
#
9192
# @private
9293
class FileSystemResolver < ::ActionView::FileSystemResolver
93-
def find_all(name, prefix = nil, partial = false, details = {}, _key = nil, _locals = []) # rubocop:disable Style/ParameterLists
94-
templates = super
95-
EmptyTemplateResolver.nullify_template_rendering(templates)
96-
end
94+
private
9795

98-
def find_all_anywhere(name, prefix, partial = false, details = {}, _key = nil, _locals = []) # rubocop:disable Style/ParameterLists
96+
def find_templates(*args)
9997
templates = super
10098
EmptyTemplateResolver.nullify_template_rendering(templates)
10199
end

0 commit comments

Comments
 (0)