actionpack 1.11.2 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

Files changed (149) hide show
  1. data/CHANGELOG +392 -5
  2. data/lib/action_controller.rb +8 -4
  3. data/lib/action_controller/assertions.rb +9 -10
  4. data/lib/action_controller/base.rb +177 -88
  5. data/lib/action_controller/benchmarking.rb +5 -5
  6. data/lib/action_controller/caching.rb +44 -36
  7. data/lib/action_controller/cgi_ext/cgi_methods.rb +71 -6
  8. data/lib/action_controller/cgi_ext/cookie_performance_fix.rb +1 -1
  9. data/lib/action_controller/cgi_process.rb +36 -24
  10. data/lib/action_controller/components.rb +152 -52
  11. data/lib/action_controller/dependencies.rb +1 -1
  12. data/lib/action_controller/deprecated_redirects.rb +2 -2
  13. data/lib/action_controller/deprecated_request_methods.rb +34 -0
  14. data/lib/action_controller/filters.rb +59 -19
  15. data/lib/action_controller/flash.rb +53 -47
  16. data/lib/action_controller/helpers.rb +2 -2
  17. data/lib/action_controller/integration.rb +524 -0
  18. data/lib/action_controller/layout.rb +58 -23
  19. data/lib/action_controller/mime_responds.rb +163 -0
  20. data/lib/action_controller/mime_type.rb +142 -0
  21. data/lib/action_controller/pagination.rb +13 -7
  22. data/lib/action_controller/request.rb +59 -56
  23. data/lib/action_controller/rescue.rb +1 -1
  24. data/lib/action_controller/routing.rb +29 -10
  25. data/lib/action_controller/scaffolding.rb +8 -0
  26. data/lib/action_controller/session/active_record_store.rb +21 -10
  27. data/lib/action_controller/session/mem_cache_store.rb +18 -12
  28. data/lib/action_controller/session_management.rb +30 -11
  29. data/lib/action_controller/templates/rescues/_trace.rhtml +1 -1
  30. data/lib/action_controller/templates/scaffolds/layout.rhtml +4 -4
  31. data/lib/action_controller/templates/scaffolds/list.rhtml +1 -1
  32. data/lib/action_controller/test_process.rb +189 -118
  33. data/lib/action_controller/vendor/html-scanner/html/node.rb +20 -1
  34. data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +3 -0
  35. data/lib/action_controller/vendor/html-scanner/html/version.rb +1 -1
  36. data/lib/action_controller/vendor/xml_node.rb +97 -0
  37. data/lib/action_controller/verification.rb +2 -0
  38. data/lib/action_pack/version.rb +3 -3
  39. data/lib/action_view.rb +0 -2
  40. data/lib/action_view/base.rb +109 -36
  41. data/lib/action_view/compiled_templates.rb +1 -1
  42. data/lib/action_view/helpers/active_record_helper.rb +4 -2
  43. data/lib/action_view/helpers/asset_tag_helper.rb +6 -7
  44. data/lib/action_view/helpers/capture_helper.rb +49 -12
  45. data/lib/action_view/helpers/date_helper.rb +14 -4
  46. data/lib/action_view/helpers/form_helper.rb +136 -20
  47. data/lib/action_view/helpers/form_options_helper.rb +29 -7
  48. data/lib/action_view/helpers/form_tag_helper.rb +22 -20
  49. data/lib/action_view/helpers/java_script_macros_helper.rb +29 -9
  50. data/lib/action_view/helpers/javascript_helper.rb +50 -446
  51. data/lib/action_view/helpers/javascripts/controls.js +95 -30
  52. data/lib/action_view/helpers/javascripts/dragdrop.js +161 -21
  53. data/lib/action_view/helpers/javascripts/effects.js +310 -211
  54. data/lib/action_view/helpers/javascripts/prototype.js +228 -28
  55. data/lib/action_view/helpers/number_helper.rb +9 -9
  56. data/lib/action_view/helpers/pagination_helper.rb +1 -1
  57. data/lib/action_view/helpers/prototype_helper.rb +900 -0
  58. data/lib/action_view/helpers/scriptaculous_helper.rb +135 -0
  59. data/lib/action_view/helpers/text_helper.rb +7 -6
  60. data/lib/action_view/helpers/url_helper.rb +23 -14
  61. data/lib/action_view/partials.rb +12 -4
  62. data/rakefile +13 -5
  63. data/test/abstract_unit.rb +4 -3
  64. data/test/active_record_unit.rb +88 -0
  65. data/test/{controller → activerecord}/active_record_assertions_test.rb +7 -50
  66. data/test/{controller → activerecord}/active_record_store_test.rb +27 -4
  67. data/test/activerecord/pagination_test.rb +161 -0
  68. data/test/controller/action_pack_assertions_test.rb +18 -15
  69. data/test/controller/base_test.rb +31 -42
  70. data/test/controller/benchmark_test.rb +8 -11
  71. data/test/controller/capture_test.rb +33 -1
  72. data/test/controller/cgi_test.rb +33 -0
  73. data/test/controller/custom_handler_test.rb +8 -0
  74. data/test/controller/fake_controllers.rb +9 -17
  75. data/test/controller/filters_test.rb +32 -3
  76. data/test/controller/flash_test.rb +26 -41
  77. data/test/controller/fragment_store_setting_test.rb +1 -1
  78. data/test/controller/layout_test.rb +73 -0
  79. data/test/controller/mime_responds_test.rb +257 -0
  80. data/test/controller/mime_type_test.rb +24 -0
  81. data/test/controller/new_render_test.rb +157 -1
  82. data/test/controller/redirect_test.rb +23 -0
  83. data/test/controller/render_test.rb +54 -56
  84. data/test/controller/request_test.rb +25 -0
  85. data/test/controller/routing_test.rb +74 -66
  86. data/test/controller/test_test.rb +66 -1
  87. data/test/controller/verification_test.rb +3 -1
  88. data/test/controller/webservice_test.rb +255 -0
  89. data/test/fixtures/companies.yml +24 -0
  90. data/test/fixtures/company.rb +9 -0
  91. data/test/fixtures/db_definitions/sqlite.sql +42 -0
  92. data/test/fixtures/developer.rb +7 -0
  93. data/test/fixtures/developers.yml +21 -0
  94. data/test/fixtures/developers_projects.yml +13 -0
  95. data/test/fixtures/layout_tests/layouts/controller_name_space/nested.rhtml +1 -0
  96. data/test/fixtures/layout_tests/layouts/item.rhtml +1 -0
  97. data/test/fixtures/layout_tests/layouts/layout_test.rhtml +1 -0
  98. data/test/fixtures/layout_tests/layouts/third_party_template_library.mab +1 -0
  99. data/test/fixtures/layout_tests/views/hello.rhtml +1 -0
  100. data/test/fixtures/multipart/mona_lisa.jpg +0 -0
  101. data/test/fixtures/project.rb +3 -0
  102. data/test/fixtures/projects.yml +7 -0
  103. data/test/fixtures/replies.yml +13 -0
  104. data/test/fixtures/reply.rb +5 -0
  105. data/test/fixtures/respond_to/all_types_with_layout.rhtml +1 -0
  106. data/test/fixtures/respond_to/all_types_with_layout.rjs +1 -0
  107. data/test/fixtures/respond_to/layouts/standard.rhtml +1 -0
  108. data/test/fixtures/respond_to/using_defaults.rhtml +1 -0
  109. data/test/fixtures/respond_to/using_defaults.rjs +1 -0
  110. data/test/fixtures/respond_to/using_defaults.rxml +1 -0
  111. data/test/fixtures/respond_to/using_defaults_with_type_list.rhtml +1 -0
  112. data/test/fixtures/respond_to/using_defaults_with_type_list.rjs +1 -0
  113. data/test/fixtures/respond_to/using_defaults_with_type_list.rxml +1 -0
  114. data/test/fixtures/test/block_content_for.rhtml +2 -0
  115. data/test/fixtures/test/delete_with_js.rjs +2 -0
  116. data/test/fixtures/test/dot.directory/render_file_with_ivar.rhtml +1 -0
  117. data/test/fixtures/test/enum_rjs_test.rjs +6 -0
  118. data/test/fixtures/test/erb_content_for.rhtml +2 -0
  119. data/test/fixtures/test/hello_world.rxml +3 -0
  120. data/test/fixtures/test/hello_world_with_layout_false.rhtml +1 -0
  121. data/test/fixtures/test/non_erb_block_content_for.rxml +4 -0
  122. data/test/fixtures/topic.rb +3 -0
  123. data/test/fixtures/topics.yml +22 -0
  124. data/test/template/active_record_helper_test.rb +4 -0
  125. data/test/template/asset_tag_helper_test.rb +7 -2
  126. data/test/template/date_helper_test.rb +39 -2
  127. data/test/template/form_helper_test.rb +238 -5
  128. data/test/template/form_options_helper_test.rb +78 -0
  129. data/test/template/form_tag_helper_test.rb +11 -0
  130. data/test/template/java_script_macros_helper_test.rb +51 -6
  131. data/test/template/javascript_helper_test.rb +7 -153
  132. data/test/template/number_helper_test.rb +14 -13
  133. data/test/template/prototype_helper_test.rb +423 -0
  134. data/test/template/scriptaculous_helper_test.rb +90 -0
  135. data/test/template/text_helper_test.rb +12 -9
  136. data/test/template/url_helper_test.rb +31 -15
  137. metadata +291 -246
  138. data/lib/action_controller/cgi_ext/multipart_progress.rb +0 -169
  139. data/lib/action_controller/upload_progress.rb +0 -473
  140. data/lib/action_controller/vendor/html-scanner/html/node.rb.rej +0 -17
  141. data/lib/action_view/helpers/upload_progress_helper.rb +0 -433
  142. data/lib/action_view/vendor/builder.rb +0 -13
  143. data/lib/action_view/vendor/builder/blankslate.rb +0 -53
  144. data/lib/action_view/vendor/builder/xmlbase.rb +0 -143
  145. data/lib/action_view/vendor/builder/xmlevents.rb +0 -63
  146. data/lib/action_view/vendor/builder/xmlmarkup.rb +0 -308
  147. data/test/controller/multipart_progress_testx.rb +0 -365
  148. data/test/controller/upload_progress_testx.rb +0 -89
  149. data/test/template/upload_progress_helper_testx.rb +0 -136
