actionpack 1.9.1 → 1.10.1

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 (123) hide show
  1. data/CHANGELOG +237 -0
  2. data/README +12 -12
  3. data/lib/action_controller.rb +17 -12
  4. data/lib/action_controller/assertions.rb +119 -67
  5. data/lib/action_controller/base.rb +184 -102
  6. data/lib/action_controller/benchmarking.rb +35 -6
  7. data/lib/action_controller/caching.rb +115 -58
  8. data/lib/action_controller/cgi_ext/cgi_methods.rb +54 -21
  9. data/lib/action_controller/cgi_ext/cookie_performance_fix.rb +39 -35
  10. data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +34 -21
  11. data/lib/action_controller/cgi_process.rb +23 -20
  12. data/lib/action_controller/components.rb +11 -2
  13. data/lib/action_controller/dependencies.rb +0 -5
  14. data/lib/action_controller/deprecated_redirects.rb +17 -0
  15. data/lib/action_controller/filters.rb +13 -9
  16. data/lib/action_controller/flash.rb +7 -7
  17. data/lib/action_controller/helpers.rb +1 -14
  18. data/lib/action_controller/layout.rb +40 -29
  19. data/lib/action_controller/macros/auto_complete.rb +52 -0
  20. data/lib/action_controller/macros/in_place_editing.rb +32 -0
  21. data/lib/action_controller/pagination.rb +44 -28
  22. data/lib/action_controller/request.rb +54 -40
  23. data/lib/action_controller/rescue.rb +8 -6
  24. data/lib/action_controller/routing.rb +77 -28
  25. data/lib/action_controller/scaffolding.rb +10 -14
  26. data/lib/action_controller/session/active_record_store.rb +36 -7
  27. data/lib/action_controller/session_management.rb +126 -0
  28. data/lib/action_controller/streaming.rb +14 -5
  29. data/lib/action_controller/templates/rescues/_request_and_response.rhtml +1 -1
  30. data/lib/action_controller/templates/rescues/_trace.rhtml +24 -0
  31. data/lib/action_controller/templates/rescues/diagnostics.rhtml +2 -13
  32. data/lib/action_controller/templates/rescues/template_error.rhtml +4 -2
  33. data/lib/action_controller/templates/scaffolds/list.rhtml +1 -1
  34. data/lib/action_controller/test_process.rb +35 -17
  35. data/lib/action_controller/upload_progress.rb +52 -0
  36. data/lib/action_controller/url_rewriter.rb +21 -16
  37. data/lib/action_controller/vendor/html-scanner/html/document.rb +2 -2
  38. data/lib/action_controller/vendor/html-scanner/html/node.rb +30 -3
  39. data/lib/action_pack/version.rb +9 -0
  40. data/lib/action_view.rb +1 -1
  41. data/lib/action_view/base.rb +204 -60
  42. data/lib/action_view/compiled_templates.rb +70 -0
  43. data/lib/action_view/helpers/active_record_helper.rb +7 -3
  44. data/lib/action_view/helpers/asset_tag_helper.rb +22 -12
  45. data/lib/action_view/helpers/capture_helper.rb +2 -10
  46. data/lib/action_view/helpers/date_helper.rb +21 -13
  47. data/lib/action_view/helpers/form_helper.rb +14 -10
  48. data/lib/action_view/helpers/form_options_helper.rb +4 -4
  49. data/lib/action_view/helpers/form_tag_helper.rb +59 -25
  50. data/lib/action_view/helpers/java_script_macros_helper.rb +188 -0
  51. data/lib/action_view/helpers/javascript_helper.rb +68 -133
  52. data/lib/action_view/helpers/javascripts/controls.js +427 -165
  53. data/lib/action_view/helpers/javascripts/dragdrop.js +256 -277
  54. data/lib/action_view/helpers/javascripts/effects.js +766 -277
  55. data/lib/action_view/helpers/javascripts/prototype.js +906 -218
  56. data/lib/action_view/helpers/javascripts/slider.js +258 -0
  57. data/lib/action_view/helpers/number_helper.rb +4 -3
  58. data/lib/action_view/helpers/pagination_helper.rb +42 -27
  59. data/lib/action_view/helpers/tag_helper.rb +25 -11
  60. data/lib/action_view/helpers/text_helper.rb +119 -13
  61. data/lib/action_view/helpers/upload_progress_helper.rb +2 -2
  62. data/lib/action_view/helpers/url_helper.rb +68 -21
  63. data/lib/action_view/partials.rb +17 -6
  64. data/lib/action_view/template_error.rb +19 -24
  65. data/rakefile +4 -3
  66. data/test/abstract_unit.rb +2 -1
  67. data/test/controller/action_pack_assertions_test.rb +62 -2
  68. data/test/controller/active_record_assertions_test.rb +5 -6
  69. data/test/controller/active_record_store_test.rb +23 -1
  70. data/test/controller/addresses_render_test.rb +4 -0
  71. data/test/controller/{base_tests.rb → base_test.rb} +4 -3
  72. data/test/controller/benchmark_test.rb +36 -0
  73. data/test/controller/caching_filestore.rb +22 -40
  74. data/test/controller/capture_test.rb +10 -1
  75. data/test/controller/cgi_test.rb +145 -23
  76. data/test/controller/components_test.rb +50 -0
  77. data/test/controller/custom_handler_test.rb +3 -3
  78. data/test/controller/fake_controllers.rb +24 -0
  79. data/test/controller/filters_test.rb +6 -6
  80. data/test/controller/flash_test.rb +6 -6
  81. data/test/controller/fragment_store_setting_test.rb +45 -0
  82. data/test/controller/helper_test.rb +1 -3
  83. data/test/controller/new_render_test.rb +119 -7
  84. data/test/controller/redirect_test.rb +11 -1
  85. data/test/controller/render_test.rb +34 -1
  86. data/test/controller/request_test.rb +14 -5
  87. data/test/controller/routing_test.rb +238 -42
  88. data/test/controller/send_file_test.rb +11 -10
  89. data/test/controller/session_management_test.rb +94 -0
  90. data/test/controller/test_test.rb +194 -5
  91. data/test/controller/url_rewriter_test.rb +46 -0
  92. data/test/fixtures/layouts/talk_from_action.rhtml +2 -0
  93. data/test/fixtures/layouts/yield.rhtml +2 -0
  94. data/test/fixtures/multipart/binary_file +0 -0
  95. data/test/fixtures/multipart/large_text_file +10 -0
  96. data/test/fixtures/multipart/mixed_files +0 -0
  97. data/test/fixtures/multipart/single_parameter +5 -0
  98. data/test/fixtures/multipart/text_file +10 -0
  99. data/test/fixtures/test/_customer_greeting.rhtml +1 -0
  100. data/test/fixtures/test/_hash_object.rhtml +1 -0
  101. data/test/fixtures/test/_person.rhtml +2 -0
  102. data/test/fixtures/test/action_talk_to_layout.rhtml +2 -0
  103. data/test/fixtures/test/content_for.rhtml +2 -0
  104. data/test/fixtures/test/potential_conflicts.rhtml +4 -0
  105. data/test/template/active_record_helper_test.rb +15 -8
  106. data/test/template/asset_tag_helper_test.rb +40 -16
  107. data/test/template/compiled_templates_tests.rb +63 -0
  108. data/test/template/date_helper_test.rb +80 -4
  109. data/test/template/form_helper_test.rb +48 -42
  110. data/test/template/form_options_helper_test.rb +40 -40
  111. data/test/template/form_tag_helper_test.rb +21 -15
  112. data/test/template/java_script_macros_helper_test.rb +56 -0
  113. data/test/template/javascript_helper_test.rb +70 -47
  114. data/test/template/number_helper_test.rb +2 -0
  115. data/test/template/tag_helper_test.rb +9 -0
  116. data/test/template/text_helper_test.rb +146 -1
  117. data/test/template/upload_progress_helper_testx.rb +11 -147
  118. data/test/template/url_helper_test.rb +90 -22
  119. data/test/testing_sandbox.rb +26 -0
  120. metadata +37 -7
  121. data/lib/action_controller/auto_complete.rb +0 -47
  122. data/lib/action_controller/deprecated_renders_and_redirects.rb +0 -76
  123. data/lib/action_controller/session.rb +0 -14
