Skip to content
This repository
Browse code

Cleaning up more render tests

  • Loading branch information...
commit 8fac2c88cae0f2fd42fad3c2c2c6c860df14d629 1 parent 49a84ff
authored May 14, 2009
3  actionpack/lib/action_controller/abstract.rb
... ...
@@ -1,3 +1,6 @@
  1
+require "active_support/core_ext/module/attr_internal"
  2
+require "active_support/core_ext/module/delegation"
  3
+
1 4
 module AbstractController
2 5
   autoload :Base,           "action_controller/abstract/base"
3 6
   autoload :Callbacks,      "action_controller/abstract/callbacks"
9  actionpack/lib/action_controller/abstract/base.rb
@@ -23,6 +23,15 @@ def abstract!
23 23
       end
24 24
       
25 25
       alias_method :abstract?, :abstract
  26
+
  27
+      def inherited(klass)
  28
+        ::AbstractController::Base.subclasses << klass.to_s
  29
+        super
  30
+      end
  31
+
  32
+      def subclasses
  33
+        @subclasses ||= []
  34
+      end
26 35
       
27 36
       def internal_methods
28 37
         controller = self
1  actionpack/lib/action_view.rb
@@ -24,6 +24,7 @@
24 24
 activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
25 25
 $:.unshift activesupport_path if File.directory?(activesupport_path)
26 26
 require 'active_support'
  27
+require 'active_support/core_ext/class/attribute_accessors'
27 28
 
28 29
 require File.join(File.dirname(__FILE__), "action_pack")
29 30
 
2  actionpack/lib/action_view/helpers/tag_helper.rb
@@ -9,7 +9,7 @@ module TagHelper
9 9
       include ERB::Util
10 10
 
11 11
       BOOLEAN_ATTRIBUTES = %w(disabled readonly multiple checked).to_set
12  
-      BOOLEAN_ATTRIBUTES.merge(BOOLEAN_ATTRIBUTES.map(&:to_sym))
  12
+      BOOLEAN_ATTRIBUTES.merge(BOOLEAN_ATTRIBUTES.map {|attr| attr.to_sym })
13 13
 
14 14
       # Returns an empty HTML tag of type +name+ which by default is XHTML
15 15
       # compliant. Set +open+ to true to create an open tag compatible
5  actionpack/test/controller/render_test.rb
@@ -262,6 +262,7 @@ def layout_test
262 262
     render :action => "hello_world"
263 263
   end
264 264
 
  265
+  # :ported:
265 266
   def builder_layout_test
266 267
     render :action => "hello", :layout => "layouts/builder"
267 268
   end
@@ -271,6 +272,7 @@ def builder_partial_test
271 272
     render :action => "hello_world_container"
272 273
   end
273 274
 
  275
+  # :ported:
274 276
   def partials_list
275 277
     @test_unchanged = 'hello'
276 278
     @customers = [ Customer.new("david"), Customer.new("mary") ]
@@ -860,6 +862,7 @@ def test_render_xml
860 862
     assert_equal "application/xml", @response.content_type
861 863
   end
862 864
 
  865
+  # :ported:
863 866
   def test_render_xml_as_string_template
864 867
     get :render_xml_hello_as_string_template
865 868
     assert_equal "<html>\n  <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body
@@ -872,11 +875,13 @@ def test_render_xml_with_default
872 875
     assert_equal "<p>This is grand!</p>\n", @response.body
873 876
   end
874 877
 
  878
+  # :move: test in AV
875 879
   def test_render_xml_with_partial
876 880
     get :builder_partial_test
877 881
     assert_equal "<test>\n  <hello/>\n</test>\n", @response.body
878 882
   end
879 883
 
  884
+  # :ported:
880 885
   def test_layout_rendering
881 886
     get :layout_test
882 887
     assert_equal "<html>Hello world!</html>", @response.body
17  actionpack/test/new_base/render_action_test.rb
@@ -131,8 +131,10 @@ class BasicController < ::ApplicationController
131 131
     # Set the view path to an application view structure with layouts
