aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_view/base.rb3
-rw-r--r--actionpack/test/action_view_test.rb26
2 files changed, 27 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 81a8299e91..d73fb643e8 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -516,8 +516,7 @@ module ActionView #:nodoc:
# Determine the template extension from the <tt>@first_render</tt> filename
def find_template_extension_from_first_render
- extension = @first_render.to_s.sub /^\w+\.?/, ''
- extension.blank? ? nil : extension
+ File.basename(@first_render.to_s)[/^[^.]+\.(.+)$/, 1]
end
# This method reads a template file.
diff --git a/actionpack/test/action_view_test.rb b/actionpack/test/action_view_test.rb
new file mode 100644
index 0000000000..729438af32
--- /dev/null
+++ b/actionpack/test/action_view_test.rb
@@ -0,0 +1,26 @@
+require File.dirname(__FILE__) + '/abstract_unit'
+require 'test/unit'
+
+class ActionViewTests < Test::Unit::TestCase
+ def test_find_template_extension_from_first_render
+ base = ActionView::Base.new
+
+ assert_nil base.send(:find_template_extension_from_first_render)
+
+ {
+ nil => nil,
+ '' => nil,
+ 'foo' => nil,
+ '/foo' => nil,
+ 'foo.rb' => 'rb',
+ 'foo.bar.rb' => 'bar.rb',
+ 'baz/foo.rb' => 'rb',
+ 'baz/foo.bar.rb' => 'bar.rb',
+ 'baz/foo.o/foo.rb' => 'rb',
+ 'baz/foo.o/foo.bar.rb' => 'bar.rb',
+ }.each do |input,expectation|
+ base.instance_variable_set('@first_render', input)
+ assert_equal expectation, base.send(:find_template_extension_from_first_render)
+ end
+ end
+end