@@ -1,45 +1,6 @@
1
- require "#{File.dirname(__FILE__)}/../abstract_unit"
2
-
3
- # Unfurl the safety net.
4
- path_to_ar = File.dirname(__FILE__) + '/../../../activerecord'
5
- if Object.const_defined?(:ActiveRecord) || File.exist?(path_to_ar)
6
- begin
7
-
8
- # These tests require Active Record, so you're going to need AR in a
9
- # sibling directory to AP and have SQLite installed.
10
-
11
- unless Object.const_defined?(:ActiveRecord)
12
- require "#{path_to_ar}/lib/active_record"
13
- end
14
-
15
- begin
16
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :dbfile => ':memory:')
17
- ActiveRecord::Base.connection
18
- rescue Object
19
- $stderr.puts 'SQLite 3 unavailable; falling to SQLite 2.'
20
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite', :dbfile => ':memory:')
21
- ActiveRecord::Base.connection
22
- end
23
-
24
- # Set up company fixtures.
25
- $LOAD_PATH << "#{path_to_ar}/test"
26
- QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name('type') unless Object.const_defined?(:QUOTED_TYPE)
1
+ require "#{File.dirname(__FILE__)}/../active_record_unit"
27
2
  require 'fixtures/company'
28
- File.read("#{path_to_ar}/test/fixtures/db_definitions/sqlite.sql").split(';').each do |sql|
29
- ActiveRecord::Base.connection.execute(sql) unless sql.blank?
30
- end
31
-
32
- # Add some validation rules to trip up the assertions.
33
- class Company
34
- protected
35
- def validate
36
- errors.add_on_empty('name')
37
- errors.add('rating', 'rating should not be 2') if rating == 2
38
- errors.add_to_base('oh oh') if rating == 3
39
- end
40
- end
41
3
 
