actionpack 0.9.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 (100) hide show
  1. data/CHANGELOG +604 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +418 -0
  4. data/RUNNING_UNIT_TESTS +14 -0
  5. data/examples/.htaccess +24 -0
  6. data/examples/address_book/index.rhtml +33 -0
  7. data/examples/address_book/layout.rhtml +8 -0
  8. data/examples/address_book_controller.cgi +9 -0
  9. data/examples/address_book_controller.fcgi +6 -0
  10. data/examples/address_book_controller.rb +52 -0
  11. data/examples/address_book_controller.rbx +4 -0
  12. data/examples/benchmark.rb +52 -0
  13. data/examples/benchmark_with_ar.fcgi +89 -0
  14. data/examples/blog_controller.cgi +53 -0
  15. data/examples/debate/index.rhtml +14 -0
  16. data/examples/debate/new_topic.rhtml +22 -0
  17. data/examples/debate/topic.rhtml +32 -0
  18. data/examples/debate_controller.cgi +57 -0
  19. data/install.rb +93 -0
  20. data/lib/action_controller.rb +47 -0
  21. data/lib/action_controller/assertions/action_pack_assertions.rb +166 -0
  22. data/lib/action_controller/assertions/active_record_assertions.rb +65 -0
  23. data/lib/action_controller/base.rb +626 -0
  24. data/lib/action_controller/benchmarking.rb +49 -0
  25. data/lib/action_controller/cgi_ext/cgi_ext.rb +43 -0
  26. data/lib/action_controller/cgi_ext/cgi_methods.rb +91 -0
  27. data/lib/action_controller/cgi_process.rb +123 -0
  28. data/lib/action_controller/filters.rb +279 -0
  29. data/lib/action_controller/flash.rb +65 -0
  30. data/lib/action_controller/layout.rb +143 -0
  31. data/lib/action_controller/request.rb +92 -0
  32. data/lib/action_controller/rescue.rb +94 -0
  33. data/lib/action_controller/response.rb +15 -0
  34. data/lib/action_controller/scaffolding.rb +183 -0
  35. data/lib/action_controller/session/active_record_store.rb +72 -0
  36. data/lib/action_controller/session/drb_server.rb +9 -0
  37. data/lib/action_controller/session/drb_store.rb +31 -0
  38. data/lib/action_controller/support/class_attribute_accessors.rb +57 -0
  39. data/lib/action_controller/support/class_inheritable_attributes.rb +37 -0
  40. data/lib/action_controller/support/clean_logger.rb +10 -0
  41. data/lib/action_controller/support/cookie_performance_fix.rb +121 -0
  42. data/lib/action_controller/support/inflector.rb +70 -0
  43. data/lib/action_controller/templates/rescues/_request_and_response.rhtml +28 -0
  44. data/lib/action_controller/templates/rescues/diagnostics.rhtml +22 -0
  45. data/lib/action_controller/templates/rescues/layout.rhtml +29 -0
  46. data/lib/action_controller/templates/rescues/missing_template.rhtml +2 -0
  47. data/lib/action_controller/templates/rescues/template_error.rhtml +26 -0
  48. data/lib/action_controller/templates/rescues/unknown_action.rhtml +2 -0
  49. data/lib/action_controller/templates/scaffolds/edit.rhtml +6 -0
  50. data/lib/action_controller/templates/scaffolds/layout.rhtml +29 -0
  51. data/lib/action_controller/templates/scaffolds/list.rhtml +24 -0
  52. data/lib/action_controller/templates/scaffolds/new.rhtml +5 -0
  53. data/lib/action_controller/templates/scaffolds/show.rhtml +9 -0
  54. data/lib/action_controller/test_process.rb +194 -0
  55. data/lib/action_controller/url_rewriter.rb +153 -0
  56. data/lib/action_view.rb +40 -0
  57. data/lib/action_view/base.rb +253 -0
  58. data/lib/action_view/helpers/active_record_helper.rb +171 -0
  59. data/lib/action_view/helpers/date_helper.rb +223 -0
  60. data/lib/action_view/helpers/debug_helper.rb +17 -0
  61. data/lib/action_view/helpers/form_helper.rb +176 -0
  62. data/lib/action_view/helpers/form_options_helper.rb +169 -0
  63. data/lib/action_view/helpers/tag_helper.rb +59 -0
  64. data/lib/action_view/helpers/text_helper.rb +129 -0
  65. data/lib/action_view/helpers/url_helper.rb +72 -0
  66. data/lib/action_view/partials.rb +61 -0
  67. data/lib/action_view/template_error.rb +84 -0
  68. data/lib/action_view/vendor/builder.rb +13 -0
  69. data/lib/action_view/vendor/builder/blankslate.rb +21 -0
  70. data/lib/action_view/vendor/builder/xmlbase.rb +143 -0
  71. data/lib/action_view/vendor/builder/xmlevents.rb +63 -0
  72. data/lib/action_view/vendor/builder/xmlmarkup.rb +288 -0
  73. data/rakefile +105 -0
  74. data/test/abstract_unit.rb +9 -0
  75. data/test/controller/action_pack_assertions_test.rb +295 -0
  76. data/test/controller/active_record_assertions_test.rb +118 -0
  77. data/test/controller/cgi_test.rb +142 -0
  78. data/test/controller/cookie_test.rb +38 -0
  79. data/test/controller/filters_test.rb +159 -0
  80. data/test/controller/flash_test.rb +69 -0
  81. data/test/controller/layout_test.rb +49 -0
  82. data/test/controller/redirect_test.rb +44 -0
  83. data/test/controller/render_test.rb +169 -0
  84. data/test/controller/url_test.rb +318 -0
  85. data/test/fixtures/layouts/builder.rxml +3 -0
  86. data/test/fixtures/layouts/standard.rhtml +1 -0
  87. data/test/fixtures/test/_customer.rhtml +1 -0
  88. data/test/fixtures/test/greeting.rhtml +1 -0
  89. data/test/fixtures/test/hello.rxml +4 -0
  90. data/test/fixtures/test/hello_world.rhtml +1 -0
  91. data/test/fixtures/test/hello_xml_world.rxml +11 -0
  92. data/test/fixtures/test/list.rhtml +1 -0
  93. data/test/template/active_record_helper_test.rb +76 -0
  94. data/test/template/date_helper_test.rb +103 -0
  95. data/test/template/form_helper_test.rb +115 -0
  96. data/test/template/form_options_helper_test.rb +174 -0
  97. data/test/template/tag_helper_test.rb +18 -0
  98. data/test/template/text_helper_test.rb +62 -0
  99. data/test/template/url_helper_test.rb +35 -0
  100. metadata +154 -0
