Permalink
Browse files

thread local is only set when template missing error is raised

  • Loading branch information...
reidmix committed Dec 31, 2009
1 parent 16f70a9 commit cf678c98af5757a9a607041d9ccd661e7965ff19
Showing with 24 additions and 6 deletions.
  1. +6 −2 lib/overlay_paths.rb
  2. +18 −4 spec/overlay_paths_spec.rb
View
@@ -17,8 +17,12 @@ def find_template_with_overlay(original_template_path, format = nil, html_fallba
elsif template = load_path["#{template_path}_#{Overlay.current}.#{I18n.locale}"]
return template
else
- Thread.current[:missing_default] = true
- return find_template_without_overlay(original_template_path, format, html_fallback)
+ begin
+ return find_template_without_overlay(original_template_path, format, html_fallback)
+ rescue ActionView::MissingTemplate => e
+ Thread.current[:missing_default] = true
+ raise e
+ end
end
end
end
View
@@ -30,10 +30,24 @@
@paths.find_template(template).should == template
end
- it 'sets Thead.current on :missing_template to true' do
- @paths.should_receive(:find_template_without_overlay).with('foo', 'html', false).and_return :template
- Thread.current.should_receive(:[]=).with(:missing_default, true)
- @paths.find_template('foo', 'html', false)
+ describe 'Thread.current[:missing_default]' do
+ it 'is not set on success' do
+ @paths.should_receive(:find_template_without_overlay).with('foo', 'html', false).and_return :template
+ Thread.current.should_not_receive(:[]=)
+ @paths.find_template('foo', 'html', false)
+ end
+
+ it 'is not set on non-missing template error' do
+ @paths.should_receive(:find_template_without_overlay).and_raise RuntimeError.new('suck')
+ Thread.current.should_not_receive(:[]=)
+ lambda { @paths.find_template('foo', 'html', false) }.should raise_error(RuntimeError, 'suck')
+ end
+
+ it 'is true with missing template' do
+ @paths.should_receive(:find_template_without_overlay).and_raise ActionView::MissingTemplate.new(ActionView::PathSet.new, 'foo')
+ Thread.current.should_receive(:[]=).with(:missing_default, true)
+ lambda { @paths.find_template('foo', 'html', false) }.should raise_error(ActionView::MissingTemplate)
+ end
end
end

0 comments on commit cf678c9

Please sign in to comment.