42
- # A controller to host the assertions.
43
4
  class ActiveRecordAssertionsController < ActionController::Base
44
5
  self.template_root = "#{File.dirname(__FILE__)}/../fixtures/"
45
6
 
@@ -76,12 +37,15 @@ class ActiveRecordAssertionsController < ActionController::Base
76
37
  # the safety dance......
77
38
  def rescue_action(e) raise; end
78
39
  end
79
-
80
- class ActiveRecordAssertionsControllerTest < Test::Unit::TestCase
40
+
41
+ class ActiveRecordAssertionsControllerTest < ActiveRecordTestCase
42
+ fixtures :companies
43
+
81
44
  def setup
82
45
  @request = ActionController::TestRequest.new
83
46
  @response = ActionController::TestResponse.new
84
47
  @controller = ActiveRecordAssertionsController.new
48
+ super
85
49
  end
86
50
 
87
51
  # test for 1 bad apple column
@@ -117,11 +81,4 @@ class ActiveRecordAssertionsControllerTest < Test::Unit::TestCase
117
81
  assert_success
118
82
  assert_invalid_record 'company'
119
83
  end
120
- end
121
-
122
- # End of safety net.
123
- rescue Object => e
124
- $stderr.puts "Skipping Active Record assertion tests: #{e}"
125
- #$stderr.puts " #{e.backtrace.join("\n ")}"
126
- end
127
- end
84
+ end
@@ -62,6 +62,10 @@ class ActiveRecordStoreTest < Test::Unit::TestCase
62
62
  CGI::Session::ActiveRecordStore::Session
