~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/actionpack/test/controller/layout_test.rb

  • Committer: Richard Lee (Canonical)
  • Date: 2010-10-15 15:17:58 UTC
  • mfrom: (190.1.3 use-case-mapper)
  • Revision ID: richard.lee@canonical.com-20101015151758-wcvmfxrexsongf9d
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require 'abstract_unit'
2
 
 
3
 
# The view_paths array must be set on Base and not LayoutTest so that LayoutTest's inherited
4
 
# method has access to the view_paths array when looking for a layout to automatically assign.
5
 
old_load_paths = ActionController::Base.view_paths
6
 
 
7
 
ActionView::Template::register_template_handler :mab,
8
 
  lambda { |template| template.source.inspect }
9
 
 
10
 
ActionController::Base.view_paths = [ File.dirname(__FILE__) + '/../fixtures/layout_tests/' ]
11
 
 
12
 
class LayoutTest < ActionController::Base
13
 
  def self.controller_path; 'views' end
14
 
  self.view_paths = ActionController::Base.view_paths.dup
15
 
end
16
 
 
17
 
# Restore view_paths to previous value
18
 
ActionController::Base.view_paths = old_load_paths
19
 
 
20
 
class ProductController < LayoutTest
21
 
end
22
 
 
23
 
class ItemController < LayoutTest
24
 
end
25
 
 
26
 
class ThirdPartyTemplateLibraryController < LayoutTest
27
 
end
28
 
 
29
 
module ControllerNameSpace
30
 
end
31
 
 
32
 
class ControllerNameSpace::NestedController < LayoutTest
33
 
end
34
 
 
35
 
class MultipleExtensions < LayoutTest
36
 
end
37
 
 
38
 
class LayoutAutoDiscoveryTest < ActionController::TestCase
39
 
  def setup
40
 
    @request.host = "www.nextangle.com"
41
 
  end
42
 
 
43
 
  def test_application_layout_is_default_when_no_controller_match
44
 
    @controller = ProductController.new
45
 
    get :hello
46
 
    assert_equal 'layout_test.rhtml hello.rhtml', @response.body
47
 
  end
48
 
 
49
 
  def test_controller_name_layout_name_match
50
 
    @controller = ItemController.new
51
 
    get :hello
52
 
    assert_equal 'item.rhtml hello.rhtml', @response.body
53
 
  end
54
 
 
55
 
  def test_third_party_template_library_auto_discovers_layout
56
 
    @controller = ThirdPartyTemplateLibraryController.new
57
 
    get :hello
58
 
    assert_equal 'layouts/third_party_template_library.mab', @controller.active_layout.to_s
59
 
    assert_equal 'layouts/third_party_template_library', @response.layout
60
 
    assert_response :success
61
 
    assert_equal 'Mab', @response.body
62
 
  end
63
 
 
64
 
  def test_namespaced_controllers_auto_detect_layouts
65
 
    @controller = ControllerNameSpace::NestedController.new
66
 
    get :hello
67
 
    assert_equal 'layouts/controller_name_space/nested', @controller.active_layout.to_s
68
 
    assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body
69
 
  end
70
 
 
71
 
  def test_namespaced_controllers_auto_detect_layouts
72
 
    @controller = MultipleExtensions.new
73
 
    get :hello
74
 
    assert_equal 'layouts/multiple_extensions.html.erb', @controller.active_layout.to_s
75
 
    assert_equal 'multiple_extensions.html.erb hello.rhtml', @response.body.strip
76
 
  end
77
 
end
78
 
 
79
 
class DefaultLayoutController < LayoutTest
80
 
end
81
 
 
82
 
class AbsolutePathLayoutController < LayoutTest
83
 
  layout File.expand_path(File.expand_path(__FILE__) + '/../../fixtures/layout_tests/layouts/layout_test.rhtml')
84
 
end
85
 
 
86
 
class AbsolutePathWithoutLayoutsController < LayoutTest
87
 
  # Absolute layout path without 'layouts' in it.
88
 
  layout File.expand_path(File.expand_path(__FILE__) + '/../../fixtures/layout_tests/abs_path_layout.rhtml')
89
 
end
90
 
 
91
 
class HasOwnLayoutController < LayoutTest
92
 
  layout 'item'
93
 
end
94
 
 
95
 
class PrependsViewPathController < LayoutTest
96
 
  def hello
97
 
    prepend_view_path File.dirname(__FILE__) + '/../fixtures/layout_tests/alt/'
98
 
    render :layout => 'alt'