132 132
     self.view_paths = self.view_paths = [ActionView::Template::FixturePath.new(
133 133
       "render_action_with_application_layout/basic/hello_world.html.erb" => "Hello World!",
  134
+      "render_action_with_application_layout/basic/hello.html.builder"   => "xml.p 'Omg'",
134 135
       "layouts/application.html.erb"                                     => "OHAI <%= yield %> KTHXBAI",
135  
-      "layouts/greetings.html.erb"                                       => "Greetings <%= yield %> Bai"
  136
+      "layouts/greetings.html.erb"                                       => "Greetings <%= yield %> Bai",
  137
+      "layouts/builder.html.builder"                                     => "xml.html do\n  xml << yield\nend"
136 138
     )]
137 139
     
138 140
     def hello_world
@@ -154,6 +156,10 @@ def hello_world_with_layout_nil
154 156
     def hello_world_with_custom_layout
155 157
       render :action => "hello_world", :layout => "greetings"
156 158
     end
  159
+    
  160
+    def with_builder_and_layout
  161
+      render :action => "hello", :layout => "builder"
  162
+    end
157 163
   end
158 164
   
159 165
   class TestDefaultLayout < SimpleRouteCase
@@ -199,6 +205,15 @@ class TestCustomLayout < SimpleRouteCase
199 205
     assert_status 200
200 206
   end
201 207
   
  208
+  class TestLayout < SimpleRouteCase
  209
+    testing BasicController
  210
+    
  211
+    test "builder works with layouts" do
  212
+      get :with_builder_and_layout
  213
+      assert_response "<html>\n<p>Omg</p>\n</html>\n"
  214
+    end
  215
+  end
  216
+  
202 217
 end
203 218
 
204 219
 module RenderActionWithControllerLayout
2  actionpack/test/new_base/render_layout_test.rb
@@ -22,8 +22,6 @@ def layout_false
22 22
       render :layout => false
23 23
     end
24 24
     
25  
-    
26  
-    
27 25
     def builder_override
28 26
       
29 27
     end
27  actionpack/test/new_base/render_partial_test.rb
... ...
@@ -0,0 +1,27 @@
  1
+require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
  2
+
  3
+module RenderPartial
  4
+  
  5
+  class BasicController < ActionController::Base
  6
+    
  7
+    self.view_paths = [ActionView::Template::FixturePath.new(
  8
+      "render_partial/basic/_basic.html.erb"    => "OMG!",
  9
+      "render_partial/basic/basic.html.erb"      => "<%= @test_unchanged = 'goodbye' %><%= render :partial => 'basic' %><%= @test_unchanged %>"
  10
+    )]
  11
+    
  12
+    def changing
  13
+      @test_unchanged = 'hello'
  14
+      render :action => "basic"
  15
+    end    
  16
+  end
  17
+  
  18
+  class TestPartial < SimpleRouteCase
  19
+    testing BasicController
  20
+    
  21
+    test "rendering a partial in ActionView doesn't pull the ivars again from the controller" do
  22
+      get :changing
  23
+      assert_response("goodbyeOMG!goodbye")
  24
+    end
  25
+  end
  26
+  
  27
+end
76  actionpack/test/new_base/render_template_test.rb
@@ -4,14 +4,19 @@ module RenderTemplate
4 4
   class WithoutLayoutController < ActionController::Base
5 5
     
6 6
     self.view_paths = [ActionView::Template::FixturePath.new(
7  
-      "test/basic.html.erb" => "Hello from basic.html.erb",
8  
-      "shared.html.erb"     => "Elastica",
9  
-      "locals.html.erb"     => "The secret is <%= secret %>"
  7
+      "test/basic.html.erb"      => "Hello from basic.html.erb",
  8
+      "shared.html.erb"          => "Elastica",
  9
+      "locals.html.erb"          => "The secret is <%= secret %>",
  10
+      "xml_template.xml.builder" => "xml.html do\n  xml.p 'Hello'\nend"
10 11
     )]
11 12
     
12 13
     def index
13 14
       render :template => "test/basic"
14 15
     end
  16
+    
  17
+    def index_without_key
  18
+      render "test/basic"
  19
+    end
15 20
 
16 21
     def in_top_directory
17 22
       render :template => 'shared'
@@ -21,41 +26,56 @@ def in_top_directory_with_slash
21 26
       render :template => '/shared'