data/CHANGELOG CHANGED
@@ -1,3 +1,240 @@
1
+ *1.10.1* (October 19th, 2005)
2
+
3
+ * Update error trace templates [Nicholas Seckar]
4
+
5
+ * Stop showing generated routing code in application traces [Nicholas Seckar]
6
+
7
+
8
+ *1.10.0* (October 16th, 2005)
9
+
10
+ * Make string-keys locals assigns optional. Add documentation describing depreciated state [skaes@web.de]
11
+
12
+ * Improve line number detection for template errors [Nicholas Seckar]
13
+
14
+ * Update/clean up documentation (rdoc)
15
+
16
+ * Upgrade to Prototype 1.4.0_rc0 [Sam Stephenson]
17
+
18
+ * Added assert_vaild. Reports the proper AR error messages as fail message when the passed record is invalid [Tobias Luetke]
19
+
20
+ * Add temporary support for passing locals to render using string keys [Nicholas Seckar]
21
+
22
+ * Clean up error pages by providing better backtraces [Nicholas Seckar]
23
+
24
+ * Raise an exception if an attempt is made to insert more session data into the ActiveRecordStore data column than the column can hold. #2234. [justin@textdrive.com]
25
+
26
+ * Removed references to assertions.rb from actionpack assert's backtraces. Makes error reports in functional unit tests much less noisy. [Tobias Luetke]
27
+
28
+ * Updated and clarified documentation for JavaScriptHelper to be more concise about the various options for including the JavaScript libs. [Thomas Fuchs]
29
+
30
+ * Hide "Retry with Breakpoint" button on error pages until feature is functional. [DHH]
31
+
32
+ * Fix Request#host_with_port to use the standard port when Rails is behind a proxy. [Nicholas Seckar]
33
+
34
+ * Escape query strings in the href attribute of URLs created by url_helper. #2333 [Michael Schuerig <michael@schuerig.de>]
35
+
36
+ * Improved line number reporting for template errors [Nicholas Seckar]
37
+
38
+ * Added :locals support for render :inline #2463 [mdabney@cavoksolutions.com]
39
+
40
+ * Unset the X-Requested-With header when using the xhr wrapper in functional tests so that future requests aren't accidentally xhr'ed #2352 [me@julik.nl, Sam Stephenson]
41
+
42
+ * Unescape paths before writing cache to file system. #1877. [Damien Pollet]
43
+
44
+ * Wrap javascript_tag contents in a CDATA section and add a cdata_section method to TagHelper #1691 [Michael Schuerig, Sam Stephenson]
45
+
46
+ * Misc doc fixes (typos/grammar/etc). #2445. [coffee2code]
47
+
48
+ * Speed improvement for session_options. #2287. [skaes@web.de]
49
+
50
+ * Make cacheing binary files friendly with Windows. #1975. [Rich Olson]
51
+
52
+ * Convert boolean form options form the tag_helper. #809. [Michael Schuerig <michael@schuerig.de>]
53
+
54
+ * Fixed that an instance variable with the same name as a partial should be implicitly passed as the partial :object #2269 [court3nay]
55
+
56
+ * Update Prototype to V1.4.0_pre11, script.aculo.us to [2502] [Thomas Fuchs]
57
+
58
+ * Make assert_tag :children count appropriately. Closes #2181. [jamie@bravenet.com]
59
+
60
+ * Forced newer versions of RedCloth to use hard breaks [DHH]
61
+
62
+ * Added new scriptaculous options for auto_complete_field #2343 [m.stienstra@fngtps.com]
63
+
64
+ * Don't prepend the asset host if the string is already a fully-qualified URL
65
+
66
+ * Updated to script.aculo.us V1.5.0_rc2 and Prototype to V1.4.0_pre7 [Thomas Fuchs]
67
+
68
+ * Undo condition change made in [2345] to prevent normal parameters arriving as StringIO.
69
+
70
+ * Tolerate consecutive delimiters in query parameters. #2295 [darashi@gmail.com]
71
+
72
+ * Streamline render process, code cleaning. Closes #2294. [skae]
73
+
74
+ * Keep flash after components are rendered. #2291 [Rick Olson, Scott]
75
+
76
+ * Shorten IE file upload path to filename only to match other browsers. #1507 [court3nay@gmail.com]
77
+
78
+ * Fix open/save dialog in IE not opening files send with send_file/send_data, #2279 [Thomas Fuchs]
79
+
80
+ * Fixed that auto_discovery_link_tag couldn't take a string as the URL [DHH]
81
+
82
+ * Fixed problem with send_file and WEBrick using stdout #1812 [DHH]
83
+
84
+ * Optimized tag_options to not sort keys, which is no longer necessary when assert_dom_equal and friend is available #1995 [skae]
85
+
86
+ * Added assert_dom_equal and assert_dom_not_equal to compare tags generated by the helpers in an order-indifferent manner #1995 [skae]
87
+
88
+ * Fixed that Request#domain caused an exception if the domain header wasn't set in the original http request #1795 [Michael Koziarski]
89
+
90
+ * Make the truncate() helper multi-byte safe (assuming $KCODE has been set to something other than "NONE") #2103
91
+
92
+ * Add routing tests from #1945 [ben@groovie.org]
93
+
94
+ * Add a routing test case covering #2101 [Nicholas Seckar]
95
+
96
+ * Cache relative_url_root for all webservers, not just Apache #2193 [skae]
97
+
98
+ * Speed up cookie use by decreasing string copying #2194 [skae]
99
+
100
+ * Fixed access to "Host" header with requests made by crappy old HTTP/1.0 clients #2124 [Marcel Molina]
101
+
102
+ * Added easy assignment of fragment cache store through use of symbols for included stores (old way still works too)
103
+
104
+ Before:
105
+ ActionController::Base.fragment_cache_store =
106
+ ActionController::Base::Caching::Fragments::FileStore.new("/path/to/cache/directory")
107
+
108
+ After:
109
+ ActionController::Base.fragment_cache_store = :file_store, "/path/to/cache/directory"
110
+
111
+ * Added ActionController::Base.session_store=, session_store, and session_options to make it easier to tweak the session options (instead of going straight to ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS)
112
+
113
+ * Added TextHelper#cycle to cycle over an array of values on each hit (useful for alternating row colors etc) #2154 [dave-ml@dribin.org]
114
+
115
+ * Ensure that request.path never returns nil. Closes #1675 [Nicholas Seckar]
116
+
117
+ * Add ability to specify Route Regexps for controllers. Closes #1917. [Sebastian Kanthak]
118
+
119
+ * Provide Named Route's hash methods as helper methods. Closes #1744. [Nicholas Seckar, Steve Purcell]
120
+
121
+ * Added :multipart option to ActiveRecordHelper#form to make it possible to add file input fields #2034 [jstirk@oobleyboo.com]
122
+
123
+ * Moved auto-completion and in-place editing into the Macros module and their helper counterparts into JavaScriptMacrosHelper
124
+
125
+ * Added in-place editing support in the spirit of auto complete with ActionController::Base.in_place_edit_for, JavascriptHelper#in_place_editor_field, and Javascript support from script.aculo.us #2038 [Jon Tirsen]
126
+
127
+ * Added :disabled option to all data selects that'll make the elements inaccessible for change #2167, #253 [eigentone]
128
+
129
+ * Fixed that TextHelper#auto_link_urls would include punctuation in the links #2166, #1671 [eigentone]
130
+
131
+ * Fixed that number_to_currency(1000, {:precision => 0})) should return "$1,000", instead of "$1,000." #2122 [sd@notso.net]
132
+
133
+ * Allow link_to_remote to use any DOM-element as the parent of the form elements to be submitted #2137 [erik@ruby-lang.nl]. Example:
134
+
135
+ <tr id="row023">
136
+ <td><input name="foo"/></td>
137
+ <td><input name="bar"/></td>
138
+ <td><%= link_to_remote 'Save', :update => "row023",
139
+ :submit => "row023", :url => {:action => 'save_row'} %></td>
140
+ </tr>
141
+
142
+ * Fixed that render :partial would fail when :object was a Hash (due to backwards compatibility issues) #2148 [Sam Stephenson]
143
+
144
+ * Fixed JavascriptHelper#auto_complete_for to only include unique items #2153 [Thomas Fuchs]
145
+
146
+ * Fixed all AssetHelper methods to work with relative paths, such that javascript_include_tag('stdlib/standard') will look in /javascripts/stdlib/standard instead of '/stdlib/standard/' #1963
147
+
148
+ * Avoid extending view instance with helper modules each request. Closes #1979
149
+
150
+ * Performance improvements to CGI methods. Closes #1980 [Skaes]
151
+
152
+ * Added :post option to UrlHelper#link_to that makes it possible to do POST requests through normal ahref links using Javascript
153
+
154
+ * Fixed overwrite_params
155
+
156
+ * Added ActionController::Base.benchmark and ActionController::Base.silence to allow for easy benchmarking and turning off the log
157
+
158
+ * Updated vendor copy of html-scanner to support better xml parsing
159
+
160
+ * Added :popup option to UrlHelper#link_to #1996 [gabriel.gironda@gmail.com]. Examples:
161
+
162
+ link_to "Help", { :action => "help" }, :popup => true
163
+ link_to "Busy loop", { :action => "busy" }, :popup => ['new_window', 'height=300,width=600']
164
+
165
+ * Drop trailing \000 if present on RAW_POST_DATA (works around bug in Safari Ajax implementation) #918
166
+
167
+ * Fix observe_field to fall back to event-based observation if frequency <= 0 #1916 [michael@schubert.cx]
168
+
169
+ * Allow use of the :with option for submit_to_remote #1936 [jon@instance-design.co.uk]
170
+
171
+ * AbstractRequest#domain returns nil when host is an ip address #2012 [kevin.clark@gmail.com]
172
+
173
+ * ActionController documentation update #2051 [fbeausoleil@ftml.net]
174
+
175
+ * Yield @content_for_ variables to templates #2058 [Sam Stephenson]
176
+
177
+ * Make rendering an empty partial collection behave like :nothing => true #2080 [Sam Stephenson]
178
+
179
+ * Add option to specify the singular name used by pagination.
180
+
181
+ * Use string key to obtain action value. Allows indifferent hashes to be disabled.
182
+
183
+ * Added ActionView::Base.cache_template_loading back.
184
+
185
+ * Rewrote compiled templates to decrease code complexity. Removed template load caching in favour of compiled caching. Fixed template error messages. [Nicholas Seckar]
186
+
187
+ * Fix Routing to handle :some_param => nil better. [Nicholas Seckar, Luminas]
188
+
189
+ * Add support for :include with pagination (subject to existing constraints for :include with :limit and :offset) #1478 [michael@schubert.cx]
190
+
191
+ * Prevent the benchmark module from blowing up if a non-HTTP/1.1 request is processed
192
+
193
+ * Added :use_short_month option to select_month helper to show month names as abbreviations
194
+
195
+ * Make link_to escape the javascript in the confirm option #1964 [nicolas.pouillard@gmail.com]
196
+
197
+ * Make assert_redirected_to properly check URL's passed as strings #1910 [Scott Barron]
198
+
199
+ * Make sure :layout => false is always used when rendering inside a layout
200
+
201
+ * Use raise instead of assert_not_nil in Test::Unit::TestCase#process to ensure that the test variables (controller, request, response) have been set
202
+
203
+ * Make sure assigns are built for every request when testing #1866
204
+
205
+ * Allow remote_addr to be queried on TestRequest #1668
206
+
207
+ * Fixed bug when a partial render was passing a local with the same name as the partial
208
+
209
+ * Improved performance of test app req/sec with ~10% refactoring the render method #1823 [Stefan Kaes]
210
+
211
+ * Improved performance of test app req/sec with 5-30% through a series of Action Pack optimizations #1811 [Stefan Kaes]
212
+
213
+ * Changed caching/expiration/hit to report using the DEBUG log level and errors to use the ERROR log level instead of both using INFO
214
+
215
+ * Added support for per-action session management #1763
216
+
217
+ * Improved rendering speed on complicated templates by up to 100% (the more complex the templates, the higher the speedup) #1234 [Stephan Kaes]. This did necessasitate a change to the internals of ActionView#render_template that now has four parameters. Developers of custom view handlers (like Amrita) need to update for that.
218
+
219
+ * Added options hash as third argument to FormHelper#input, so you can do input('person', 'zip', :size=>10) #1719 [jeremye@bsa.ca.gov]
220
+
221
+ * Added Base#expires_in(seconds)/Base#expires_now to control HTTP content cache headers #1755 [Thomas Fuchs]
222
+
223
+ * Fixed line number reporting for Builder template errors #1753 [piotr]
224
+
225
+ * Fixed assert_routing so that testing controllers in modules works as expected [Nicholas Seckar, Rick Olson]
226
+
227
+ * Fixed bug with :success/:failure callbacks for the JavaScriptHelper methods #1730 [court3nay/Thomas Fuchs]
228
+
229
+ * Added named_route method to RouteSet instances so that RouteSet instance methods do not prevent certain names from being used. [Nicholas Seckar]
230
+
231
+ * Fixed routes so that routes which do not specify :action in the path or in the requirements have a default of :action => 'index', In addition, fixed url generation so that :action => 'index' does not need to be provided for such urls. [Nicholas Seckar, Markjuh]
232
+
233
+ * Worked around a Safari bug where it wouldn't pass headers through if the response was zero length by having render :nothing return ' ' instead of ''
234
+
235
+ * Fixed Request#subdomains to handle "foo.foo.com" correctly
236
+
237
+
1
238
  *1.9.1* (11 July, 2005)