63
63
  end
64
64
 
65
+ def session_id_column
66
+ "session_id"
67
+ end
68
+
65
69
  def setup
66
70
  session_class.create_table!
67
71
 
@@ -73,16 +77,31 @@ class ActiveRecordStoreTest < Test::Unit::TestCase
73
77
  @new_session['foo'] = 'bar'
74
78
  end
75
79
 
76
- def test_another_instance
77
- @another = CGI::Session.new(@cgi, 'session_id' => @new_session.session_id, 'database_manager' => CGI::Session::ActiveRecordStore)
78
- assert_equal @new_session.session_id, @another.session_id
79
- end
80
+ # this test only applies for eager sesssion saving
81
+ # def test_another_instance
82
+ # @another = CGI::Session.new(@cgi, 'session_id' => @new_session.session_id, 'database_manager' => CGI::Session::ActiveRecordStore)
83
+ # assert_equal @new_session.session_id, @another.session_id
84
+ # end
80
85
 
81
86
  def test_model_attribute
82
87
  assert_kind_of CGI::Session::ActiveRecordStore::Session, @new_session.model
83
88
  assert_equal({ 'foo' => 'bar' }, @new_session.model.data)
84
89
  end
85
90
 
91
+ def test_save_unloaded_session
92
+ c = session_class.connection
93
+ bogus_class = c.quote(Base64.encode64("\004\010o:\vBlammo\000"))
94
+ c.insert("INSERT INTO #{session_class.table_name} ('#{session_id_column}', 'data') VALUES ('abcdefghijklmnop', #{bogus_class})")
95
+
96
+ sess = session_class.find_by_session_id('abcdefghijklmnop')
97
+ assert_not_nil sess
98
+ assert !sess.loaded?
99
+
100
+ # because the session is not loaded, the save should be a no-op. If it
101
+ # isn't, this'll try and unmarshall the bogus class, and should get an error.
102
+ assert_nothing_raised { sess.save }
103
+ end
104
+
86
105
  def teardown
87
106
  session_class.drop_table!
88
107
  end
@@ -109,6 +128,10 @@ class ColumnLimitTest < Test::Unit::TestCase
109
128
  end
110
129
 
111
130
  class DeprecatedActiveRecordStoreTest < ActiveRecordStoreTest
131
+ def session_id_column
132
+ "sessid"
133
+ end
134
+
112
135
  def setup
113
136
  session_class.connection.execute 'create table old_sessions (id integer primary key, sessid text unique, data text)'
114
137
  session_class.table_name = 'old_sessions'
