aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/abstract_controller/layouts_test.rb
blob: 35329eea834c14f92568d3398d402aa73d0bcc63 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")

module AbstractControllerTests
  module Layouts

    # Base controller for these tests
    class Base < AbstractController::Base
      include AbstractController::Renderer
      include AbstractController::Layouts
      
      self.view_paths = [ActionView::FixtureTemplate::FixturePath.new(
        "layouts/hello.html.erb" => "With String <%= yield %>"
      )]
      
      def render_to_string(options)
        options[:_layout] = _default_layout
        super
      end
    end
    
    class Blank < Base
      self.view_paths = []
      
      def index
        render :_template => ActionView::TextTemplate.new("Hello blank!")
      end
    end
    
    class WithString < Base
      layout "hello"
      
      def index
        render :_template => ActionView::TextTemplate.new("Hello string!")
      end
    end
    
    class WithMissingLayout < Base
      layout "missing"
      
      def index
        render :_template => ActionView::TextTemplate.new("Hello missing!")
      end
    end
      
    
    class TestBase < ActiveSupport::TestCase
      test "when no layout is specified, and no default is available, render without a layout" do
        result = Blank.process(:index)
        assert_equal "Hello blank!", result.response_obj[:body]
      end
      
      test "when layout is specified as a string, render with that layout" do
        result = Blank.process(:index)
        assert_equal "With String Hello string!", result.response_obj[:body]
      end
      
      test "when layout is specified as a string, but the layout is missing, raise an exception" do
        assert_raises(ActionView::MissingTemplate) { WithMissingLayout.process(:index) }
      end
    end


  end
end