2
239
 
3
240
  * Fixed that auto_complete_for didn't force the input string to lower case even as the db comparison was
data/README CHANGED
@@ -40,14 +40,14 @@ A short rundown of the major features:
40
40
 
41
41
  def update
42
42
  @customer = find_customer
43
- @customer.attributes = @params["customer"]
43
+ @customer.attributes = params[:customer]
44
44
  @customer.save ?
45
45
  redirect_to(:action => "display") :
46
46
  render(:action => "edit")
47
47
  end
48
48
 
49
49
  private
50
- def find_customer() Customer.find(@params["id"]) end
50
+ def find_customer() Customer.find(params[:id]) end
51
51
  end
52
52
 
53
53
  {Learn more}[link:classes/ActionController/Base.html]
@@ -182,7 +182,7 @@ A short rundown of the major features:
182
182
  # controller
183
183
  def list
184
184
  @pages, @people =
185
- paginate :people, :order_by => 'last_name, first_name'
185
+ paginate :people, :order => 'last_name, first_name'
186
186
  end
187
187
 
188
188
  # view
@@ -202,8 +202,8 @@ A short rundown of the major features:
202
202
  end
203
203
 
204
204
  def test_failing_authenticate
205
- process :authenticate, "user_name" => "nop", "password" => ""
206
- assert_flash_has 'alert'
205
+ process :authenticate, :user_name => "nop", :password => ""
206
+ assert flash.has_key?(:alert)
207
207
  assert_redirected_to :action => "index"
