diff --git a/CHANGELOG.md b/CHANGELOG.md index 87b1efb..6439064 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/xray/engine.rb b/lib/xray/engine.rb index fdac4fe..ea0ebee 100644 --- a/lib/xray/engine.rb +++ b/lib/xray/engine.rb @@ -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 diff --git a/spec/xray/engine_spec.rb b/spec/xray/engine_spec.rb index a3e825d..a6e5009 100644 --- a/spec/xray/engine_spec.rb +++ b/spec/xray/engine_spec.rb @@ -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) @@ -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