@@ -0,0 +1,161 @@
1
+ require File.dirname(__FILE__) + '/../active_record_unit'
2
+
3
+ require 'fixtures/topic'
4
+ require 'fixtures/reply'
5
+ require 'fixtures/developer'
6
+ require 'fixtures/project'
7
+
8
+ class PaginationTest < ActiveRecordTestCase
9
+ fixtures :topics, :replies, :developers, :projects, :developers_projects
10
+
11
+ class PaginationController < ActionController::Base
12
+ self.template_root = "#{File.dirname(__FILE__)}/../fixtures/"
13
+
14
+ def simple_paginate
15
+ @topic_pages, @topics = paginate(:topics)
16
+ render :nothing => true
17
+ end
18
+
19
+ def paginate_with_per_page
20
+ @topic_pages, @topics = paginate(:topics, :per_page => 1)
21
+ render :nothing => true
22
+ end
23
+
24
+ def paginate_with_order
25
+ @topic_pages, @topics = paginate(:topics, :order => 'created_at asc')
26
+ render :nothing => true
27
+ end
28
+
29
+ def paginate_with_order_by
30
+ @topic_pages, @topics = paginate(:topics, :order_by => 'created_at asc')
31
+ render :nothing => true
32
+ end
33
+
34
+ def paginate_with_include_and_order
35
+ @topic_pages, @topics = paginate(:topics, :include => :replies, :order => 'replies.created_at asc, topics.created_at asc')
36
+ render :nothing => true
37
+ end
38
+
39
+ def paginate_with_conditions
40
+ @topic_pages, @topics = paginate(:topics, :conditions => ["created_at > ?", 30.minutes.ago])
41
+ render :nothing => true
42
+ end
43
+
44
+ def paginate_with_class_name
45
+ @developer_pages, @developers = paginate(:developers, :class_name => "DeVeLoPeR")
46
+ render :nothing => true
47
+ end
48
+
49
+ def paginate_with_singular_name
50
+ @developer_pages, @developers = paginate()
51
+ render :nothing => true
52
+ end
53
+
54
+ def paginate_with_joins
55
+ @developer_pages, @developers = paginate(:developers,
56
+ :joins => 'LEFT JOIN developers_projects ON developers.id = developers_projects.developer_id',
57
+ :conditions => 'project_id=1')
58
+ render :nothing => true
59
+ end
60
+
61
+ def paginate_with_join
62
+ @developer_pages, @developers = paginate(:developers,
63
+ :join => 'LEFT JOIN developers_projects ON developers.id = developers_projects.developer_id',
64
+ :conditions => 'project_id=1')
65
+ render :nothing => true
66
+ end
67
+
68
+ def paginate_with_join_and_count
69
+ @developer_pages, @developers = paginate(:developers,
70
+ :join => 'd LEFT JOIN developers_projects ON d.id = developers_projects.developer_id',
71
+ :conditions => 'project_id=1',
72
+ :count => "d.id")
73
+ render :nothing => true
74
+ end
75
+
76
+ def rescue_errors(e) raise e end
77
+
78
+ def rescue_action(e) raise end
79
+
80
+ end
81
+
82
+ def setup
83
+ @controller = PaginationController.new
84
+ @request = ActionController::TestRequest.new
85
+ @response = ActionController::TestResponse.new
86
+ super
87
+ end
88
+
89
+ # Single Action Pagination Tests
90
+
91
+ def test_simple_paginate
92
+ get :simple_paginate
93
+ assert_equal 1, assigns(:topic_pages).page_count
94
+ assert_equal 3, assigns(:topics).size
95
+ end
96
+
97
+ def test_paginate_with_per_page
98
+ get :paginate_with_per_page
99
+ assert_equal 1, assigns(:topics).size
100
+ assert_equal 3, assigns(:topic_pages).page_count
101
+ end
102
+
103
+ def test_paginate_with_order
104
+ get :paginate_with_order
105
+ expected = [topics(:futurama),
106
+ topics(:harvey_birdman),
107
+ topics(:rails)]
108
+ assert_equal expected, assigns(:topics)
109
+ assert_equal 1, assigns(:topic_pages).page_count
110
+ end
111
+
112
+ def test_paginate_with_order_by
113
+ get :paginate_with_order
114
+ expected = assigns(:topics)
115
+ get :paginate_with_order_by
116
+ assert_equal expected, assigns(:topics)
117
+ assert_equal 1, assigns(:topic_pages).page_count
118
+ end
119
+
120
+ def test_paginate_with_conditions
121
+ get :paginate_with_conditions
122
+ expected = [topics(:rails)]
123
+ assert_equal expected, assigns(:topics)
124
+ assert_equal 1, assigns(:topic_pages).page_count
125
+ end
126
+
127
+ def test_paginate_with_class_name
128
+ get :paginate_with_class_name
129
+
130
+ assert assigns(:developers).size > 0
131
+ assert_equal DeVeLoPeR, assigns(:developers).first.class
132
+ end
133
+
134
+ def test_paginate_with_joins
135
+ get :paginate_with_joins
136
+ assert_equal 2, assigns(:developers).size
137
+ developer_names = assigns(:developers).map { |d| d.name }
138
+ assert developer_names.include?('David')
139
+ assert developer_names.include?('Jamis')
140
+ end
141
+
142
+ def test_paginate_with_join_and_conditions
143
+ get :paginate_with_joins
144
+ expected = assigns(:developers)
145
+ get :paginate_with_join
146
+ assert_equal expected, assigns(:developers)
147
+ end
148
+
149
+ def test_paginate_with_join_and_count
150
+ get :paginate_with_joins
151
+ expected = assigns(:developers)
152
+ get :paginate_with_join_and_count
153
+ assert_equal expected, assigns(:developers)
154
+ end
155
+
156
+ def test_paginate_with_include_and_order
157
+ get :paginate_with_include_and_order
158
+ expected = Topic.find(:all, :include => 'replies', :order => 'replies.created_at asc, topics.created_at asc', :limit => 10)
159
+ assert_equal expected, assigns(:topics)
160
+ end
161
+ end
@@ -87,7 +87,7 @@ class ActionPackAssertionsController < ActionController::Base
87
87
 