208
208
  end
209
209
  end
@@ -252,10 +252,10 @@ A short rundown of the major features:
252
252
  end
253
253
 
254
254
  def update
255
- List.update(@params["list"]["id"], @params["list"])
256
- expire_page :action => "show", :id => @params["list"]["id"]
255
+ List.update(params[:list][:id], params[:list])
256
+ expire_page :action => "show", :id => params[:list][:id]
257
257
  expire_action :action => "account"
258
- redirect_to :action => "show", :id => @params["list"]["id"]
258
+ redirect_to :action => "show", :id => params[:list][:id]
259
259
  end
260
260
  end
261
261
 
@@ -342,8 +342,8 @@ A short rundown of the major features:
342
342
 
343
343
  class WeblogController < ActionController::Base
344
344
  def save
345
- post = Post.create(@params["post"])
346
- redirect_to :action => "display", :path_params => { "id" => post.id }
345
+ post = Post.create(params[:post])
346
+ redirect_to :action => "display", :id => post.id
347
347
  end
348
348
  end
349
349
 
@@ -370,7 +370,7 @@ methods:
370
370
  end
371
371
 
372
372
  def display
373
- @post = Post.find(@params["id"])
373
+ @post = Post.find(:params[:id])
374
374
  end
375
375
 
376
376
  def new
