Skip to content

Delegate properly to custom Resolver instances #1568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,4 @@ branches:
only:
- master
- /^\d+-\d+-maintenance$/
- fix_empty_view_rendering
2 changes: 2 additions & 0 deletions example_app_generator/generate_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
|# Rack::Cache 1.3.0 requires Ruby >= 2.0.0
|gem 'rack-cache', '< 1.3.0' if RUBY_VERSION < '2.0.0'
|
|gem 'rake', '~> 10.0', '< 11'
|
|gem 'rspec-rails',
| :path => '#{rspec_rails_repo_path}',
| :groups => [:development, :test]
Expand Down
58 changes: 44 additions & 14 deletions lib/rspec/rails/view_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,18 @@ def render_views?
self.class.render_views? || !controller.class.respond_to?(:view_paths)
end

# Delegates find_all to the submitted path set and then returns templates
# with modified source
#
# @private
class EmptyTemplateResolver < ::ActionView::FileSystemResolver

def initialize(path, pattern=nil)
unless path.is_a?(::ActionView::Resolver)
super
class EmptyTemplateResolver
def self.build(path)
if path.is_a?(::ActionView::Resolver)
ResolverDecorator.new(path)
else
FileSystemResolver.new(path)
end
end

private

def find_templates(*args)
super.map do |template|
def self.nullify_template_rendering(templates)
templates.map do |template|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This map could probably now be delegated to outside as it does the same as below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but I don’t really know where to move it. EmptyTemplateHandler?

::ActionView::Template.new(
"",
template.identifier,
Expand All @@ -64,6 +60,40 @@ def find_templates(*args)
)
end
end

# Delegates find_templates to the submitted resolver and then returns templates
# with modified source
#
# @private
class ResolverDecorator
def initialize(resolver)
@resolver = resolver
end

def method_missing(name, *args, &block)
@resolver.send(name, *args, &block)
end

private

def find_templates(*args)
templates = @resolver.find_templates(*args)
EmptyTemplateResolver.nullify_template_rendering(templates)
end
end

# Delegates find_templates to the submitted path set and then returns
# templates with modified source
#
# @private
class FileSystemResolver < ::ActionView::FileSystemResolver
private

def find_templates(*args)
templates = super
EmptyTemplateResolver.nullify_template_rendering(templates)
end
end
end

# @private
Expand All @@ -88,13 +118,13 @@ def append_view_path(new_path)
private

def _path_decorator(*paths)
paths.map { |path| EmptyTemplateResolver.new(path) }
paths.map { |path| EmptyTemplateResolver.build(path) }
end
end

# @private
RESOLVER_CACHE = Hash.new do |hash, path|
hash[path] = EmptyTemplateResolver.new(path)
hash[path] = EmptyTemplateResolver.build(path)
end

included do
Expand Down
2 changes: 1 addition & 1 deletion rspec-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Gem::Specification.new do |s|
end
end

s.add_development_dependency 'rake', '~> 10.0'
s.add_development_dependency 'rake', '~> 10.0', '< 11'
s.add_development_dependency 'cucumber', '~> 1.3.5'
s.add_development_dependency 'aruba', '~> 0.5.4'
s.add_development_dependency 'ammeter', '1.1.2'
Expand Down