88
88
  def errors
89
89
  Class.new do
90
- def full_messages; '...stuff...'; end
90
+ def full_messages; []; end
91
91
  end.new
92
92
  end
93
93
 
@@ -106,7 +106,7 @@ class ActionPackAssertionsController < ActionController::Base
106
106
 
107
107
  def errors
108
108
  Class.new do
109
- def full_messages; '...stuff...'; end
109
+ def full_messages; ['...stuff...']; end
110
110
  end.new
111
111
  end
112
112
  end.new
@@ -174,17 +174,18 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
174
174
  assert_equal @response.body, 'request method: POST'
175
175
  end
176
176
 
177
- # test the get/post switch within one test action
178
- def test_get_post_switch
179
- post :raise_on_get
180
- assert_equal @response.body, 'request method: POST'
181
- get :raise_on_post
182
- assert_equal @response.body, 'request method: GET'
183
- post :raise_on_get
184
- assert_equal @response.body, 'request method: POST'
185
- get :raise_on_post
186
- assert_equal @response.body, 'request method: GET'
187
- end
177
+ # the following test fails because the request_method is now cached on the request instance
178
+ # test the get/post switch within one test action
179
+ # def test_get_post_switch
180
+ # post :raise_on_get
181
+ # assert_equal @response.body, 'request method: POST'
182
+ # get :raise_on_post
183
+ # assert_equal @response.body, 'request method: GET'
184
+ # post :raise_on_get
185
+ # assert_equal @response.body, 'request method: POST'
186
+ # get :raise_on_post
187
+ # assert_equal @response.body, 'request method: GET'
188
+ # end
188
189
 
189
190
  # test the assertion of goodies in the template
190
191
  def test_assert_template_has
@@ -478,13 +479,15 @@ class ActionPackHeaderTest < Test::Unit::TestCase
478
479
  @controller = ActionPackAssertionsController.new
479
480
  @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
480
481
  end
482
+
481
483
  def test_rendering_xml_sets_content_type
482
484
  process :hello_xml_world
483
- assert_equal('text/xml', @controller.headers['Content-Type'])
485
+ assert_equal('application/xml', @controller.headers['Content-Type'])
484
486
  end
487
+
485
488
  def test_rendering_xml_respects_content_type
486
489
  @response.headers['Content-Type'] = 'application/pdf'
487
490
  process :hello_xml_world