22 27
     end
23 28
     
  29
+    def in_top_directory_with_slash_without_key
  30
+      render '/shared'
  31
+    end
  32
+    
24 33
     def with_locals
25 34
       render :template => "locals", :locals => { :secret => 'area51' }
26 35
     end
  36
+    
  37
+    def builder_template
  38
+      render :template => "xml_template"
  39
+    end
27 40
   end
28 41
   
29 42
   class TestWithoutLayout < SimpleRouteCase
30  
-    describe "rendering a normal template with full path without layout"
  43
+    testing RenderTemplate::WithoutLayoutController
31 44
     
32  
-    get "/render_template/without_layout"
33  
-    assert_body   "Hello from basic.html.erb"
34  
-    assert_status 200
35  
-  end
36  
-  
37  
-  class TestTemplateRenderInTopDirectory < SimpleRouteCase
38  
-    describe "rendering a template not in a subdirectory"
  45
+    test "rendering a normal template with full path without layout" do
  46
+      get :index
  47
+      assert_response "Hello from basic.html.erb"
  48
+    end
39 49
     
40  
-    get "/render_template/without_layout/in_top_directory"
41  
-    assert_body   "Elastica"
42  
-    assert_status 200
43  
-  end
44  
-
45  
-  class TestTemplateRenderInTopDirectoryWithSlash < SimpleRouteCase
46  
-    describe "rendering a template not in a subdirectory with a leading slash"
  50
+    test "rendering a normal template with full path without layout without key" do
  51
+      get :index_without_key
  52
+      assert_response "Hello from basic.html.erb"
  53
+    end
47 54
     
48  
-    get "/render_template/without_layout/in_top_directory_with_slash"
49  
-    assert_body   "Elastica"
50  
-    assert_status 200
51  
-  end
52  
-  
53  
-  class TestTemplateRenderWithLocals < SimpleRouteCase
54  
-    describe "rendering a template with local variables"
  55
+    test "rendering a template not in a subdirectory" do
  56
+      get :in_top_directory
  57
+      assert_response "Elastica"
  58
+    end
55 59
     
56  
-    get "/render_template/without_layout/with_locals"
57  
-    assert_body   "The secret is area51"
58  
-    assert_status 200
  60
+    test "rendering a template not in a subdirectory with a leading slash" do
  61
+      get :in_top_directory_with_slash
  62
+      assert_response "Elastica"
  63
+    end
  64
+    
  65
+    test "rendering a template not in a subdirectory with a leading slash without key" do
  66
+      get :in_top_directory_with_slash_without_key
  67
+      assert_response "Elastica"
  68
+    end
  69
+    
  70
+    test "rendering a template with local variables" do
  71
+      get :with_locals
  72
+      assert_response "The secret is area51"
  73
+    end
  74
+    
  75
+    test "rendering a builder template" do
  76
+      get :builder_template
  77
+      assert_response "<html>\n  <p>Hello</p>\n</html>\n"
  78
+    end
59 79
   end
60 80
     
61 81
   class WithLayoutController < ::ApplicationController
11  actionpack/test/new_base/render_xml_test.rb
... ...
@@ -0,0 +1,11 @@
  1
+require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
  2
+
  3
+module RenderXml
  4
+  
  5
+  # This has no layout and it works
  6
+  class BasicController < ActionController::Base
  7
+    self.view_paths = [ActionView::Template::FixturePath.new(
  8
+      "render_xml/basic/with_render_erb" => "Hello world!"
  9
+    )]
  10
+  end
  11
+end
2  actionpack/test/new_base/test_helper.rb
@@ -46,7 +46,7 @@ class Rack::TestCase < ActiveSupport::TestCase
46 46
     ActionController::Routing.use_controllers!(controllers)
47 47
     
48 48
     # Move into a bootloader
49  
-    AbstractController::Base.subclasses.each do |klass|
  49
+    ActionController::Base.subclasses.each do |klass|
50 50
       klass = klass.constantize
51 51
       next unless klass < AbstractController::Layouts
52 52
       klass.class_eval do

0 notes on commit 8fac2c8

Please sign in to comment.
Something went wrong with that request. Please try again.