@@ -378,7 +378,7 @@ methods:
378
378
  end
379
379
 
380
380
  def create
381
- @post = Post.create(@params["post"])
381
+ @post = Post.create(params[:post])
382
382
  redirect_to :action => "display", :id => @post.id
383
383
  end
384
384
  end
@@ -21,24 +21,26 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #++
23
23
 
24
- $:.unshift(File.dirname(__FILE__))
25
- $:.unshift(File.dirname(__FILE__) + "/../../activesupport/lib")
24
+ $:.unshift(File.dirname(__FILE__)) unless
25
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
26
26
 
27
- begin
28
- require 'active_support'
29
- rescue LoadError
30
- require 'rubygems'
31
- require_gem 'activesupport'
27
+ unless defined?(ActiveSupport)
28
+ begin
29
+ $:.unshift(File.dirname(__FILE__) + "/../../activesupport/lib")
30
+ require 'active_support'
31
+ rescue LoadError
32
+ require 'rubygems'
33
+ require_gem 'activesupport'
34
+ end
32
35
  end
33
36
 
34
37
  require 'action_controller/base'
35
- require 'action_controller/deprecated_renders_and_redirects'
38
+ require 'action_controller/deprecated_redirects'
36
39
  require 'action_controller/rescue'
37
40
  require 'action_controller/benchmarking'