@@ -0,0 +1,318 @@
1
+ require File.dirname(__FILE__) + '/../abstract_unit'
2
+ require 'action_controller/url_rewriter'
3
+
4
+ MockRequest = Struct.new("MockRequest", :protocol, :host, :port, :path, :parameters)
5
+ class MockRequest
6
+ def host_with_port
7
+ if (protocol == "http://" && port == 80) || (protocol == "https://" && port == 443)
8
+ host
9
+ else
10
+ host + ":#{port}"
11
+ end
12
+ end
13
+ end
14
+
15
+ class UrlTest < Test::Unit::TestCase
16
+ def setup
17
+ @library_url = ActionController::UrlRewriter.new(MockRequest.new(
18
+ "http://",
19
+ "www.singlefile.com",
20
+ 80,
21
+ "/library/books/ISBN/0743536703/show",
22
+ { "type" => "ISBN", "code" => "0743536703" }
23
+ ), "books", "show")
24
+
25
+ @library_url_on_index = ActionController::UrlRewriter.new(MockRequest.new(
26
+ "http://",
27
+ "www.singlefile.com",
28
+ 80,
29
+ "/library/books/ISBN/0743536703/",
30
+ { "type" => "ISBN", "code" => "0743536703" }
31
+ ), "books", "index")
32
+
33
+ @clean_url = ActionController::UrlRewriter.new(MockRequest.new(
34
+ "http://", "www.singlefile.com", 80, "/identity/", {}
35
+ ), "identity", "index")
36
+
37
+ @clean_url_with_id = ActionController::UrlRewriter.new(MockRequest.new(
38
+ "http://", "www.singlefile.com", 80, "/identity/show/5", { "id" => "5" }
39
+ ), "identity", "show")
40
+
41
+ @clean_url_with_id_as_char = ActionController::UrlRewriter.new(MockRequest.new(
42
+ "http://", "www.singlefile.com", 80, "/teachers/show/t", { "id" => "t" }
43
+ ), "teachers", "show")
44
+ end
45
+
46
+ def test_clean_action
47
+ assert_equal "http://www.singlefile.com/library/books/ISBN/0743536703/edit", @library_url.rewrite(:action => "edit")
48
+ end
49
+
50
+ def test_clean_action_with_only_path
51
+ assert_equal "/library/books/ISBN/0743536703/edit", @library_url.rewrite(:action => "edit", :only_path => true)
52
+ end
53
+
54
+ def test_action_from_index
55
+ assert_equal "http://www.singlefile.com/library/books/ISBN/0743536703/edit", @library_url_on_index.rewrite(:action => "edit")
56
+ end
57
+
58
+ def test_action_from_index_on_clean
59
+ assert_equal "http://www.singlefile.com/identity/edit", @clean_url.rewrite(:action => "edit")
60
+ end
61
+
62
+ def test_action_without_prefix
63
+ assert_equal "http://www.singlefile.com/library/books/", @library_url.rewrite(:action => "index", :action_prefix => "")
64
+ end
65
+
66
+ def test_action_with_prefix
67
+ assert_equal(
68
+ "http://www.singlefile.com/library/books/XTC/123/show",
69
+ @library_url.rewrite(:action => "show", :action_prefix => "XTC/123")
70
+ )
71
+ end
72
+
73
+ def test_action_prefix_alone
74
+ assert_equal(
75
+ "http://www.singlefile.com/library/books/XTC/123/",
76
+ @library_url.rewrite(:action_prefix => "XTC/123")
77
+ )
78
+ end
79
+
80
+ def test_action_with_suffix
81
+ assert_equal(
82
+ "http://www.singlefile.com/library/books/show/XTC/123",
83
+ @library_url.rewrite(:action => "show", :action_prefix => "", :action_suffix => "XTC/123")
84
+ )
85
+ end
86
+
87
+ def test_clean_controller
88
+ assert_equal "http://www.singlefile.com/library/settings/", @library_url.rewrite(:controller => "settings")
89
+ end
90
+
91
+ def test_clean_controller_prefix
92
+ assert_equal "http://www.singlefile.com/shop/", @library_url.rewrite(:controller_prefix => "shop")
93
+ end
94
+
95
+ def test_controller_and_action
96
+ assert_equal "http://www.singlefile.com/library/settings/show", @library_url.rewrite(:controller => "settings", :action => "show")
97
+ end
98
+
99
+ def test_controller_and_action_and_anchor
100
+ assert_equal(
101
+ "http://www.singlefile.com/library/settings/show#5",
102
+ @library_url.rewrite(:controller => "settings", :action => "show", :anchor => "5")
103
+ )
104
+ end
105
+
106
+ def test_controller_and_action_and_empty_overwrite_params_and_anchor
107
+ assert_equal(
108
+ "http://www.singlefile.com/library/settings/show?code=0743536703&type=ISBN#5",
109
+ @library_url.rewrite(:controller => "settings", :action => "show", :overwrite_params => {}, :anchor => "5")
110
+ )
111
+ end
112
+
113
+ def test_controller_and_action_and_overwrite_params_and_anchor
114
+ assert_equal(
115
+ "http://www.singlefile.com/library/settings/show?code=0000001&type=ISBN#5",
116
+ @library_url.rewrite(:controller => "settings", :action => "show", :overwrite_params => {"code"=>"0000001"}, :anchor => "5")
117
+ )
118
+ end
119
+
120
+ def test_controller_and_action_and_overwrite_params_with_nil_value_and_anchor
121
+ assert_equal(
122
+ "http://www.singlefile.com/library/settings/show?type=ISBN#5",
123
+ @library_url.rewrite(:controller => "settings", :action => "show", :overwrite_params => {"code" => nil}, :anchor => "5")
124
+ )
125
+ end
126
+
127
+ def test_controller_and_action_params_and_overwrite_params_and_anchor
128
+ assert_equal(
129
+ "http://www.singlefile.com/library/settings/show?code=0000001&version=5.0#5",
130
+ @library_url.rewrite(:controller => "settings", :action => "show", :params=>{"version" => "5.0" }, :overwrite_params => {"code"=>"0000001"}, :anchor => "5")
131
+ )
132
+ end
133
+
134
+ def test_controller_and_action_and_params_anchor
135
+ assert_equal(
136
+ "http://www.singlefile.com/library/settings/show?update=1#5",
137
+ @library_url.rewrite(:controller => "settings", :action => "show", :params => { "update" => "1"}, :anchor => "5")
138
+ )
139
+ end
140
+
141
+ def test_controller_and_index_action
142
+ assert_equal "http://www.singlefile.com/library/settings/", @library_url.rewrite(:controller => "settings", :action => "index")
143
+ end
144
+
145
+ def test_controller_and_action_with_same_name_as_controller
146
+ assert_equal "http://www.singlefile.com/anything/identity", @clean_url.rewrite(:controller => "anything", :action => "identity")
147
+ end
148
+
149
+ def test_controller_and_index_action_without_controller_prefix
150
+ assert_equal(
151
+ "http://www.singlefile.com/settings/",
152
+ @library_url.rewrite(:controller => "settings", :action => "index", :controller_prefix => "")
153
+ )
154
+ end
155
+
156
+ def test_controller_and_index_action_with_controller_prefix
157
+ assert_equal(
158
+ "http://www.singlefile.com/fantastic/settings/show",
159
+ @library_url.rewrite(:controller => "settings", :action => "show", :controller_prefix => "fantastic")
160
+ )
161
+ end
162
+
163
+ def test_path_parameters
164
+ assert_equal "http://www.singlefile.com/library/books/EXBC/0743536703/show", @library_url.rewrite(:path_params => {"type" => "EXBC"})
165
+ end
166
+
167
+ def test_parameters
168
+ assert_equal(
169
+ "http://www.singlefile.com/library/books/ISBN/0743536703/show?delete=1&name=David",
170
+ @library_url.rewrite(:params => {"delete" => "1", "name" => "David"})
171
+ )
172
+ end
173
+
174
+ def test_parameters_with_id
175
+ assert_equal(
176
+ "http://www.singlefile.com/identity/show?name=David&id=5",
177
+ @clean_url.rewrite(
178
+ :action => "show",
179
+ :params => {"id" => "5", "name" => "David"}
180
+ )
181
+ )
182
+ end
183
+
184
+ def test_action_with_id
185
+ assert_equal(
186
+ "http://www.singlefile.com/identity/show/7",
187
+ @clean_url_with_id.rewrite(
188
+ :action => "show",
189
+ :id => 7
190
+ )
191
+ )
192
+ end
193
+
194
+ def test_parameters_with_id_and_away
195
+ assert_equal(
196
+ "http://www.singlefile.com/identity/show/25?name=David",
197
+ @clean_url_with_id.rewrite(
198
+ :path_params => {"id" => "25" },
199
+ :params => { "name" => "David"}
200
+ )
201
+ )
202
+ end
203
+
204
+ def test_action_going_away_from_id
205
+ assert_equal(
206
+ "http://www.singlefile.com/identity/list",
207
+ @clean_url_with_id.rewrite(
208
+ :action => "list"
209
+ )
210
+ )
211
+ end
212
+
213
+ def test_parameters_with_direct_id_and_away
214
+ assert_equal(
215
+ "http://www.singlefile.com/identity/show/25?name=David",
216
+ @clean_url_with_id.rewrite(
217
+ :id => "25",
218
+ :params => { "name" => "David"}
219
+ )
220
+ )
221
+ end
222
+
223
+ def test_parameters_with_direct_id_and_away
224
+ assert_equal(
225
+ "http://www.singlefile.com/store/open/25?name=David",
226
+ @clean_url_with_id.rewrite(
227
+ :controller => "store",
228
+ :action => "open",
229
+ :id => "25",
230
+ :params => { "name" => "David"}
231
+ )
232
+ )
233
+ end
234
+
235
+ def test_parameters_to_id
236
+ assert_equal(
237
+ "http://www.singlefile.com/identity/show/25?name=David",
238
+ @clean_url.rewrite(
239
+ :action => "show",
240
+ :path_params => {"id" => "25" },
241
+ :params => { "name" => "David"}
242
+ )
243
+ )
244
+ end
245
+
246
+ def test_parameters_from_id
247
+ assert_equal(
248
+ "http://www.singlefile.com/identity/",
249
+ @clean_url_with_id.rewrite(
250
+ :action => "index"
251
+ )
252
+ )
253
+ end
254
+
255
+ def test_id_as_char_and_part_of_controller
256
+ assert_equal(
257
+ "http://www.singlefile.com/teachers/skill/5",
258
+ @clean_url_with_id_as_char.rewrite(
259
+ :action => "skill",
260
+ :id => 5
261
+ )
262
+ )
263
+ end
264
+
265
+ def test_from_clean_to_libray
266
+ assert_equal(
267
+ "http://www.singlefile.com/library/books/ISBN/0743536703/show?delete=1&name=David",
268
+ @clean_url.rewrite(
269
+ :controller_prefix => "library",
270
+ :controller => "books",
271
+ :action_prefix => "ISBN/0743536703",
272
+ :action => "show",
273
+ :params => {"delete" => "1", "name" => "David"}
274
+ )
275
+ )
276
+ end
277
+
278
+ def test_from_library_to_clean
279
+ assert_equal(
280
+ "http://www.singlefile.com/identity/",
281
+ @library_url.rewrite(
282
+ :controller => "identity", :controller_prefix => ""
283
+ )
284
+ )
285
+ end
286
+
287
+ def test_from_another_port
288
+ @library_url = ActionController::UrlRewriter.new(MockRequest.new(
289
+ "http://",
290
+ "www.singlefile.com",
291
+ 8080,
292
+ "/library/books/ISBN/0743536703/show",
293
+ { "type" => "ISBN", "code" => "0743536703" }
294
+ ), "books", "show")
295
+
296
+ assert_equal(
297
+ "http://www.singlefile.com:8080/identity/",
298
+ @library_url.rewrite(
299
+ :controller => "identity", :controller_prefix => ""
300
+ )
301
+ )
302
+ end
303
+
304
+ def test_basecamp
305
+ basecamp_url = ActionController::UrlRewriter.new(MockRequest.new(
306
+ "http://",
307
+ "projects.basecamp",
308
+ 80,
309
+ "/clients/disarray/1/msg/transcripts/",
310
+ {"category_name"=>"transcripts", "client_name"=>"disarray", "action"=>"index", "controller"=>"msg", "project_name"=>"1"}
311
+ ), "msg", "index")
312
+
313
+ assert_equal(
314
+ "http://projects.basecamp/clients/disarray/1/msg/transcripts/1/comments",
315
+ basecamp_url.rewrite(:action_prefix => "transcripts/1", :action => "comments")
316
+ )
317
+ end
318
+ end
@@ -0,0 +1,3 @@
1
+ xml.wrapper do
2
+ xml << @content_for_layout
3
+ end
@@ -0,0 +1 @@
1
+ <html><%= @content_for_layout %></html>
@@ -0,0 +1 @@
1
+ Hello: <%= customer.name %>
@@ -0,0 +1 @@
1
+ <p>This is grand!</p>
@@ -0,0 +1,4 @@
1
+ xml.html do
2
+ xml.p "Hello #{@name}"
3
+ xml << render_file("test/greeting")
4
+ end
@@ -0,0 +1 @@
1
+ Hello world!
@@ -0,0 +1,11 @@
1
+ xml.html do
2
+ xml.head do
3
+ xml.title "Hello World"
4
+ end
5
+
6
+ xml.body do
7
+ xml.p "abes"
8
+ xml.p "monks"
9
+ xml.p "wiseguys"
10
+ end
11
+ end
@@ -0,0 +1 @@
1
+ <%= render_collection_of_partials "customer", @customers %>
@@ -0,0 +1,76 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../../lib/action_view/helpers/date_helper'
3
+ require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_helper'
4
+ # require File.dirname(__FILE__) + '/../../lib/action_view/helpers/active_record_helper'
5
+
6
+ class ActiveRecordHelperTest < Test::Unit::TestCase
7
+ include ActionView::Helpers::FormHelper
8
+ include ActionView::Helpers::ActiveRecordHelper
9
+
10
+ Post = Struct.new("Post", :title, :author_name, :body, :secret, :written_on)
11
+ Column = Struct.new("Column", :type, :name, :human_name)
12
+
13
+ def setup
14
+ @post = Post.new
15
+ def @post.errors() Class.new{ def on(field) field == "author_name" || field == "body" end }.new end
16
+ def @post.new_record?() true end
17
+
18
+ def @post.column_for_attribute(attr_name)
19
+ Post.content_columns.select { |column| column.name == attr_name }.first
20
+ end
21
+
22
+ def Post.content_columns() [ Column.new(:string, "title", "Title"), Column.new(:text, "body", "Body") ] end
23
+
24
+ @post.title = "Hello World"
25
+ @post.author_name = ""
26
+ @post.body = "Back to the hill and over it again!"
27
+ @post.secret = 1
28
+ @post.written_on = Date.new(2004, 6, 15)
29
+ end
30
+
31
+ def test_generic_input_tag
32
+ assert_equal(
33
+ '<input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />', input("post", "title")
34
+ )
35
+ end
36
+
37
+ def test_text_area_with_errors
38
+ assert_equal(
39
+ "<div class=\"fieldWithErrors\"><textarea cols=\"40\" id=\"post_body\" name=\"post[body]\" rows=\"20\" wrap=\"virtual\">Back to the hill and over it again!</textarea></div>",
40
+ text_area("post", "body")
41
+ )
42
+ end
43
+
44
+ def test_text_field_with_errors
45
+ assert_equal(
46
+ '<div class="fieldWithErrors"><input id="post_author_name" name="post[author_name]" size="30" type="text" value="" /></div>',
47
+ text_field("post", "author_name")
48
+ )
49
+ end
50
+
51
+ def test_form_with_string
52
+ assert_equal(
53
+ "<form action='create' method='POST'><p><b>Title</b><br /><input id=\"post_title\" name=\"post[title]\" size=\"30\" type=\"text\" value=\"Hello World\" /></p>\n<p><b>Body</b><br /><div class=\"fieldWithErrors\"><textarea cols=\"40\" id=\"post_body\" name=\"post[body]\" rows=\"20\" wrap=\"virtual\">Back to the hill and over it again!</textarea></div></p><input type='submit' value='Create' /></form>",
54
+ form("post")
55
+ )
56
+ end
57
+
58
+ def test_form_with_date
59
+ def Post.content_columns() [ Column.new(:date, "written_on", "Written on") ] end
60
+
61
+ assert_equal(
62
+ "<form action='create' method='POST'><p><b>Written on</b><br /><select name='post[written_on(1i)]'>\n<option>1999</option>\n<option>2000</option>\n<option>2001</option>\n<option>2002</option>\n<option>2003</option>\n<option selected=\"selected\">2004</option>\n<option>2005</option>\n<option>2006</option>\n<option>2007</option>\n<option>2008</option>\n<option>2009</option>\n</select>\n<select name='post[written_on(2i)]'>\n<option value='1'>January</option>\n<option value='2'>February</option>\n<option value='3'>March</option>\n<option value='4'>April</option>\n<option value='5'>May</option>\n<option value='6' selected=\"selected\">June</option>\n<option value='7'>July</option>\n<option value='8'>August</option>\n<option value='9'>September</option>\n<option value='10'>October</option>\n<option value='11'>November</option>\n<option value='12'>December</option>\n</select>\n<select name='post[written_on(3i)]'>\n<option>1</option>\n<option>2</option>\n<option>3</option>\n<option>4</option>\n<option>5</option>\n<option>6</option>\n<option>7</option>\n<option>8</option>\n<option>9</option>\n<option>10</option>\n<option>11</option>\n<option>12</option>\n<option>13</option>\n<option>14</option>\n<option selected=\"selected\">15</option>\n<option>16</option>\n<option>17</option>\n<option>18</option>\n<option>19</option>\n<option>20</option>\n<option>21</option>\n<option>22</option>\n<option>23</option>\n<option>24</option>\n<option>25</option>\n<option>26</option>\n<option>27</option>\n<option>28</option>\n<option>29</option>\n<option>30</option>\n<option>31</option>\n</select>\n</p><input type='submit' value='Create' /></form>",
63
+ form("post")
64
+ )
65
+ end
66
+
67
+ def test_form_with_datetime
68
+ def Post.content_columns() [ Column.new(:datetime, "written_on", "Written on") ] end
69
+ @post.written_on = Time.gm(2004, 6, 15, 16, 30)
70
+
71
+ assert_equal(
72
+ "<form action='create' method='POST'><p><b>Written on</b><br /><select name='post[written_on(1i)]'>\n<option>1999</option>\n<option>2000</option>\n<option>2001</option>\n<option>2002</option>\n<option>2003</option>\n<option selected=\"selected\">2004</option>\n<option>2005</option>\n<option>2006</option>\n<option>2007</option>\n<option>2008</option>\n<option>2009</option>\n</select>\n<select name='post[written_on(2i)]'>\n<option value='1'>January</option>\n<option value='2'>February</option>\n<option value='3'>March</option>\n<option value='4'>April</option>\n<option value='5'>May</option>\n<option value='6' selected=\"selected\">June</option>\n<option value='7'>July</option>\n<option value='8'>August</option>\n<option value='9'>September</option>\n<option value='10'>October</option>\n<option value='11'>November</option>\n<option value='12'>December</option>\n</select>\n<select name='post[written_on(3i)]'>\n<option>1</option>\n<option>2</option>\n<option>3</option>\n<option>4</option>\n<option>5</option>\n<option>6</option>\n<option>7</option>\n<option>8</option>\n<option>9</option>\n<option>10</option>\n<option>11</option>\n<option>12</option>\n<option>13</option>\n<option>14</option>\n<option selected=\"selected\">15</option>\n<option>16</option>\n<option>17</option>\n<option>18</option>\n<option>19</option>\n<option>20</option>\n<option>21</option>\n<option>22</option>\n<option>23</option>\n<option>24</option>\n<option>25</option>\n<option>26</option>\n<option>27</option>\n<option>28</option>\n<option>29</option>\n<option>30</option>\n<option>31</option>\n</select>\n &mdash; <select name='post[written_on(4i)]'>\n<option>00</option>\n<option>01</option>\n<option>02</option>\n<option>03</option>\n<option>04</option>\n<option>05</option>\n<option>06</option>\n<option>07</option>\n<option>08</option>\n<option>09</option>\n<option>10</option>\n<option>11</option>\n<option>12</option>\n<option>13</option>\n<option>14</option>\n<option>15</option>\n<option selected=\"selected\">16</option>\n<option>17</option>\n<option>18</option>\n<option>19</option>\n<option>20</option>\n<option>21</option>\n<option>22</option>\n<option>23</option>\n</select>\n : <select name='post[written_on(5i)]'>\n<option>00</option>\n<option>01</option>\n<option>02</option>\n<option>03</option>\n<option>04</option>\n<option>05</option>\n<option>06</option>\n<option>07</option>\n<option>08</option>\n<option>09</option>\n<option>10</option>\n<option>11</option>\n<option>12</option>\n<option>13</option>\n<option>14</option>\n<option>15</option>\n<option>16</option>\n<option>17</option>\n<option>18</option>\n<option>19</option>\n<option>20</option>\n<option>21</option>\n<option>22</option>\n<option>23</option>\n<option>24</option>\n<option>25</option>\n<option>26</option>\n<option>27</option>\n<option>28</option>\n<option>29</option>\n<option selected=\"selected\">30</option>\n<option>31</option>\n<option>32</option>\n<option>33</option>\n<option>34</option>\n<option>35</option>\n<option>36</option>\n<option>37</option>\n<option>38</option>\n<option>39</option>\n<option>40</option>\n<option>41</option>\n<option>42</option>\n<option>43</option>\n<option>44</option>\n<option>45</option>\n<option>46</option>\n<option>47</option>\n<option>48</option>\n<option>49</option>\n<option>50</option>\n<option>51</option>\n<option>52</option>\n<option>53</option>\n<option>54</option>\n<option>55</option>\n<option>56</option>\n<option>57</option>\n<option>58</option>\n<option>59</option>\n</select>\n</p><input type='submit' value='Create' /></form>",
73
+ form("post")
74
+ )
75
+ end
76
+ end
@@ -0,0 +1,103 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../../lib/action_view/helpers/date_helper'
3
+
4
+ class DateHelperTest < Test::Unit::TestCase
5
+ include ActionView::Helpers::DateHelper
6
+
7
+ def test_distance_in_words
8
+ from = Time.mktime(2004, 3, 6, 21, 41, 18)
9
+
10
+ assert_equal "5 minutes", distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 21, 46, 25))
11
+ assert_equal "about 1 hour", distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 22, 47, 25))
12
+ assert_equal "about 3 hours", distance_of_time_in_words(from, Time.mktime(2004, 3, 7, 0, 41))
13
+ assert_equal "about 4 hours", distance_of_time_in_words(from, Time.mktime(2004, 3, 7, 1, 20))
14
+ assert_equal "2 days", distance_of_time_in_words(from, Time.mktime(2004, 3, 9, 15, 40))
15
+ end
16
+
17
+ def test_select_day
18
+ expected = "<select name='date[day]'>\n"
19
+ expected <<
20
+ "<option>1</option>\n<option>2</option>\n<option>3</option>\n<option>4</option>\n<option>5</option>\n<option>6</option>\n<option>7</option>\n<option>8</option>\n<option>9</option>\n<option>10</option>\n<option>11</option>\n<option>12</option>\n<option>13</option>\n<option>14</option>\n<option>15</option>\n<option selected=\"selected\">16</option>\n<option>17</option>\n<option>18</option>\n<option>19</option>\n<option>20</option>\n<option>21</option>\n<option>22</option>\n<option>23</option>\n<option>24</option>\n<option>25</option>\n<option>26</option>\n<option>27</option>\n<option>28</option>\n<option>29</option>\n<option>30</option>\n<option>31</option>\n"
21
+ expected << "</select>\n"
22
+
23
+ assert_equal expected, select_day(Time.mktime(2003, 8, 16))
24
+ assert_equal expected, select_day(16)
25
+ end
26
+
27
+ def test_select_day_with_blank
28
+ expected = "<select name='date[day]'>\n"
29
+ expected <<
30
+ "<option></option>\n<option>1</option>\n<option>2</option>\n<option>3</option>\n<option>4</option>\n<option>5</option>\n<option>6</option>\n<option>7</option>\n<option>8</option>\n<option>9</option>\n<option>10</option>\n<option>11</option>\n<option>12</option>\n<option>13</option>\n<option>14</option>\n<option>15</option>\n<option selected=\"selected\">16</option>\n<option>17</option>\n<option>18</option>\n<option>19</option>\n<option>20</option>\n<option>21</option>\n<option>22</option>\n<option>23</option>\n<option>24</option>\n<option>25</option>\n<option>26</option>\n<option>27</option>\n<option>28</option>\n<option>29</option>\n<option>30</option>\n<option>31</option>\n"
31
+ expected << "</select>\n"
32
+
33
+ assert_equal expected, select_day(Time.mktime(2003, 8, 16), :include_blank => true)
34
+ assert_equal expected, select_day(16, :include_blank => true)
35
+ end
36
+
37
+ def test_select_month
38
+ expected = "<select name='date[month]'>\n"
39
+ expected << "<option value='1'>January</option>\n<option value='2'>February</option>\n<option value='3'>March</option>\n<option value='4'>April</option>\n<option value='5'>May</option>\n<option value='6'>June</option>\n<option value='7'>July</option>\n<option value='8' selected=\"selected\">August</option>\n<option value='9'>September</option>\n<option value='10'>October</option>\n<option value='11'>November</option>\n<option value='12'>December</option>\n"
40
+ expected << "</select>\n"
41
+
42
+ assert_equal expected, select_month(Time.mktime(2003, 8, 16))
43
+ assert_equal expected, select_month(8)
44
+ end
45
+
46
+ def test_select_month_with_numbers
47
+ expected = "<select name='date[month]'>\n"
48
+ expected << "<option value='1'>1</option>\n<option value='2'>2</option>\n<option value='3'>3</option>\n<option value='4'>4</option>\n<option value='5'>5</option>\n<option value='6'>6</option>\n<option value='7'>7</option>\n<option value='8' selected=\"selected\">8</option>\n<option value='9'>9</option>\n<option value='10'>10</option>\n<option value='11'>11</option>\n<option value='12'>12</option>\n"
49
+ expected << "</select>\n"
50
+
51
+ assert_equal expected, select_month(Time.mktime(2003, 8, 16), :use_month_numbers => true)
52
+ assert_equal expected, select_month(8, :use_month_numbers => true)
53
+ end
54
+
55
+ def test_select_month_with_numbers_and_names
56
+ expected = "<select name='date[month]'>\n"
57
+ expected << "<option value='1'>1 - January</option>\n<option value='2'>2 - February</option>\n<option value='3'>3 - March</option>\n<option value='4'>4 - April</option>\n<option value='5'>5 - May</option>\n<option value='6'>6 - June</option>\n<option value='7'>7 - July</option>\n<option value='8' selected=\"selected\">8 - August</option>\n<option value='9'>9 - September</option>\n<option value='10'>10 - October</option>\n<option value='11'>11 - November</option>\n<option value='12'>12 - December</option>\n"
58
+ expected << "</select>\n"
59
+
60
+ assert_equal expected, select_month(Time.mktime(2003, 8, 16), :add_month_numbers => true)
61
+ assert_equal expected, select_month(8, :add_month_numbers => true)
62
+ end
63
+
64
+ def test_select_year
65
+ expected = "<select name='date[year]'>\n"
66
+ expected << "<option selected=\"selected\">2003</option>\n<option>2004</option>\n<option>2005</option>\n"
67
+ expected << "</select>\n"
68
+
69
+ assert_equal expected, select_year(Time.mktime(2003, 8, 16), :start_year => 2003, :end_year => 2005)
70
+ assert_equal expected, select_year(2003, :start_year => 2003, :end_year => 2005)
71
+ end
72
+
73
+ def test_select_year_with_type_discarding
74
+ expected = "<select name='date_year'>\n"
75
+ expected << "<option selected=\"selected\">2003</option>\n<option>2004</option>\n<option>2005</option>\n"
76
+ expected << "</select>\n"
77
+
78
+ assert_equal expected, select_year(
79
+ Time.mktime(2003, 8, 16), :prefix => "date_year", :discard_type => true, :start_year => 2003, :end_year => 2005)
80
+ assert_equal expected, select_year(
81
+ 2003, :prefix => "date_year", :discard_type => true, :start_year => 2003, :end_year => 2005)
82
+ end
83
+
84
+
85
+ def test_select_date
86
+ expected = "<select name='date[first][year]'>\n"
87
+ expected << "<option selected=\"selected\">2003</option>\n<option>2004</option>\n<option>2005</option>\n"
88
+ expected << "</select>\n"
89
+
90
+ expected << "<select name='date[first][month]'>\n"
91
+ expected << "<option value='1'>January</option>\n<option value='2'>February</option>\n<option value='3'>March</option>\n<option value='4'>April</option>\n<option value='5'>May</option>\n<option value='6'>June</option>\n<option value='7'>July</option>\n<option value='8' selected=\"selected\">August</option>\n<option value='9'>September</option>\n<option value='10'>October</option>\n<option value='11'>November</option>\n<option value='12'>December</option>\n"
92
+ expected << "</select>\n"
93
+
94
+ expected << "<select name='date[first][day]'>\n"
95
+ expected <<
96
+ "<option>1</option>\n<option>2</option>\n<option>3</option>\n<option>4</option>\n<option>5</option>\n<option>6</option>\n<option>7</option>\n<option>8</option>\n<option>9</option>\n<option>10</option>\n<option>11</option>\n<option>12</option>\n<option>13</option>\n<option>14</option>\n<option>15</option>\n<option selected=\"selected\">16</option>\n<option>17</option>\n<option>18</option>\n<option>19</option>\n<option>20</option>\n<option>21</option>\n<option>22</option>\n<option>23</option>\n<option>24</option>\n<option>25</option>\n<option>26</option>\n<option>27</option>\n<option>28</option>\n<option>29</option>\n<option>30</option>\n<option>31</option>\n"
97
+ expected << "</select>\n"
98
+
99
+ assert_equal expected, select_date(
100
+ Time.mktime(2003, 8, 16), :start_year => 2003, :end_year => 2005, :prefix => "date[first]"
101
+ )
102
+ end
103
+ end