base_test.rb 2.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
require "#{File.dirname(__FILE__)}/../abstract_unit"
require "#{File.dirname(__FILE__)}/../testing_sandbox"

class ActionViewTemplateTest < Test::Unit::TestCase
  include TestingSandbox
  
  uses_mocha "Action View Templates" do
    def setup
      @template = ActionView::Base.new
    end
    
    def test_should_find_delegated_extension
      @template.expects(:delegate_template_exists?).with('foo').returns(['foo'])
      assert_equal :foo, @template.send(:find_template_extension_for, 'foo')
    end
    
17 18 19 20 21 22
    def test_should_find_formatted_erb_extension
      @template.expects(:delegate_template_exists?).with('foo').returns(nil)
      @template.expects(:formatted_template_exists?).with('foo.html').returns("erb")
      assert_equal "html.erb", @template.send(:find_template_extension_for, 'foo')
    end
    
23 24
    def test_should_find_erb_extension
      @template.expects(:delegate_template_exists?).with('foo').returns(nil)
25
      @template.expects(:formatted_template_exists?).with('foo.html').returns(nil)
26 27 28 29 30 31
      @template.expects(:erb_template_exists?).with('foo').returns(:erb)
      assert_equal :erb, @template.send(:find_template_extension_for, 'foo')
    end
    
    def test_should_find_builder_extension
      @template.expects(:delegate_template_exists?).with('foo').returns(nil)
32
      @template.expects(:formatted_template_exists?).with('foo.html').returns(nil)
33 34 35 36 37 38 39
      @template.expects(:erb_template_exists?).with('foo').returns(nil)
      @template.expects(:builder_template_exists?).with('foo').returns(:builder)
      assert_equal :builder, @template.send(:find_template_extension_for, 'foo')
    end
    
    def test_should_find_javascript_extension
      @template.expects(:delegate_template_exists?).with('foo').returns(nil)
40
      @template.expects(:formatted_template_exists?).with('foo.html').returns(nil)
41 42 43 44 45 46 47
      @template.expects(:erb_template_exists?).with('foo').returns(nil)
      @template.expects(:builder_template_exists?).with('foo').returns(nil)
      @template.expects(:javascript_template_exists?).with('foo').returns(true)
      assert_equal :rjs, @template.send(:find_template_extension_for, 'foo')
    end
  end
end