38
41
  require 'action_controller/filters'
39
42
  require 'action_controller/layout'
40
43
  require 'action_controller/flash'
41
- require 'action_controller/session'
42
44
  require 'action_controller/dependencies'
43
45
  require 'action_controller/pagination'
44
46
  require 'action_controller/scaffolding'
@@ -49,7 +51,9 @@ require 'action_controller/caching'
49
51
  require 'action_controller/components'
50
52
  require 'action_controller/verification'
51
53
  require 'action_controller/streaming'
52
- require 'action_controller/auto_complete'
54
+ require 'action_controller/session_management'
55
+ require 'action_controller/macros/auto_complete'
56
+ require 'action_controller/macros/in_place_editing'
53
57
 
54
58
  require 'action_view'
55
59
  ActionController::Base.template_class = ActionView::Base
@@ -65,10 +69,11 @@ ActionController::Base.class_eval do
65
69
  include ActionController::Scaffolding
66
70
  include ActionController::Helpers
67
71
  include ActionController::Cookies
68
- include ActionController::Session
69
72
  include ActionController::Caching
70
73
  include ActionController::Components
71
74
  include ActionController::Verification
72
75
  include ActionController::Streaming
73
- include ActionController::AutoComplete
76
+ include ActionController::SessionManagement
77
+ include ActionController::Macros::AutoComplete
78
+ include ActionController::Macros::InPlaceEditing
74
79
  end
@@ -1,6 +1,7 @@
1
1
  require 'test/unit'
2
2
  require 'test/unit/assertions'
3
3
  require 'rexml/document'
4
+ require "#{File.dirname(__FILE__)}/vendor/html-scanner/html/document"
4
5
 
5
6
  module Test #:nodoc:
6
7
  module Unit #:nodoc:
@@ -55,12 +56,14 @@ module Test #:nodoc:
55
56
  #
56
57
  # You can also pass an explicit status code number as the type, like assert_response(501)
57
58
  def assert_response(type, message = nil)
58
- if [ :success, :missing, :redirect, :error ].include?(type) && @response.send("#{type}?")
59
- assert_block("") { true } # to count the assertion
60
- elsif type.is_a?(Fixnum) && @response.response_code == type
61
- assert_block("") { true } # to count the assertion
62
- else
63
- assert_block(build_message(message, "Expected response to be a <?>, but was <?>", type, @response.response_code)) { false }
59
+ clean_backtrace do
60
+ if [ :success, :missing, :redirect, :error ].include?(type) && @response.send("#{type}?")
61
+ assert_block("") { true } # to count the assertion
62
+ elsif type.is_a?(Fixnum) && @response.response_code == type
63
+ assert_block("") { true } # to count the assertion
64
+ else
65
+ assert_block(build_message(message, "Expected response to be a <?>, but was <?>", type, @response.response_code)) { false }
66
+ end
64
67
  end
65
68
  end
66
69
 
@@ -68,30 +71,31 @@ module Test #:nodoc:
68
71
  # such at assert_redirected_to(:controller => "weblog") will also match the redirection of
69
72
  # redirect_to(:controller => "weblog", :action => "show") and so on.
70
73
  def assert_redirected_to(options = {}, message=nil)
71
- assert_response(:redirect, message)
74
+ clean_backtrace do
75
+ assert_response(:redirect, message)
72
76
 
