aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/template_test.rb
blob: 5c6523201b49f1cd41fef41799305e493374732e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'abstract_unit'

class TemplateTest < Test::Unit::TestCase
  def test_template_path_parsing
    with_options :base_path => nil, :name => 'abc', :locale => nil, :format => 'html', :extension => 'erb' do |t|
      t.assert_parses_template_path 'abc.en.html.erb',        :locale => 'en'
      t.assert_parses_template_path 'abc.en.plain.html.erb',  :locale => 'en', :format => 'plain.html'
      t.assert_parses_template_path 'abc.html.erb'
      t.assert_parses_template_path 'abc.plain.html.erb',     :format => 'plain.html'
      t.assert_parses_template_path 'abc.erb',                :format => nil
      t.assert_parses_template_path 'abc.html',               :extension => nil
      
      t.assert_parses_template_path '_abc.html.erb',          :name => '_abc'
      
      t.assert_parses_template_path 'test/abc.html.erb',      :base_path => 'test'
      t.assert_parses_template_path './test/abc.html.erb',    :base_path => './test'
      t.assert_parses_template_path '../test/abc.html.erb',   :base_path => '../test'
      
      t.assert_parses_template_path 'abc',                    :extension => nil, :format => nil, :name => nil
      t.assert_parses_template_path 'abc.xxx',                :extension => nil, :format => 'xxx', :name => 'abc'
      t.assert_parses_template_path 'abc.html.xxx',           :extension => nil, :format => 'xxx', :name => 'abc'

      t.assert_parses_template_path 'abc.html.erb.orig',      :format => 'orig', :extension => nil
    end
  end

  private
  def assert_parses_template_path(path, parse_results)
    template = ActionView::Template.new(path, '')
    parse_results.each_pair do |k, v|
      assert_block(%Q{Expected template to parse #{k.inspect} from "#{path}" as #{v.inspect}, but got #{template.send(k).inspect}}) { v == template.send(k) }
    end
  end
end