Skip to content
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

Handle nil templates #96

Merged
merged 2 commits into from
Mar 13, 2019
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ lesser changes or bug fixes.
## [Unreleased][]

* Your contribution here!
* Gracefully handle nil templates
[#96](https://github.com/brentd/xray-rails/pull/96)

## [0.3.1][] (2017-06-16)

Expand Down
2 changes: 1 addition & 1 deletion lib/xray/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def render_with_xray(*args, &block)

options = args.last.kind_of?(Hash) ? args.last : {}

if suitable_template && !(options.has_key?(:xray) && (options[:xray] == false))
if source && suitable_template && !(options.has_key?(:xray) && (options[:xray] == false))
Xray.augment_template(source, path)
else
source
Expand Down
14 changes: 14 additions & 0 deletions spec/xray/engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
expect(subject.render(*xray_enabled_render_args)).to eql(augmented_render_result)
end

it 'should render and augment when template source is an empty string' do
subject.should_receive(:render_without_xray).with(*xray_enabled_render_args).and_return('')
subject.should_receive(:identifier).and_return(html_identifier)
Xray.should_receive(:augment_template).with('', html_identifier).and_return(augmented_render_result)
expect(subject.render(*xray_enabled_render_args)).to eql(augmented_render_result)
end

it 'should render but not augment HTML if :xray => false passed as an option' do
subject.should_receive(:render_without_xray).with(*xray_enabled_render_args).and_return(render_result)
subject.should_receive(:identifier).and_return(html_identifier)
Expand All @@ -31,6 +38,13 @@
Xray.should_not_receive(:augment_template)
expect(subject.render(*xray_disabled_render_args)).to eql(plain_text_result)
end

it 'should render but not augment when template source is nil' do
subject.should_receive(:render_without_xray).with(*xray_enabled_render_args).and_return(nil)
subject.should_receive(:identifier).and_return(html_identifier)
Xray.should_not_receive(:augment_template)
expect(subject.render(*xray_enabled_render_args)).to eql(nil)
end
end
end