99
 
  end
100
 
end
101
 
 
102
 
class SetsLayoutInRenderController < LayoutTest
103
 
  def hello
104
 
    render :layout => 'third_party_template_library'
105
 
  end
106
 
end
107
 
 
108
 
class RendersNoLayoutController < LayoutTest
109
 
  def hello
110
 
    render :layout => false
111
 
  end
112
 
end
113
 
 
114
 
class LayoutSetInResponseTest < ActionController::TestCase
115
 
  def test_layout_set_when_using_default_layout
116
 
    @controller = DefaultLayoutController.new
117
 
    get :hello
118
 
    assert_equal 'layouts/layout_test', @response.layout
119
 
  end
120
 
 
121
 
  def test_layout_set_when_set_in_controller
122
 
    @controller = HasOwnLayoutController.new
123
 
    get :hello
124
 
    assert_equal 'layouts/item', @response.layout
125
 
  end
126
 
 
127
 
  def test_layout_set_when_using_render
128
 
    @controller = SetsLayoutInRenderController.new
129
 
    get :hello
130
 
    assert_equal 'layouts/third_party_template_library', @response.layout
131
 
  end
132
 
 
133
 
  def test_layout_is_not_set_when_none_rendered
134
 
    @controller = RendersNoLayoutController.new
135
 
    get :hello
136
 
    assert_nil @response.layout
137
 
  end
138
 
 
139
 
  def test_exempt_from_layout_honored_by_render_template
140
 
    ActionController::Base.exempt_from_layout :rhtml
141
 
    @controller = RenderWithTemplateOptionController.new
142
 
 
143
 
    get :hello
144
 
    assert_equal "alt/hello.rhtml", @response.body.strip
145
 
 
146
 
  ensure
147
 
    ActionController::Base.exempt_from_layout.delete(/\.rhtml$/)
148
 
  end
149
 
 
150
 
  def test_layout_is_picked_from_the_controller_instances_view_path
151
 
    @controller = PrependsViewPathController.new
152
 
    get :hello
153
 
    assert_equal 'layouts/alt', @response.layout
154
 
  end
155
 
 
156
 
  def test_absolute_pathed_layout
157
 
    @controller = AbsolutePathLayoutController.new
158
 
    get :hello
159
 
    assert_equal "layout_test.rhtml hello.rhtml", @response.body.strip
160
 
  end
161
 
 
162
 
  def test_absolute_pathed_layout_without_layouts_in_path
163
 
    @controller = AbsolutePathWithoutLayoutsController.new
164
 
    get :hello
165
 
    assert_equal "abs_path_layout.rhtml hello.rhtml", @response.body.strip
166
 
  end
167
 
end
168
 
 
169
 
class RenderWithTemplateOptionController < LayoutTest
170
 
  def hello
171
 
    render :template => 'alt/hello'
172
 
  end
173
 
end
174
 
 
175
 
class SetsNonExistentLayoutFile < LayoutTest
176
 
  layout "nofile.rhtml"
177
 
end
178
 
 
179
 
class LayoutExceptionRaised < ActionController::TestCase
180
 
  def test_exception_raised_when_layout_file_not_found
181
 
    @controller = SetsNonExistentLayoutFile.new
182
 
    get :hello
183
 
    assert_kind_of ActionView::MissingTemplate, @response.template.instance_eval { @exception }
184
 
  end
185
 
end
186
 
 
187
 
class LayoutStatusIsRendered < LayoutTest
188
 
  def hello
189
 
    render :status => 401
190
 
  end
191
 
end
192
 
 
193
 
class LayoutStatusIsRenderedTest < ActionController::TestCase
194
 
  def test_layout_status_is_rendered
195
 
    @controller = LayoutStatusIsRendered.new
196
 
    get :hello
197
 
    assert_response 401
198
 
  end
199
 
end
200
 
 
201
 
unless RUBY_PLATFORM =~ /(:?mswin|mingw|bccwin)/
202
 
  class LayoutSymlinkedTest < LayoutTest
203
 
    layout "symlinked/symlinked_layout"
204
 
  end
205
 
 
206
 
  class LayoutSymlinkedIsRenderedTest < ActionController::TestCase
207
 
    def test_symlinked_layout_is_rendered
208
 
      @controller = LayoutSymlinkedTest.new
209
 
      get :hello
210
 
      assert_response 200
211
 
      assert_equal "layouts/symlinked/symlinked_layout", @response.layout
212
 
    end
213
 
  end
214
 
end
215