488
491
  assert_equal('application/pdf', @controller.headers['Content-Type'])
489
492
  end
490
- end
493
+ end
@@ -2,68 +2,57 @@ require File.dirname(__FILE__) + '/../abstract_unit'
2
2
  require 'test/unit'
3
3
  require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late
4
4
 
5
- # This file currently contains a few controller UTs
6
- # I couldn't find where the current base tests are, so I created this file.
7
- # If there aren't any base-specific UTs, then this file should grow as they
8
- # are written. If there are, or there is a better place for these, then I will
9
- # move them to the correct location.
10
- #
11
- # Nicholas Seckar aka. Ulysses
12
-
13
- # Provide a static version of the Controllers module instead of the auto-loading version.
14
- # We don't want these tests to fail when dependencies are to blame.
15
- module Controllers
16
- module Submodule
17
- class ContainedEmptyController < ActionController::Base
18
- end
19
- class ContainedNonEmptyController < ActionController::Base
20
- def public_action
21
- end
22
-
23
- hide_action :hidden_action
24
- def hidden_action
25
- end
26
-
27
- def another_hidden_action
28
- end
29
- hide_action :another_hidden_action
30
- end
31
- class SubclassedController < ContainedNonEmptyController
32
- hide_action :public_action # Hiding it here should not affect the superclass.
33
- end
34
- end
35
- class EmptyController < ActionController::Base
36
- include ActionController::Caching
5
+ # Provide some controller to run the tests on.
6
+ module Submodule
7
+ class ContainedEmptyController < ActionController::Base
37
8
  end
38
- class NonEmptyController < ActionController::Base
9
+ class ContainedNonEmptyController < ActionController::Base
39
10
  def public_action
40
11
  end
41
12
 
42
13
  hide_action :hidden_action
43
14
  def hidden_action
44
15
  end
16
+
17
+ def another_hidden_action
18
+ end
19
+ hide_action :another_hidden_action
20
+ end
21
+ class SubclassedController < ContainedNonEmptyController
22
+ hide_action :public_action # Hiding it here should not affect the superclass.
23
+ end
24
+ end
25
+ class EmptyController < ActionController::Base
26
+ include ActionController::Caching
27
+ end
28
+ class NonEmptyController < ActionController::Base
29
+ def public_action
30
+ end
31
+
32
+ hide_action :hidden_action
33
+ def hidden_action
45
34
  end
46
35
  end
47
36
 
48
37
  class ControllerClassTests < Test::Unit::TestCase
49
38
  def test_controller_path
50
- assert_equal 'empty', Controllers::EmptyController.controller_path
51
- assert_equal 'submodule/contained_empty', Controllers::Submodule::ContainedEmptyController.controller_path
39
+ assert_equal 'empty', EmptyController.controller_path
40
+ assert_equal 'submodule/contained_empty', Submodule::ContainedEmptyController.controller_path
52
41
  end
53
42
  def test_controller_name
54
- assert_equal 'empty', Controllers::EmptyController.controller_name
55
- assert_equal 'contained_empty', Controllers::Submodule::ContainedEmptyController.controller_name
43
+ assert_equal 'empty', EmptyController.controller_name
44
+ assert_equal 'contained_empty', Submodule::ContainedEmptyController.controller_name
56
45
  end
57
46
  end
58
47
 
59
48
  class ControllerInstanceTests < Test::Unit::TestCase
60
49
  def setup
61
- @empty = Controllers::EmptyController.new
62
- @contained = Controllers::Submodule::ContainedEmptyController.new
63
- @empty_controllers = [@empty, @contained, Controllers::Submodule::SubclassedController.new]
50
+ @empty = EmptyController.new
51
+ @contained = Submodule::ContainedEmptyController.new
52
+ @empty_controllers = [@empty, @contained, Submodule::SubclassedController.new]
64
53
 
65
- @non_empty_controllers = [Controllers::NonEmptyController.new,
66
- Controllers::Submodule::ContainedNonEmptyController.new]
54
+ @non_empty_controllers = [NonEmptyController.new,
55
+ Submodule::ContainedNonEmptyController.new]
67
56
  end
68
57
 
69
58
  def test_action_methods