73
- if options.is_a?(String)
74
- msg = build_message(message, "expected a redirect to <?>, found one to <?>", options, @response.redirect_url)
75
- url_regexp = %r{^(\w+://.*?(/|$|\?))(.*)$}
76
- eurl, epath, url, path = [options, @response.redirect_url].collect do |url|
77
- u, p = (url_regexp =~ url) ? [$1, $3] : [nil, url]
78
- [u, (p[0..0] == '/') ? p : '/' + p]
79
- end.flatten
77
+ if options.is_a?(String)
78
+ msg = build_message(message, "expected a redirect to <?>, found one to <?>", options, @response.redirect_url)
79
+ url_regexp = %r{^(\w+://.*?(/|$|\?))(.*)$}
80
+ eurl, epath, url, path = [options, @response.redirect_url].collect do |url|
81
+ u, p = (url_regexp =~ url) ? [$1, $3] : [nil, url]
82
+ [u, (p[0..0] == '/') ? p : '/' + p]
83
+ end.flatten
80
84
 
81
- if eurl && url then assert_equal(eurl, url, msg)
82
- else assert_equal(epath, path, msg)
83
- end
84
- else
85
- msg = build_message(message, "response is not a redirection to all of the options supplied (redirection is <?>)",
86
- @response.redirected_to || @response.redirect_url)
85
+ assert_equal(eurl, url, msg) if eurl && url
86
+ assert_equal(epath, path, msg) if epath && path
87
+ else
88
+ msg = build_message(message, "response is not a redirection to all of the options supplied (redirection is <?>)",
89
+ @response.redirected_to || @response.redirect_url)
87
90
 
88
- assert_block(msg) do
89
- if options.is_a?(Symbol)
90
- @response.redirected_to == options
91
- else
92
- options.keys.all? do |k|
93
- if k == :controller then options[k] == ActionController::Routing.controller_relative_to(@response.redirected_to[k], @controller.class.controller_path)
94
- else options[k] == (@response.redirected_to[k].respond_to?(:to_param) ? @response.redirected_to[k].to_param : @response.redirected_to[k] unless @response.redirected_to[k].nil?)
91
+ assert_block(msg) do
92
+ if options.is_a?(Symbol)
93
+ @response.redirected_to == options
94
+ else
95
+ options.keys.all? do |k|
96
+ if k == :controller then options[k] == ActionController::Routing.controller_relative_to(@response.redirected_to[k], @controller.class.controller_path)
97
+ else options[k] == (@response.redirected_to[k].respond_to?(:to_param) ? @response.redirected_to[k].to_param : @response.redirected_to[k] unless @response.redirected_to[k].nil?)
98
+ end
95
99
  end
96
100
  end
97
101
  end
@@ -101,61 +105,70 @@ module Test #:nodoc:
101
105
 
102
106
  # Asserts that the request was rendered with the appropriate template file.
103
107
  def assert_template(expected = nil, message=nil)
104
- rendered = expected ? @response.rendered_file(!expected.include?('/')) : @response.rendered_file
105
- msg = build_message(message, "expecting <?> but rendering with <?>", expected, rendered)
106
- assert_block(msg) do
107
- if expected.nil?
108
- !@response.rendered_with_file?
109
- else
110
- expected == rendered
111
- end
108
+ clean_backtrace do
109
+ rendered = expected ? @response.rendered_file(!expected.include?('/')) : @response.rendered_file
110
+ msg = build_message(message, "expecting <?> but rendering with <?>", expected, rendered)
111
+ assert_block(msg) do
112
+ if expected.nil?
113
+ !@response.rendered_with_file?
114
+ else
115
+ expected == rendered
116
+ end
117
+ end
112
118
  end
113
119
  end
114
120
 
115
121
  # Asserts that the routing of the given path is handled correctly and that the parsed options match.
116
122
  def assert_recognizes(expected_options, path, extras={}, message=nil)
117
- path = "/#{path}" unless path[0..0] == '/'
118
- # Load routes.rb if it hasn't been loaded.
119
- ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
123
+ clean_backtrace do
124
+ path = "/#{path}" unless path[0..0] == '/'
125
+ # Load routes.rb if it hasn't been loaded.
126
+ ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
120
127
 
121
- # Assume given controller
122
- request = ActionController::TestRequest.new({}, {}, nil)
123
- request.path = path
124
- ActionController::Routing::Routes.recognize!(request)
128
+ # Assume given controller
129
+ request = ActionController::TestRequest.new({}, {}, nil)
130
+ request.path = path
131
+ ActionController::Routing::Routes.recognize!(request)
125
132
 
126
- expected_options = expected_options.clone
127
- extras.each_key { |key| expected_options.delete key } unless extras.nil?
133
+ expected_options = expected_options.clone
134
+ extras.each_key { |key| expected_options.delete key } unless extras.nil?
128
135
 
129
- expected_options.stringify_keys!
130
- msg = build_message(message, "The recognized options <?> did not match <?>",
131
- request.path_parameters, expected_options)
132
- assert_block(msg) { request.path_parameters == expected_options }
136
+ expected_options.stringify_keys!
137
+ msg = build_message(message, "The recognized options <?> did not match <?>",
138
+ request.path_parameters, expected_options)
139
+ assert_block(msg) { request.path_parameters == expected_options }
140
+ end
133
141
  end
134
142
 
135
143
  # Asserts that the provided options can be used to generate the provided path.
136
144
  def assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)
137
- expected_path = "/#{expected_path}" unless expected_path[0] == ?/
138
- # Load routes.rb if it hasn't been loaded.
139
- ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
145
+ clean_backtrace do
146
+ expected_path = "/#{expected_path}" unless expected_path[0] == ?/
147
+ # Load routes.rb if it hasn't been loaded.
148
+ ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
140
149
 
141
- # Assume given controller
142
- request = ActionController::TestRequest.new({}, {}, nil)
143
- request.path_parameters = (defaults or {}).clone
144
- request.path_parameters[:controller] ||= options[:controller]
145
-
146
- generated_path, found_extras = ActionController::Routing::Routes.generate(options, request)
147
- msg = build_message(message, "found extras <?>, not <?>", found_extras, extras)
148
- assert_block(msg) { found_extras == extras }
150
+ generated_path, extra_keys = ActionController::Routing::Routes.generate(options, extras)
151
+ found_extras = options.reject {|k, v| ! extra_keys.include? k}
152
+
153
+ msg = build_message(message, "found extras <?>, not <?>", found_extras, extras)
154
+ assert_block(msg) { found_extras == extras }
149
155
 
150
- msg = build_message(message, "The generated path <?> did not match <?>", generated_path,
151
- expected_path)
152
- assert_block(msg) { expected_path == generated_path }
156
+ msg = build_message(message, "The generated path <?> did not match <?>", generated_path,
157
+ expected_path)
158
+ assert_block(msg) { expected_path == generated_path }
159
+ end
153
160
  end
154
161
 
155
162
  # asserts that path and options match both ways, in other words, the URL generated from
156
163
  # options is same as path, and also that the options recognized from path are same as options
157
164
  def assert_routing(path, options, defaults={}, extras={}, message=nil)
158
165
  assert_recognizes(options, path, extras, message)
166
+
167
+ controller, default_controller = options[:controller], defaults[:controller]
168
+ if controller && controller.include?(?/) && default_controller && default_controller.include?(?/)
169
+ options[:controller] = "/#{controller}"
170
+ end
171
+
159
172
  assert_generates(path, options, defaults, extras, message)
160
173
  end
161
174
 
@@ -236,17 +249,56 @@ module Test #:nodoc:
236
249
  # :descendant => { :tag => "span",
237
250
  # :child => /hello world/ }
238
251
  def assert_tag(opts)
239
- tag = find_tag(opts)
240
- assert tag, "expected tag, but no tag found matching #{opts.inspect} in:\n#{@response.body.inspect}"
252
+ clean_backtrace do
253
+ tag = find_tag(opts)
254
+ assert tag, "expected tag, but no tag found matching #{opts.inspect} in:\n#{@response.body.inspect}"
255
+ end
241
256
  end
242
257
 
243
258
  # Identical to #assert_tag, but asserts that a matching tag does _not_
244
259
  # exist. (See #assert_tag for a full discussion of the syntax.)
245
260
  def assert_no_tag(opts)
246
- tag = find_tag(opts)
247
- assert !tag, "expected no tag, but found tag matching #{opts.inspect} in:\n#{@response.body.inspect}"
261
+ clean_backtrace do
262
+ tag = find_tag(opts)
263
+ assert !tag, "expected no tag, but found tag matching #{opts.inspect} in:\n#{@response.body.inspect}"
264
+ end
265
+ end
266
+
267
+ # test 2 html strings to be equivalent, i.e. identical up to reordering of attributes
268
+ def assert_dom_equal(expected, actual, message="")
269
+ clean_backtrace do
270
+ expected_dom = HTML::Document.new(expected).root
271
+ actual_dom = HTML::Document.new(actual).root
272
+ full_message = build_message(message, "<?> expected to be == to\n<?>.", expected_dom.to_s, actual_dom.to_s)
273
+ assert_block(full_message) { expected_dom == actual_dom }
274
+ end
275
+ end
276
+
277
+ # negated form of +assert_dom_equivalent+
278
+ def assert_dom_not_equal(expected, actual, message="")
279
+ clean_backtrace do
280
+ expected_dom = HTML::Document.new(expected).root
281
+ actual_dom = HTML::Document.new(actual).root
282
+ full_message = build_message(message, "<?> expected to be != to\n<?>.", expected_dom.to_s, actual_dom.to_s)
283
+ assert_block(full_message) { expected_dom != actual_dom }
284
+ end
285
+ end
286
+
287
+ # ensures that the passed record is valid by active record standards. returns the error messages if not
288
+ def assert_valid(record)
289
+ clean_backtrace do
290
+ assert record.valid?, record.errors.full_messages
291
+ end
292
+ end
293
+
294
+ def clean_backtrace(&block)
295
+ begin
296
+ yield
297
+ rescue AssertionFailedError => e
298
+ path = File.expand_path(__FILE__)
299
+ raise AssertionFailedError, e.message, e.backtrace.reject { |line| File.expand_path(line) =~ /#{path}/ }
300
+ end
248
301
  end
249
-
250
302
  end
251
303
  end
252
304
  end