Skip to content
This repository
Browse code

Merge RenderTest and NewRenderTest

  • Loading branch information...
commit a200c67611ed3bb2d276a9a1d1eb67b5c926f22a 1 parent 743f0e7
Joshua Peek josh authored
983 actionpack/test/controller/new_render_test.rb
... ... @@ -1,983 +0,0 @@
1   -require 'abstract_unit'
2   -require 'controller/fake_models'
3   -
4   -class CustomersController < ActionController::Base
5   -end
6   -
7   -module Fun
8   - class GamesController < ActionController::Base
9   - def hello_world
10   - end
11   - end
12   -end
13   -
14   -module NewRenderTestHelper
15   - def rjs_helper_method_from_module
16   - page.visual_effect :highlight
17   - end
18   -end
19   -
20   -class LabellingFormBuilder < ActionView::Helpers::FormBuilder
21   -end
22   -
23   -class NewRenderTestController < ActionController::Base
24   - layout :determine_layout
25   -
26   - def self.controller_name; "test"; end
27   - def self.controller_path; "test"; end
28   -
29   - def hello_world
30   - end
31   -
32   - def render_hello_world
33   - render :template => "test/hello_world"
34   - end
35   -
36   - def render_hello_world_from_variable
37   - @person = "david"
38   - render :text => "hello #{@person}"
39   - end
40   -
41   - def render_action_hello_world
42   - render :action => "hello_world"
43   - end
44   -
45   - def render_action_hello_world_as_symbol
46   - render :action => :hello_world
47   - end
48   -
49   - def render_text_hello_world
50   - render :text => "hello world"
51   - end
52   -
53   - def render_text_hello_world_with_layout
54   - @variable_for_layout = ", I'm here!"
55   - render :text => "hello world", :layout => true
56   - end
57   -
58   - def hello_world_with_layout_false
59   - render :layout => false
60   - end
61   -
62   - def render_custom_code
63   - render :text => "hello world", :status => "404 Moved"
64   - end
65   -
66   - def render_file_with_instance_variables
67   - @secret = 'in the sauce'
68   - path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb')
69   - render :file => path
70   - end
71   -
72   - def render_file_from_template
73   - @secret = 'in the sauce'
74   - @path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb'))
75   - end
76   -
77   - def render_file_with_locals
78   - path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_locals.erb')
79   - render :file => path, :locals => {:secret => 'in the sauce'}
80   - end
81   -
82   - def render_file_not_using_full_path
83   - @secret = 'in the sauce'
84   - render :file => 'test/render_file_with_ivar'
85   - end
86   -
87   - def render_file_not_using_full_path_with_dot_in_path
88   - @secret = 'in the sauce'
89   - render :file => 'test/dot.directory/render_file_with_ivar'
90   - end
91   -
92   - def render_xml_hello
93   - @name = "David"
94   - render :template => "test/hello"
95   - end
96   -
97   - def greeting
98   - # let's just rely on the template
99   - end
100   -
101   - def layout_test
102   - render :action => "hello_world"
103   - end
104   -
105   - def layout_test_with_different_layout
106   - render :action => "hello_world", :layout => "standard"
107   - end
108   -
109   - def rendering_without_layout
110   - render :action => "hello_world", :layout => false
111   - end
112   -
113   - def layout_overriding_layout
114   - render :action => "hello_world", :layout => "standard"
115   - end
116   -
117   - def rendering_nothing_on_layout
118   - render :nothing => true
119   - end
120   -
121   - def builder_layout_test
122   - render :action => "hello"
123   - end
124   -
125   - def partials_list
126   - @test_unchanged = 'hello'
127   - @customers = [ Customer.new("david"), Customer.new("mary") ]
128   - render :action => "list"
129   - end
130   -
131   - def partial_only
132   - render :partial => true
133   - end
134   -
135   - def partial_only_with_layout
136   - render :partial => "partial_only", :layout => true
137   - end
138   -
139   - def partial_with_counter
140   - render :partial => "counter", :locals => { :counter_counter => 5 }
141   - end
142   -
143   - def partial_with_locals
144   - render :partial => "customer", :locals => { :customer => Customer.new("david") }
145   - end
146   -
147   - def partial_with_form_builder
148   - render :partial => ActionView::Helpers::FormBuilder.new(:post, nil, @template, {}, Proc.new {})
149   - end
150   -
151   - def partial_with_form_builder_subclass
152   - render :partial => LabellingFormBuilder.new(:post, nil, @template, {}, Proc.new {})
153   - end
154   -
155   - def partial_collection
156   - render :partial => "customer", :collection => [ Customer.new("david"), Customer.new("mary") ]
157   - end
158   -
159   - def partial_collection_with_as
160   - render :partial => "customer_with_var", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => :customer
161   - end
162   -
163   - def partial_collection_with_spacer
164   - render :partial => "customer", :spacer_template => "partial_only", :collection => [ Customer.new("david"), Customer.new("mary") ]
165   - end
166   -
167   - def partial_collection_with_counter
168   - render :partial => "customer_counter", :collection => [ Customer.new("david"), Customer.new("mary") ]
169   - end
170   -
171   - def partial_collection_with_locals
172   - render :partial => "customer_greeting", :collection => [ Customer.new("david"), Customer.new("mary") ], :locals => { :greeting => "Bonjour" }
173   - end
174   -
175   - def partial_collection_shorthand_with_locals
176   - render :partial => [ Customer.new("david"), Customer.new("mary") ], :locals => { :greeting => "Bonjour" }
177   - end
178   -
179   - def partial_collection_shorthand_with_different_types_of_records
180   - render :partial => [
181   - BadCustomer.new("mark"),
182   - GoodCustomer.new("craig"),
183   - BadCustomer.new("john"),
184   - GoodCustomer.new("zach"),
185   - GoodCustomer.new("brandon"),
186   - BadCustomer.new("dan") ],
187   - :locals => { :greeting => "Bonjour" }
188   - end
189   -
190   - def partial_collection_shorthand_with_different_types_of_records_with_counter
191   - partial_collection_shorthand_with_different_types_of_records
192   - end
193   -
194   - def empty_partial_collection
195   - render :partial => "customer", :collection => []
196   - end
197   -
198   - def partial_with_hash_object
199   - render :partial => "hash_object", :object => {:first_name => "Sam"}
200   - end
201   -
202   - def partial_hash_collection
203   - render :partial => "hash_object", :collection => [ {:first_name => "Pratik"}, {:first_name => "Amy"} ]
204   - end
205   -
206   - def partial_hash_collection_with_locals
207   - render :partial => "hash_greeting", :collection => [ {:first_name => "Pratik"}, {:first_name => "Amy"} ], :locals => { :greeting => "Hola" }
208   - end
209   -
210   - def partial_with_implicit_local_assignment
211   - @customer = Customer.new("Marcel")
212   - render :partial => "customer"
213   - end
214   -
215   - def missing_partial
216   - render :partial => 'thisFileIsntHere'
217   - end
218   -
219   - def hello_in_a_string
220   - @customers = [ Customer.new("david"), Customer.new("mary") ]
221   - render :text => "How's there? " << render_to_string(:template => "test/list")
222   - end
223   -
224   - def render_to_string_with_assigns
225   - @before = "i'm before the render"
226   - render_to_string :text => "foo"
227   - @after = "i'm after the render"
228   - render :action => "test/hello_world"
229   - end
230   -
231   - def render_to_string_with_partial
232   - @partial_only = render_to_string :partial => "partial_only"
233   - @partial_with_locals = render_to_string :partial => "customer", :locals => { :customer => Customer.new("david") }
234   - render :action => "test/hello_world"
235   - end
236   -
237   - def render_to_string_with_exception
238   - render_to_string :file => "exception that will not be caught - this will certainly not work"
239   - end
240   -
241   - def render_to_string_with_caught_exception
242   - @before = "i'm before the render"
243   - begin
244   - render_to_string :file => "exception that will be caught- hope my future instance vars still work!"
245   - rescue
246   - end
247   - @after = "i'm after the render"
248   - render :action => "test/hello_world"
249   - end
250   -
251   - def accessing_params_in_template
252   - render :inline => "Hello: <%= params[:name] %>"
253   - end
254   -
255   - def accessing_request_in_template
256   - render :inline => "Hello: <%= request.host %>"
257   - end
258   -
259   - def accessing_logger_in_template
260   - render :inline => "<%= logger.class %>"
261   - end
262   -
263   - def accessing_action_name_in_template
264   - render :inline => "<%= action_name %>"
265   - end
266   -
267   - def accessing_controller_name_in_template
268   - render :inline => "<%= controller_name %>"
269   - end
270   -
271   - def accessing_params_in_template_with_layout
272   - render :layout => nil, :inline => "Hello: <%= params[:name] %>"
273   - end
274   -
275   - def render_with_explicit_template
276   - render :template => "test/hello_world"
277   - end
278   -
279   - def render_with_explicit_template_with_locals
280   - render :template => "test/render_file_with_locals", :locals => { :secret => 'area51' }
281   - end
282   -
283   - def double_render
284   - render :text => "hello"
285   - render :text => "world"
286   - end
287   -
288   - def double_redirect
289   - redirect_to :action => "double_render"
290   - redirect_to :action => "double_render"
291   - end
292   -
293   - def render_and_redirect
294   - render :text => "hello"
295   - redirect_to :action => "double_render"
296   - end
297   -
298   - def render_to_string_and_render
299   - @stuff = render_to_string :text => "here is some cached stuff"
300   - render :text => "Hi web users! #{@stuff}"
301   - end
302   -
303   - def rendering_with_conflicting_local_vars
304   - @name = "David"
305   - def @template.name() nil end
306   - render :action => "potential_conflicts"
307   - end
308   -
309   - def hello_world_from_rxml_using_action
310   - render :action => "hello_world_from_rxml.builder"
311   - end
312   -
313   - def hello_world_from_rxml_using_template
314   - render :template => "test/hello_world_from_rxml.builder"
315   - end
316   -
317   - def head_with_location_header
318   - head :location => "/foo"
319   - end
320   -
321   - def head_with_symbolic_status
322   - head :status => params[:status].intern
323   - end
324   -
325   - def head_with_integer_status
326   - head :status => params[:status].to_i
327   - end
328   -
329   - def head_with_string_status
330   - head :status => params[:status]
331   - end
332   -
333   - def head_with_custom_header
334   - head :x_custom_header => "something"
335   - end
336   -
337   - def head_with_status_code_first
338   - head :forbidden, :x_custom_header => "something"
339   - end
340   -
341   - def render_with_location
342   - render :xml => "<hello/>", :location => "http://example.com", :status => 201
343   - end
344   -
345   - def render_with_object_location
346   - customer = Customer.new("Some guy", 1)
347   - render :xml => "<customer/>", :location => customer_url(customer), :status => :created
348   - end
349   -
350   - def render_with_to_xml
351   - to_xmlable = Class.new do
352   - def to_xml
353   - "<i-am-xml/>"
354   - end
355   - end.new
356   -
357   - render :xml => to_xmlable
358   - end
359   -
360   - helper NewRenderTestHelper
361   - helper do
362   - def rjs_helper_method(value)
363   - page.visual_effect :highlight, value
364   - end
365   - end
366   -
367   - def enum_rjs_test
368   - render :update do |page|
369   - page.select('.product').each do |value|
370   - page.rjs_helper_method_from_module
371   - page.rjs_helper_method(value)
372   - page.sortable(value, :url => { :action => "order" })
373   - page.draggable(value)
374   - end
375   - end
376   - end
377   -
378   - def delete_with_js
379   - @project_id = 4
380   - end
381   -
382   - def render_js_with_explicit_template
383   - @project_id = 4
384   - render :template => 'test/delete_with_js'
385   - end
386   -
387   - def render_js_with_explicit_action_template
388   - @project_id = 4
389   - render :action => 'delete_with_js'
390   - end
391   -
392   - def update_page
393   - render :update do |page|
394   - page.replace_html 'balance', '$37,000,000.00'
395   - page.visual_effect :highlight, 'balance'
396   - end
397   - end
398   -
399   - def update_page_with_instance_variables
400   - @money = '$37,000,000.00'
401   - @div_id = 'balance'
402   - render :update do |page|
403   - page.replace_html @div_id, @money
404   - page.visual_effect :highlight, @div_id
405   - end
406   - end
407   -
408   - def action_talk_to_layout
409   - # Action template sets variable that's picked up by layout
410   - end
411   -
412   - def render_text_with_assigns
413   - @hello = "world"
414   - render :text => "foo"
415   - end
416   -
417   - def yield_content_for
418   - render :action => "content_for", :layout => "yield"
419   - end
420   -
421   - def render_content_type_from_body
422   - response.content_type = Mime::RSS
423   - render :text => "hello world!"
424   - end
425   -
426   - def render_call_to_partial_with_layout
427   - render :action => "calling_partial_with_layout"
428   - end
429   -
430   - def render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout
431   - render :action => "calling_partial_with_layout"
432   - end
433   -
434   - def render_using_layout_around_block
435   - render :action => "using_layout_around_block"
436   - end
437   -
438   - def render_using_layout_around_block_with_args
439   - render :action => "using_layout_around_block_with_args"
440   - end
441   -
442   - def render_using_layout_around_block_in_main_layout_and_within_content_for_layout
443   - render :action => "using_layout_around_block"
444   - end
445   -
446   - def rescue_action(e) raise end
447   -
448   - private
449   - def determine_layout
450   - case action_name
451   - when "hello_world", "layout_test", "rendering_without_layout",
452   - "rendering_nothing_on_layout", "render_text_hello_world",
453   - "render_text_hello_world_with_layout",
454   - "hello_world_with_layout_false",
455   - "partial_only", "partial_only_with_layout",
456   - "accessing_params_in_template",
457   - "accessing_params_in_template_with_layout",
458   - "render_with_explicit_template",
459   - "render_js_with_explicit_template",
460   - "render_js_with_explicit_action_template",
461   - "delete_with_js", "update_page", "update_page_with_instance_variables"
462   -
463   - "layouts/standard"
464   - when "builder_layout_test"
465   - "layouts/builder"
466   - when "action_talk_to_layout", "layout_overriding_layout"
467   - "layouts/talk_from_action"
468   - when "render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout"
469   - "layouts/partial_with_layout"
470   - when "render_using_layout_around_block_in_main_layout_and_within_content_for_layout"
471   - "layouts/block_with_layout"
472   - end
473   - end
474   -end
475   -
476   -class NewRenderTest < Test::Unit::TestCase
477   - def setup
478   - @controller = NewRenderTestController.new
479   -
480   - # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
481   - # a more accurate simulation of what happens in "real life".
482   - @controller.logger = Logger.new(nil)
483   -
484   - @request = ActionController::TestRequest.new
485   - @response = ActionController::TestResponse.new
486   -
487   - @request.host = "www.nextangle.com"
488   - end
489   -
490   - def test_simple_show
491   - get :hello_world
492   - assert_response :success
493   - assert_template "test/hello_world"
494   - assert_equal "<html>Hello world!</html>", @response.body
495   - end
496   -
497   - def test_renders_default_template_for_missing_action
498   - get :'hyphen-ated'
499   - assert_template 'test/hyphen-ated'
500   - end
501   -
502   - def test_do_with_render
503   - get :render_hello_world
504   - assert_template "test/hello_world"
505   - end
506   -
507   - def test_do_with_render_from_variable
508   - get :render_hello_world_from_variable
509   - assert_equal "hello david", @response.body
510   - end
511   -
512   - def test_do_with_render_action
513   - get :render_action_hello_world
514   - assert_template "test/hello_world"
515   - end
516   -
517   - def test_do_with_render_action_as_symbol
518   - get :render_action_hello_world_as_symbol
519   - assert_template "test/hello_world"
520   - end
521   -
522   - def test_do_with_render_text
523   - get :render_text_hello_world
524   - assert_equal "hello world", @response.body
525   - end
526   -
527   - def test_do_with_render_text_and_layout
528   - get :render_text_hello_world_with_layout
529   - assert_equal "<html>hello world, I'm here!</html>", @response.body
530   - end
531   -
532   - def test_do_with_render_action_and_layout_false
533   - get :hello_world_with_layout_false
534   - assert_equal 'Hello world!', @response.body
535   - end
536   -
537   - def test_do_with_render_custom_code
538   - get :render_custom_code
539   - assert_response :missing
540   - end
541   -
542   - def test_render_file_with_instance_variables
543   - get :render_file_with_instance_variables
544   - assert_equal "The secret is in the sauce\n", @response.body
545   - end
546   -
547   - def test_render_file_not_using_full_path
548   - get :render_file_not_using_full_path
549   - assert_equal "The secret is in the sauce\n", @response.body
550   - end
551   -
552   - def test_render_file_not_using_full_path_with_dot_in_path
553   - get :render_file_not_using_full_path_with_dot_in_path
554   - assert_equal "The secret is in the sauce\n", @response.body
555   - end
556   -
557   - def test_render_file_with_locals
558   - get :render_file_with_locals
559   - assert_equal "The secret is in the sauce\n", @response.body
560   - end
561   -
562   - def test_render_file_from_template
563   - get :render_file_from_template
564   - assert_equal "The secret is in the sauce\n", @response.body
565   - end
566   -
567   - def test_attempt_to_access_object_method
568   - assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { get :clone }
569   - end
570   -
571   - def test_private_methods
572   - assert_raises(ActionController::UnknownAction, "No action responded to [determine_layout]") { get :determine_layout }
573   - end
574   -
575   - def test_access_to_request_in_view
576   - get :accessing_request_in_template
577   - assert_equal "Hello: www.nextangle.com", @response.body
578   - end
579   -
580   - def test_access_to_logger_in_view
581   - get :accessing_logger_in_template
582   - assert_equal "Logger", @response.body
583   - end
584   -
585   - def test_access_to_action_name_in_view
586   - get :accessing_action_name_in_template
587   - assert_equal "accessing_action_name_in_template", @response.body
588   - end
589   -
590   - def test_access_to_controller_name_in_view
591   - get :accessing_controller_name_in_template
592   - assert_equal "test", @response.body # name is explicitly set to 'test' inside the controller.
593   - end
594   -
595   - def test_render_xml
596   - get :render_xml_hello
597   - assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body
598   - end
599   -
600   - def test_enum_rjs_test
601   - get :enum_rjs_test
602   - assert_equal <<-EOS.strip, @response.body
603   -$$(".product").each(function(value, index) {
604   -new Effect.Highlight(element,{});
605   -new Effect.Highlight(value,{});
606   -Sortable.create(value, {onUpdate:function(){new Ajax.Request('/test/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(value)})}});
607   -new Draggable(value, {});
608   -});
609   -EOS
610   - end
611   -
612   - def test_render_xml_with_default
613   - get :greeting
614   - assert_equal "<p>This is grand!</p>\n", @response.body
615   - end
616   -
617   - def test_render_with_default_from_accept_header
618   - xhr :get, :greeting
619   - assert_equal "$(\"body\").visualEffect(\"highlight\");", @response.body
620   - end
621   -
622   - def test_render_rjs_with_default
623   - get :delete_with_js
624   - assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body
625   - end
626   -
627   - def test_render_rjs_template_explicitly
628   - get :render_js_with_explicit_template
629   - assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body
630   - end
631   -
632   - def test_rendering_rjs_action_explicitly
633   - get :render_js_with_explicit_action_template
634   - assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body
635   - end
636   -
637   - def test_layout_rendering
638   - get :layout_test
639   - assert_equal "<html>Hello world!</html>", @response.body
640   - end
641   -
642   - def test_layout_test_with_different_layout
643   - get :layout_test_with_different_layout
644   - assert_equal "<html>Hello world!</html>", @response.body
645   - end
646   -
647   - def test_rendering_without_layout
648   - get :rendering_without_layout
649   - assert_equal "Hello world!", @response.body
650   - end
651   -
652   - def test_layout_overriding_layout
653   - get :layout_overriding_layout
654   - assert_no_match %r{<title>}, @response.body
655   - end
656   -
657   - def test_rendering_nothing_on_layout
658   - get :rendering_nothing_on_layout
659   - assert_equal " ", @response.body
660   - end
661   -
662   - def test_render_xml_with_layouts
663   - get :builder_layout_test
664   - assert_equal "<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n", @response.body
665   - end
666   -
667   - def test_partial_only
668   - get :partial_only
669   - assert_equal "only partial", @response.body
670   - end
671   -
672   - def test_partial_only_with_layout
673   - get :partial_only_with_layout
674   - assert_equal "<html>only partial</html>", @response.body
675   - end
676   -
677   - def test_render_to_string
678   - assert_not_deprecated { get :hello_in_a_string }
679   - assert_equal "How's there? goodbyeHello: davidHello: marygoodbye\n", @response.body
680   - end
681   -
682   - def test_render_to_string_doesnt_break_assigns
683   - get :render_to_string_with_assigns
684   - assert_equal "i'm before the render", assigns(:before)
685   - assert_equal "i'm after the render", assigns(:after)
686   - end
687   -
688   - def test_render_to_string_partial
689   - get :render_to_string_with_partial
690   - assert_equal "only partial", assigns(:partial_only)
691   - assert_equal "Hello: david", assigns(:partial_with_locals)
692   - end
693   -
694   - def test_bad_render_to_string_still_throws_exception
695   - assert_raises(ActionView::MissingTemplate) { get :render_to_string_with_exception }
696   - end
697   -
698   - def test_render_to_string_that_throws_caught_exception_doesnt_break_assigns
699   - assert_nothing_raised { get :render_to_string_with_caught_exception }
700   - assert_equal "i'm before the render", assigns(:before)
701   - assert_equal "i'm after the render", assigns(:after)
702   - end
703   -
704   - def test_nested_rendering
705   - get :hello_world
706   - assert_equal "Living in a nested world", Fun::GamesController.process(@request, @response).body
707   - end
708   -
709   - def test_accessing_params_in_template
710   - get :accessing_params_in_template, :name => "David"
711   - assert_equal "Hello: David", @response.body
712   - end
713   -
714   - def test_accessing_params_in_template_with_layout
715   - get :accessing_params_in_template_with_layout, :name => "David"
716   - assert_equal "<html>Hello: David</html>", @response.body
717   - end
718   -
719   - def test_render_with_explicit_template
720   - get :render_with_explicit_template
721   - assert_response :success
722   - end
723   -
724   - def test_double_render
725   - assert_raises(ActionController::DoubleRenderError) { get :double_render }
726   - end
727   -
728   - def test_double_redirect
729   - assert_raises(ActionController::DoubleRenderError) { get :double_redirect }
730   - end
731   -
732   - def test_render_and_redirect
733   - assert_raises(ActionController::DoubleRenderError) { get :render_and_redirect }
734   - end
735   -
736   - # specify the one exception to double render rule - render_to_string followed by render
737   - def test_render_to_string_and_render
738   - get :render_to_string_and_render
739   - assert_equal("Hi web users! here is some cached stuff", @response.body)
740   - end
741   -
742   - def test_rendering_with_conflicting_local_vars
743   - get :rendering_with_conflicting_local_vars
744   - assert_equal("First: David\nSecond: Stephan\nThird: David\nFourth: David\nFifth: ", @response.body)
745   - end
746   -
747   - def test_action_talk_to_layout
748   - get :action_talk_to_layout
749   - assert_equal "<title>Talking to the layout</title>\nAction was here!", @response.body
750   - end
751   -
752   - def test_partial_with_counter
753   - get :partial_with_counter
754   - assert_equal "5", @response.body
755   - end
756   -
757   - def test_partials_list
758   - get :partials_list
759   - assert_equal "goodbyeHello: davidHello: marygoodbye\n", @response.body
760   - end
761   -
762   - def test_partial_with_locals
763   - get :partial_with_locals
764   - assert_equal "Hello: david", @response.body
765   - end
766   -
767   - def test_partial_with_form_builder
768   - get :partial_with_form_builder
769   - assert_match(/<label/, @response.body)
770   - assert_template('test/_form')
771   - end
772   -
773   - def test_partial_with_form_builder_subclass
774   - get :partial_with_form_builder_subclass
775   - assert_match(/<label/, @response.body)
776   - assert_template('test/_labelling_form')
777   - end
778   -
779   - def test_partial_collection
780   - get :partial_collection
781   - assert_equal "Hello: davidHello: mary", @response.body
782   - end
783   -
784   - def test_partial_collection_with_as
785   - get :partial_collection_with_as
786   - assert_equal "david david davidmary mary mary", @response.body
787   - end
788   -
789   - def test_partial_collection_with_counter
790   - get :partial_collection_with_counter
791   - assert_equal "david0mary1", @response.body
792   - end
793   -
794   - def test_partial_collection_with_locals
795   - get :partial_collection_with_locals
796   - assert_equal "Bonjour: davidBonjour: mary", @response.body
797   - end
798   -
799   - def test_partial_collection_with_spacer
800   - get :partial_collection_with_spacer
801   - assert_equal "Hello: davidonly partialHello: mary", @response.body
802   - end
803   -
804   - def test_partial_collection_shorthand_with_locals
805   - get :partial_collection_shorthand_with_locals
806   - assert_equal "Bonjour: davidBonjour: mary", @response.body
807   - end
808   -
809   - def test_partial_collection_shorthand_with_different_types_of_records
810   - get :partial_collection_shorthand_with_different_types_of_records
811   - assert_equal "Bonjour bad customer: mark0Bonjour good customer: craig1Bonjour bad customer: john2Bonjour good customer: zach3Bonjour good customer: brandon4Bonjour bad customer: dan5", @response.body
812   - end
813   -
814   - def test_empty_partial_collection
815   - get :empty_partial_collection
816   - assert_equal " ", @response.body
817   - end
818   -
819   - def test_partial_with_hash_object
820   - get :partial_with_hash_object
821   - assert_equal "Sam\nmaS\n", @response.body
822   - end
823   -
824   - def test_hash_partial_collection
825   - get :partial_hash_collection
826   - assert_equal "Pratik\nkitarP\nAmy\nymA\n", @response.body
827   - end
828   -
829   - def test_partial_hash_collection_with_locals
830   - get :partial_hash_collection_with_locals
831   - assert_equal "Hola: PratikHola: Amy", @response.body
832   - end
833   -
834   - def test_partial_with_implicit_local_assignment
835   - assert_deprecated do
836   - get :partial_with_implicit_local_assignment
837   - assert_equal "Hello: Marcel", @response.body
838   - end
839   - end
840   -
841   - def test_render_missing_partial_template
842   - assert_raises(ActionView::MissingTemplate) do
843   - get :missing_partial
844   - end
845   - end
846   -
847   - def test_render_text_with_assigns
848   - get :render_text_with_assigns
849   - assert_equal "world", assigns["hello"]
850   - end
851   -
852   - def test_template_with_locals
853   - get :render_with_explicit_template_with_locals
854   - assert_equal "The secret is area51\n", @response.body
855   - end
856   -
857   - def test_update_page
858   - get :update_page
859   - assert_template nil
860   - assert_equal 'text/javascript; charset=utf-8', @response.headers['type']
861   - assert_equal 2, @response.body.split($/).length
862   - end
863   -
864   - def test_update_page_with_instance_variables
865   - get :update_page_with_instance_variables
866   - assert_template nil
867   - assert_equal 'text/javascript; charset=utf-8', @response.headers['type']
868   - assert_match /balance/, @response.body
869   - assert_match /\$37/, @response.body
870   - end
871   -
872   - def test_yield_content_for
873   - assert_not_deprecated { get :yield_content_for }
874   - assert_equal "<title>Putting stuff in the title!</title>\n\nGreat stuff!\n", @response.body
875   - end
876   -
877   -
878   - def test_overwritting_rendering_relative_file_with_extension
879   - get :hello_world_from_rxml_using_template
880   - assert_equal "<html>\n <p>Hello</p>\n</html>\n", @response.body
881   -
882   - get :hello_world_from_rxml_using_action
883   - assert_equal "<html>\n <p>Hello</p>\n</html>\n", @response.body
884   - end
885   -
886   -
887   - def test_head_with_location_header
888   - get :head_with_location_header
889   - assert @response.body.blank?
890   - assert_equal "/foo", @response.headers["Location"]
891   - assert_response :ok
892   - end
893   -
894   - def test_head_with_custom_header
895   - get :head_with_custom_header
896   - assert @response.body.blank?
897   - assert_equal "something", @response.headers["X-Custom-Header"]
898   - assert_response :ok
899   - end
900   -
901   - def test_head_with_symbolic_status
902   - get :head_with_symbolic_status, :status => "ok"
903   - assert_equal "200 OK", @response.headers["Status"]
904   - assert_response :ok
905   -
906   - get :head_with_symbolic_status, :status => "not_found"
907   - assert_equal "404 Not Found", @response.headers["Status"]
908   - assert_response :not_found
909   -
910   - ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code|
911   - get :head_with_symbolic_status, :status => status.to_s
912   - assert_equal code, @response.response_code
913   - assert_response status
914   - end
915   - end
916   -
917   - def test_head_with_integer_status
918   - ActionController::StatusCodes::STATUS_CODES.each do |code, message|
919   - get :head_with_integer_status, :status => code.to_s
920   - assert_equal message, @response.message
921   - end
922   - end
923   -
924   - def test_head_with_string_status
925   - get :head_with_string_status, :status => "404 Eat Dirt"
926   - assert_equal 404, @response.response_code
927   - assert_equal "Eat Dirt", @response.message
928   - assert_response :not_found
929   - end
930   -
931   - def test_head_with_status_code_first
932   - get :head_with_status_code_first
933   - assert_equal 403, @response.response_code
934   - assert_equal "Forbidden", @response.message
935   - assert_equal "something", @response.headers["X-Custom-Header"]
936   - assert_response :forbidden
937   - end
938   -
939   - def test_rendering_with_location_should_set_header
940   - get :render_with_location
941   - assert_equal "http://example.com", @response.headers["Location"]
942   - end
943   -
944   - def test_rendering_xml_should_call_to_xml_if_possible
945   - get :render_with_to_xml
946   - assert_equal "<i-am-xml/>", @response.body
947   - end
948   -
949   - def test_rendering_with_object_location_should_set_header_with_url_for
950   - ActionController::Routing::Routes.draw do |map|
951   - map.resources :customers
952   - map.connect ':controller/:action/:id'
953   - end
954   -
955   - get :render_with_object_location
956   - assert_equal "http://www.nextangle.com/customers/1", @response.headers["Location"]
957   - end
958   -
959   - def test_render_call_to_partial_with_layout
960   - get :render_call_to_partial_with_layout
961   - assert_equal "Before (David)\nInside from partial (David)\nAfter", @response.body
962   - end
963   -
964   - def test_render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout
965   - get :render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout
966   - assert_equal "Before (Anthony)\nInside from partial (Anthony)\nAfter\nBefore (David)\nInside from partial (David)\nAfter\nBefore (Ramm)\nInside from partial (Ramm)\nAfter", @response.body
967   - end
968   -
969   - def test_using_layout_around_block
970   - get :render_using_layout_around_block
971   - assert_equal "Before (David)\nInside from block\nAfter", @response.body
972   - end
973   -
974   - def test_using_layout_around_block_in_main_layout_and_within_content_for_layout
975   - get :render_using_layout_around_block_in_main_layout_and_within_content_for_layout
976   - assert_equal "Before (Anthony)\nInside from first block in layout\nAfter\nBefore (David)\nInside from block\nAfter\nBefore (Ramm)\nInside from second block in layout\nAfter\n", @response.body
977   - end
978   -
979   - def test_using_layout_around_block_with_args
980   - get :render_using_layout_around_block_with_args
981   - assert_equal "Before\narg1arg2\nAfter", @response.body
982   - end
983   -end
849 actionpack/test/controller/render_test.rb
@@ -9,6 +9,9 @@ def hello_world
9 9 end
10 10
11 11 class TestController < ActionController::Base
  12 + class LabellingFormBuilder < ActionView::Helpers::FormBuilder
  13 + end
  14 +
12 15 layout :determine_layout
13 16
14 17 def hello_world
@@ -58,6 +61,57 @@ def render_text_hello_world
58 61 render :text => "hello world"
59 62 end
60 63
  64 + def render_text_hello_world_with_layout
  65 + @variable_for_layout = ", I'm here!"
  66 + render :text => "hello world", :layout => true
  67 + end
  68 +
  69 + def hello_world_with_layout_false
  70 + render :layout => false
  71 + end
  72 +
  73 + def render_file_with_instance_variables
  74 + @secret = 'in the sauce'
  75 + path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb')
  76 + render :file => path
  77 + end
  78 +
  79 + def render_file_not_using_full_path
  80 + @secret = 'in the sauce'
  81 + render :file => 'test/render_file_with_ivar'
  82 + end
  83 +
  84 + def render_file_not_using_full_path_with_dot_in_path
  85 + @secret = 'in the sauce'
  86 + render :file => 'test/dot.directory/render_file_with_ivar'
  87 + end
  88 +
  89 + def render_file_from_template
  90 + @secret = 'in the sauce'
  91 + @path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb'))
  92 + end
  93 +
  94 + def render_file_with_locals
  95 + path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_locals.erb')
  96 + render :file => path, :locals => {:secret => 'in the sauce'}
  97 + end
  98 +
  99 + def accessing_request_in_template
  100 + render :inline => "Hello: <%= request.host %>"
  101 + end
  102 +
  103 + def accessing_logger_in_template
  104 + render :inline => "<%= logger.class %>"
  105 + end
  106 +
  107 + def accessing_action_name_in_template
  108 + render :inline => "<%= action_name %>"
  109 + end
  110 +
  111 + def accessing_controller_name_in_template
  112 + render :inline => "<%= controller_name %>"
  113 + end
  114 +
61 115 def render_json_hello_world
62 116 render :json => {:hello => 'world'}.to_json
63 117 end
@@ -126,7 +180,7 @@ def layout_test
126 180 end
127 181
128 182 def builder_layout_test
129   - render :action => "hello"
  183 + render :action => "hello", :layout => "layouts/builder"
130 184 end
131 185
132 186 def builder_partial_test
@@ -168,8 +222,226 @@ def render_to_string_test
168 222 @foo = render_to_string :inline => "this is a test"
169 223 end
170 224
171   - def partial
172   - render :partial => 'partial'
  225 + def default_render
  226 + if @alternate_default_render
  227 + @alternate_default_render.call
  228 + else
  229 + render
  230 + end
  231 + end
  232 +
  233 + def render_action_hello_world_as_symbol
  234 + render :action => :hello_world
  235 + end
  236 +
  237 + def layout_test_with_different_layout
  238 + render :action => "hello_world", :layout => "standard"
  239 + end
  240 +
  241 + def rendering_without_layout
  242 + render :action => "hello_world", :layout => false
  243 + end
  244 +
  245 + def layout_overriding_layout
  246 + render :action => "hello_world", :layout => "standard"
  247 + end
  248 +
  249 + def rendering_nothing_on_layout
  250 + render :nothing => true
  251 + end
  252 +
  253 + def render_to_string_with_assigns
  254 + @before = "i'm before the render"
  255 + render_to_string :text => "foo"
  256 + @after = "i'm after the render"
  257 + render :action => "test/hello_world"
  258 + end
  259 +
  260 + def render_to_string_with_exception
  261 + render_to_string :file => "exception that will not be caught - this will certainly not work"
  262 + end
  263 +
  264 + def render_to_string_with_caught_exception
  265 + @before = "i'm before the render"
  266 + begin
  267 + render_to_string :file => "exception that will be caught- hope my future instance vars still work!"
  268 + rescue
  269 + end
  270 + @after = "i'm after the render"
  271 + render :action => "test/hello_world"
  272 + end
  273 +
  274 + def accessing_params_in_template_with_layout
  275 + render :layout => nil, :inline => "Hello: <%= params[:name] %>"
  276 + end
  277 +
  278 + def render_with_explicit_template
  279 + render :template => "test/hello_world"
  280 + end
  281 +
  282 + def render_with_explicit_template_with_locals
  283 + render :template => "test/render_file_with_locals", :locals => { :secret => 'area51' }
  284 + end
  285 +
  286 + def double_render
  287 + render :text => "hello"
  288 + render :text => "world"
  289 + end
  290 +
  291 + def double_redirect
  292 + redirect_to :action => "double_render"
  293 + redirect_to :action => "double_render"