actionpack 1.5.1 → 1.6.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 (39) hide show
  1. data/CHANGELOG +94 -0
  2. data/README +24 -0
  3. data/lib/action_controller.rb +2 -0
  4. data/lib/action_controller/assertions/action_pack_assertions.rb +1 -1
  5. data/lib/action_controller/base.rb +15 -2
  6. data/lib/action_controller/caching.rb +6 -16
  7. data/lib/action_controller/components.rb +1 -1
  8. data/lib/action_controller/flash.rb +125 -29
  9. data/lib/action_controller/pagination.rb +378 -0
  10. data/lib/action_controller/request.rb +13 -6
  11. data/lib/action_controller/routing.rb +37 -3
  12. data/lib/action_controller/test_process.rb +7 -3
  13. data/lib/action_controller/url_rewriter.rb +5 -4
  14. data/lib/action_view/helpers/asset_tag_helper.rb +35 -4
  15. data/lib/action_view/helpers/capture_helper.rb +95 -0
  16. data/lib/action_view/helpers/form_helper.rb +1 -1
  17. data/lib/action_view/helpers/form_options_helper.rb +2 -0
  18. data/lib/action_view/helpers/form_tag_helper.rb +28 -10
  19. data/lib/action_view/helpers/javascript_helper.rb +192 -0
  20. data/lib/action_view/helpers/javascripts/prototype.js +336 -0
  21. data/lib/action_view/helpers/pagination_helper.rb +71 -0
  22. data/lib/action_view/helpers/tag_helper.rb +2 -1
  23. data/lib/action_view/helpers/text_helper.rb +15 -2
  24. data/lib/action_view/helpers/url_helper.rb +3 -20
  25. data/lib/action_view/partials.rb +4 -2
  26. data/rakefile +2 -2
  27. data/test/controller/action_pack_assertions_test.rb +1 -2
  28. data/test/controller/flash_test.rb +30 -5
  29. data/test/controller/request_test.rb +33 -10
  30. data/test/controller/routing_tests.rb +26 -0
  31. data/test/template/asset_tag_helper_test.rb +87 -2
  32. data/test/template/form_helper_test.rb +1 -0
  33. data/test/template/form_options_helper_test.rb +11 -0
  34. data/test/template/form_tag_helper_test.rb +84 -16
  35. data/test/template/tag_helper_test.rb +2 -15
  36. data/test/template/text_helper_test.rb +6 -0
  37. data/test/template/url_helper_test.rb +13 -18
  38. metadata +10 -5
  39. data/test/controller/url_obsolete.rb.rej +0 -747
@@ -8,7 +8,7 @@ module ActionView
8
8
  # Returns the URL for the set of +options+ provided. This takes the same options
9
9
  # as url_for. For a list, see the url_for documentation in link:classes/ActionController/Base.html#M000079.
10
10
  def url_for(options = {}, *parameters_for_method_reference)
11
- if Hash === options then options = { :only_path => true }.update(options.stringify_keys) end
11
+ options = { :only_path => true }.update(options.symbolize_keys) if options.kind_of? Hash
12
12
  @controller.send(:url_for, options, *parameters_for_method_reference)
13
13
  end
14
14
 
@@ -33,25 +33,8 @@ module ActionView
33
33
  end
34
34
  end
35
35
 
36
- # Creates a link tag on the image residing at the +src+ using an URL created by the set of +options+. This takes the same options
37
- # as url_for. For a list, see the url_for documentation in link:classes/ActionController/Base.html#M000079.
38
- # It's also possible to pass a string instead of an options hash to get a link tag that just points without consideration.
39
- # The <tt>html_options</tt> works jointly for the image and ahref tag by letting the following special values enter the options on
40
- # the image and the rest goes to the ahref:
41
- #
42
- # * <tt>:alt</tt> - If no alt text is given, the file name part of the +src+ is used (capitalized and without the extension)
43
- # * <tt>:size</tt> - Supplied as "XxY", so "30x45" becomes width="30" and height="45"
44
- # * <tt>:border</tt> - Draws a border around the link
45
- # * <tt>:align</tt> - Sets the alignment, no special features
46
- #
47
- # The +src+ can be supplied as a...
48
- # * full path, like "/my_images/image.gif"
49
- # * file name, like "rss.gif", that gets expanded to "/images/rss.gif"
50
- # * file name without extension, like "logo", that gets expanded to "/images/logo.png"
51
- #
52
- # Examples:
53
- # link_image_to "logo", { :controller => "home" }, :alt => "Homepage", :size => "45x80"
54
- # link_image_to "delete", { :action => "destroy" }, :size => "10x10", :confirm => "Are you sure?", "class" => "admin"
36
+ # This tag is deprecated. Combine the link_to and AssetTagHelper::image_tag yourself instead, like:
37
+ # link_to(image_tag("rss", :size => "30x45", :border => 0), "http://www.example.com")
55
38
  def link_image_to(src, options = {}, html_options = {}, *parameters_for_method_reference)
56
39
  image_options = { "src" => src.include?("/") ? src : "/images/#{src}" }
57
40
  image_options["src"] += ".png" unless image_options["src"].include?(".")
@@ -17,7 +17,7 @@ module ActionView
17
17
  # a partial by the same name as the elements contained within. So the three-lined example in "Using partials" can be rewritten
18
18
  # with a single line:
19
19
  #
20
- # <%= render_collection_of_partials "ad", @advertisements %>
20
+ # <%= render_partial_collection "ad", @advertisements %>
21
21
  #
22
22
  # This will render "advertiser/_ad.rhtml" and pass the local variable +ad+ to the template for display. An iteration counter
23
23
  # will automatically be made available to the template with a name of the form +partial_name_counter+. In the case of the
@@ -39,7 +39,7 @@ module ActionView
39
39
  render("#{path}/_#{partial_name}", { partial_name => object }.merge(local_assigns))
40
40
  end
41
41
 
42
- def render_collection_of_partials(partial_name, collection, partial_spacer_template = nil, local_assigns = {})
42
+ def render_partial_collection(partial_name, collection, partial_spacer_template = nil, local_assigns = {})
43
43
  collection_of_partials = Array.new
44
44
  counter_name = partial_counter_name(partial_name)
45
45
  collection.each_with_index do |element, counter|
@@ -55,6 +55,8 @@ module ActionView
55
55
  end
56
56
  end
57
57
 
58
+ alias_method :render_collection_of_partials, :render_partial_collection
59
+
58
60
  private
59
61
  def partial_pieces(partial_path)
60
62
  if partial_path.include?('/')
data/rakefile CHANGED
@@ -8,7 +8,7 @@ require 'rake/contrib/rubyforgepublisher'
8
8
 
9
9
  PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
10
10
  PKG_NAME = 'actionpack'
11
- PKG_VERSION = '1.5.1' + PKG_BUILD
11
+ PKG_VERSION = '1.6.0' + PKG_BUILD
12
12
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
13
13
 
14
14
  desc "Default Task"
@@ -57,7 +57,7 @@ spec = Gem::Specification.new do |s|
57
57
  s.has_rdoc = true
58
58
  s.requirements << 'none'
59
59
 
60
- s.add_dependency('activesupport', '= 1.0.1' + PKG_BUILD)
60
+ s.add_dependency('activesupport', '= 1.0.2' + PKG_BUILD)
61
61
 
62
62
  s.require_path = 'lib'
63
63
  s.autorequire = 'action_controller'
@@ -179,7 +179,6 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
179
179
  # test the flash-based assertions with no flash at all
180
180
  def test_flash_assertions_negative
181
181
  process :nothing
182
- assert_flash_not_exists
183
182
  assert_flash_empty
184
183
  assert_flash_has_no 'hello'
185
184
  assert_flash_has_no 'qwerty'
@@ -230,7 +229,7 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
230
229
  # check the empty flashing
231
230
  def test_flash_me_naked
232
231
  process :flash_me_naked
233
- assert @response.has_flash?
232
+ assert !@response.has_flash?
234
233
  assert !@response.has_flash_with_contents?
235
234
  end
236
235
 
@@ -7,12 +7,26 @@ class FlashTest < Test::Unit::TestCase
7
7
  render_text "hello"
8
8
  end
9
9
 
10
+ def set_flash_now
11
+ flash.now["that"] = "hello"
12
+ @flash_copy = {}.update flash
13
+ render_text "hello"
14
+ end
15
+
16
+ def attempt_to_use_flash_now
17
+ @flash_copy = {}.update flash
18
+ @flashy = flash["that"]
19
+ render_text "hello"
20
+ end
21
+
10
22
  def use_flash
23
+ @flash_copy = {}.update flash
11
24
  @flashy = flash["that"]
12
25
  render_text "hello"
13
26
  end
14
27
 
15
28
  def use_flash_and_keep_it
29
+ @flash_copy = {}.update flash
16
30
  @flashy = flash["that"]
17
31
  keep_flash
18
32
  render_text "hello"
@@ -33,11 +47,11 @@ class FlashTest < Test::Unit::TestCase
33
47
 
34
48
  @request.action = "use_flash"
35
49
  first_response = process_request
36
- assert_equal "hello", first_response.template.assigns["flash"]["that"]
50
+ assert_equal "hello", first_response.template.assigns["flash_copy"]["that"]
37
51
  assert_equal "hello", first_response.template.assigns["flashy"]
38
52
 
39
53
  second_response = process_request
40
- assert_nil second_response.template.assigns["flash"]["that"], "On second flash"
54
+ assert_nil second_response.template.assigns["flash_copy"]["that"], "On second flash"
41
55
  end
42
56
 
43
57
  def test_keep_flash
@@ -46,17 +60,28 @@ class FlashTest < Test::Unit::TestCase
46
60
 
47
61
  @request.action = "use_flash_and_keep_it"
48
62
  first_response = process_request
49
- assert_equal "hello", first_response.template.assigns["flash"]["that"]
63
+ assert_equal "hello", first_response.template.assigns["flash_copy"]["that"]
50
64
  assert_equal "hello", first_response.template.assigns["flashy"]
51
65
 
52
66
  @request.action = "use_flash"
53
67
  second_response = process_request
54
- assert_equal "hello", second_response.template.assigns["flash"]["that"], "On second flash"
68
+ assert_equal "hello", second_response.template.assigns["flash_copy"]["that"], "On second flash"
55
69
 
56
70
  third_response = process_request
57
- assert_nil third_response.template.assigns["flash"]["that"], "On third flash"
71
+ assert_nil third_response.template.assigns["flash_copy"]["that"], "On third flash"
58
72
  end
59
73
 
74
+ def test_flash_now
75
+ @request.action = "set_flash_now"
76
+ response = process_request
77
+ assert_equal "hello", response.template.assigns["flash_copy"]["that"]
78
+
79
+ @request.action = "attempt_to_use_flash_now"
80
+ first_response = process_request
81
+ assert_nil first_response.template.assigns["flash_copy"]["that"]
82
+ assert_nil first_response.template.assigns["flashy"]
83
+ end
84
+
60
85
  private
61
86
  def initialize_request_and_response
62
87
  @request = ActionController::TestRequest.new
@@ -32,6 +32,23 @@ class RequestTest < Test::Unit::TestCase
32
32
  assert_equal ":8080", @request.port_string
33
33
  end
34
34
 
35
+ def test_relative_url_root
36
+ @request.env['SCRIPT_NAME'] = nil
37
+ assert_equal "", @request.relative_url_root
38
+
39
+ @request.env['SCRIPT_NAME'] = "/dispatch.cgi"
40
+ assert_equal "", @request.relative_url_root
41
+
42
+ @request.env['SCRIPT_NAME'] = "/myapp.rb"
43
+ assert_equal "", @request.relative_url_root
44
+
45
+ @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
46
+ assert_equal "/hieraki", @request.relative_url_root
47
+
48
+ @request.env['SCRIPT_NAME'] = "/collaboration/hieraki/dispatch.cgi"
49
+ assert_equal "/collaboration/hieraki", @request.relative_url_root
50
+ end
51
+
35
52
  def test_request_uri
36
53
  @request.set_REQUEST_URI "http://www.rubyonrails.org/path/of/some/uri?mapped=1"
37
54
  assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
@@ -52,18 +69,24 @@ class RequestTest < Test::Unit::TestCase
52
69
  @request.set_REQUEST_URI "/?m=b"
53
70
  assert_equal "/?m=b", @request.request_uri
54
71
  assert_equal "/", @request.path
55
- end
56
-
57
- def test_path_info
58
- @request.env["PATH_INFO"] = "/path/of/some/uri"
59
- assert_equal "/path/of/some/uri", @request.path_info
60
- assert_equal "/path/of/some/uri", @request.path
61
72
 
62
- # PATH_INFO actually has a .html suffix on many servers. But we don't want Rails to see the .html part.
63
- @request.env["PATH_INFO"] = "/path/of/some/uri.html"
64
- assert_equal "/path/of/some/uri", @request.path_info
65
- assert_equal "/path/of/some/uri", @request.path
73
+ @request.set_REQUEST_URI "/"
74
+ @request.env['SCRIPT_NAME'] = "/dispatch.cgi"
75
+ assert_equal "/", @request.request_uri
76
+ assert_equal "/", @request.path
77
+
78
+ @request.set_REQUEST_URI "/hieraki/"
79
+ @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
80
+ assert_equal "/hieraki/", @request.request_uri
81
+ assert_equal "/", @request.path
82
+
83
+ @request.set_REQUEST_URI "/collaboration/hieraki/books/edit/2"
84
+ @request.env['SCRIPT_NAME'] = "/collaboration/hieraki/dispatch.cgi"
85
+ assert_equal "/collaboration/hieraki/books/edit/2", @request.request_uri
86
+ assert_equal "/books/edit/2", @request.path
87
+
66
88
  end
89
+
67
90
 
68
91
  def test_host_with_port
69
92
  @request.env['HTTP_HOST'] = "rubyonrails.org:8080"
@@ -325,6 +325,25 @@ class RouteTests < Test::Unit::TestCase
325
325
  assert_equal Controllers::Admin::UserController, controller
326
326
  assert_equal %w{action id}, leftovers
327
327
  end
328
+
329
+ def test_path_collection
330
+ route '*path_info', :controller => 'content', :action => 'fish'
331
+ verify_recognize'path/with/slashes',
332
+ :controller => 'content', :action => 'fish', :path_info => %w(path with slashes)
333
+ verify_generate('path/with/slashes', {},
334
+ {:controller => 'content', :action => 'fish', :path_info => 'path/with/slashes'},
335
+ {})
336
+ end
337
+ def test_path_collection_with_array
338
+ route '*path_info', :controller => 'content', :action => 'fish'
339
+ verify_recognize'path/with/slashes',
340
+ :controller => 'content', :action => 'fish', :path_info => %w(path with slashes)
341
+ verify_generate('path/with/slashes', {},
342
+ {:controller => 'content', :action => 'fish', :path_info => %w(path with slashes)},
343
+ {})
344
+ end
345
+
346
+
328
347
 
329
348
  def test_special_characters
330
349
  route ':id', :controller => 'content', :action => 'fish'
@@ -337,6 +356,13 @@ class RouteTests < Test::Unit::TestCase
337
356
  verify_generate('id%2Fwith%2Fslashes', {},
338
357
  {:controller => 'content', :action => 'fish', :id => 'id/with/slashes'}, {})
339
358
  end
359
+
360
+ def test_generate_with_numeric_param
361
+ o = Object.new
362
+ def o.to_param() 10 end
363
+ verify_generate('content/action/10', {}, {:controller => 'content', :action => 'action', :id => o}, @defaults)
364
+ verify_generate('content/show/10', {}, {:controller => 'content', :action => 'show', :id => o}, @defaults)
365
+ end
340
366
  end
341
367
 
342
368
  class RouteSetTests < Test::Unit::TestCase
@@ -8,11 +8,19 @@ class AssetTagHelperTest < Test::Unit::TestCase
8
8
 
9
9
  def setup
10
10
  @controller = Class.new do
11
+
11
12
  def url_for(options, *parameters_for_method_reference)
12
13
  "http://www.example.com"
13
14
  end
14
- end
15
- @controller = @controller.new
15
+
16
+ end.new
17
+
18
+ @request = Class.new do
19
+ def relative_url_root
20
+ ""
21
+ end
22
+ end.new
23
+
16
24
  end
17
25
 
18
26
  AutoDiscoveryToTag = {
@@ -31,6 +39,74 @@ class AssetTagHelperTest < Test::Unit::TestCase
31
39
  %(stylesheet_link_tag("random.styles", "/css/stylish")) => %(<link href="/stylesheets/random.styles" media="screen" rel="Stylesheet" type="text/css" />\n<link href="/css/stylish.css" media="screen" rel="Stylesheet" type="text/css" />)
32
40
  }
33
41
 
42
+ ImageLinkToTag = {
43
+ %(image_tag("xml")) => %(<img alt="Xml" src="/images/xml.png" />),
44
+ %(image_tag("rss", :alt => "rss syndication")) => %(<img alt="rss syndication" src="/images/rss.png" />),
45
+ %(image_tag("gold", :size => "45x70")) => %(<img alt="Gold" height="70" src="/images/gold.png" width="45" />),
46
+ }
47
+
48
+ def test_auto_discovery
49
+ AutoDiscoveryToTag.each { |method, tag| assert_equal(tag, eval(method)) }
50
+ end
51
+
52
+ def test_javascript_include
53
+ JavascriptIncludeToTag.each { |method, tag| assert_equal(tag, eval(method)) }
54
+ end
55
+
56
+ def test_style_link
57
+ StyleLinkToTag.each { |method, tag| assert_equal(tag, eval(method)) }
58
+ end
59
+
60
+ def test_image_tag
61
+ ImageLinkToTag.each { |method, tag| assert_equal(tag, eval(method)) }
62
+ end
63
+
64
+ end
65
+
66
+ class AssetTagHelperNonVhostTest < Test::Unit::TestCase
67
+ include ActionView::Helpers::TagHelper
68
+ include ActionView::Helpers::UrlHelper
69
+ include ActionView::Helpers::AssetTagHelper
70
+
71
+ def setup
72
+ @controller = Class.new do
73
+
74
+ def url_for(options, *parameters_for_method_reference)
75
+ "http://www.example.com/calloboration/hieraki"
76
+ end
77
+
78
+ end.new
79
+
80
+ @request = Class.new do
81
+ def relative_url_root
82
+ "/calloboration/hieraki"
83
+ end
84
+ end.new
85
+
86
+ end
87
+
88
+ AutoDiscoveryToTag = {
89
+ %(auto_discovery_link_tag(:rss, :action => "feed")) => %(<link href="http://www.example.com/calloboration/hieraki" rel="alternate" title="RSS" type="application/rss+xml" />),
90
+ %(auto_discovery_link_tag(:atom)) => %(<link href="http://www.example.com/calloboration/hieraki" rel="alternate" title="ATOM" type="application/atom+xml" />),
91
+ %(auto_discovery_link_tag) => %(<link href="http://www.example.com/calloboration/hieraki" rel="alternate" title="RSS" type="application/rss+xml" />),
92
+ }
93
+
94
+ JavascriptIncludeToTag = {
95
+ %(javascript_include_tag("xmlhr")) => %(<script language="JavaScript" src="/calloboration/hieraki/javascripts/xmlhr.js" type="text/javascript"></script>),
96
+ %(javascript_include_tag("common.javascript", "/elsewhere/cools")) => %(<script language="JavaScript" src="/calloboration/hieraki/javascripts/common.javascript" type="text/javascript"></script>\n<script language="JavaScript" src="/calloboration/hieraki/elsewhere/cools.js" type="text/javascript"></script>),
97
+ }
98
+
99
+ StyleLinkToTag = {
100
+ %(stylesheet_link_tag("style")) => %(<link href="/calloboration/hieraki/stylesheets/style.css" media="screen" rel="Stylesheet" type="text/css" />),
101
+ %(stylesheet_link_tag("random.styles", "/css/stylish")) => %(<link href="/calloboration/hieraki/stylesheets/random.styles" media="screen" rel="Stylesheet" type="text/css" />\n<link href="/calloboration/hieraki/css/stylish.css" media="screen" rel="Stylesheet" type="text/css" />)
102
+ }
103
+
104
+ ImageLinkToTag = {
105
+ %(image_tag("xml")) => %(<img alt="Xml" src="/calloboration/hieraki/images/xml.png" />),
106
+ %(image_tag("rss", :alt => "rss syndication")) => %(<img alt="rss syndication" src="/calloboration/hieraki/images/rss.png" />),
107
+ %(image_tag("gold", :size => "45x70")) => %(<img alt="Gold" height="70" src="/calloboration/hieraki/images/gold.png" width="45" />),
108
+ }
109
+
34
110
  def test_auto_discovery
35
111
  AutoDiscoveryToTag.each { |method, tag| assert_equal(tag, eval(method)) }
36
112
  end
@@ -42,4 +118,13 @@ class AssetTagHelperTest < Test::Unit::TestCase
42
118
  def test_style_link
43
119
  StyleLinkToTag.each { |method, tag| assert_equal(tag, eval(method)) }
44
120
  end
121
+
122
+ def test_image_tag
123
+ assert_equal %(<img alt="Gold" height="70" src="/calloboration/hieraki/images/gold.png" width="45" />), image_tag("gold", :size => "45x70")
124
+ end
125
+
126
+ def test_image_tag
127
+ ImageLinkToTag.each { |method, tag| assert_equal(tag, eval(method)) }
128
+ end
129
+
45
130
  end
@@ -19,6 +19,7 @@ class FormHelperTest < Test::Unit::TestCase
19
19
  def @post.errors() Class.new{ def on(field) field == "author_name" end }.new end
20
20
 
21
21
  def @post.id; 123; end
22
+ def @post.id_before_type_cast; 123; end
22
23
 
23
24
  @post.title = "Hello World"
24
25
  @post.author_name = ""
@@ -94,6 +94,17 @@ class FormOptionsHelperTest < Test::Unit::TestCase
94
94
  )
95
95
  end
96
96
 
97
+ def test_array_options_for_string_include_in_other_string_bug_fix
98
+ assert_equal(
99
+ "<option>ruby</option>\n<option selected=\"selected\">rubyonrails</option>",
100
+ options_for_select([ "ruby", "rubyonrails" ], "rubyonrails")
101
+ )
102
+ assert_equal(
103
+ "<option selected=\"selected\">ruby</option>\n<option>rubyonrails</option>",
104
+ options_for_select([ "ruby", "rubyonrails" ], "ruby")
105
+ )
106
+ end
107
+
97
108
  def test_hash_options_for_select
98
109
  assert_equal(
99
110
  "<option value=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option>\n<option value=\"Dollar\">$</option>",
@@ -1,23 +1,91 @@
1
- require 'test/unit'
2
- require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_tag_helper'
1
+ require File.dirname(__FILE__) + '/../abstract_unit'
3
2
 
4
3
  class FormTagHelperTest < Test::Unit::TestCase
4
+
5
+ include ActionView::Helpers::UrlHelper
5
6
  include ActionView::Helpers::TagHelper
6
7
  include ActionView::Helpers::FormTagHelper
7
8
 
8
- MethodToTag = {
9
- %(text_field_tag("title", "Hello!")) => %(<input id="title" name="title" type="text" value="Hello!" />),
10
- %(text_field_tag("title", "Hello!", "class" => "admin")) => %(<input class="admin" id="title" name="title" type="text" value="Hello!" />),
11
- %(hidden_field_tag "id", 3) => %(<input id="id" name="id" type="hidden" value="3" />),
12
- %(password_field_tag) => %(<input id="password" name="password" type="password" value="" />),
13
- %(text_area_tag("body", "hello world", :size => "20x40")) => %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>),
14
- %(text_area_tag("body", "hello world", "size" => "20x40")) => %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>),
15
- %(check_box_tag("admin")) => %(<input id="admin" name="admin" type="checkbox" value="1" />),
16
- %(radio_button_tag("people", "david")) => %(<input id="people" name="people" type="radio" value="david" />),
17
- %(select_tag("people", "<option>david</option>")) => %(<select id="people" name="people"><option>david</option></select>),
18
- }
19
-
20
- def test_tags
21
- MethodToTag.each { |method, tag| assert_equal(tag, eval(method)) }
9
+ def setup
10
+ @controller = Class.new do
11
+ def url_for(options, *parameters_for_method_reference)
12
+ "http://www.example.com"
13
+ end
14
+ end
15
+ @controller = @controller.new
16
+ end
17
+
18
+ def test_check_box_tag
19
+ actual = check_box_tag "admin"
20
+ expected = %(<input id="admin" name="admin" type="checkbox" value="1" />)
21
+ assert_equal expected, actual
22
+ end
23
+
24
+ def test_form_tag
25
+ actual = form_tag
26
+ expected = %(<form action="http://www.example.com" method="post">)
27
+ assert_equal expected, actual
28
+ end
29
+
30
+ def test_form_tag_multipart
31
+ actual = form_tag({}, { 'multipart' => true })
32
+ expected = %(<form action="http://www.example.com" enctype="multipart/form-data" method="post">)
33
+ assert_equal expected, actual
34
+ end
35
+
36
+ def test_hidden_field_tag
37
+ actual = hidden_field_tag "id", 3
38
+ expected = %(<input id="id" name="id" type="hidden" value="3" />)
39
+ assert_equal expected, actual
40
+ end
41
+
42
+ def test_password_field_tag
43
+ actual = password_field_tag
44
+ expected = %(<input id="password" name="password" type="password" value="" />)
45
+ assert_equal expected, actual
46
+ end
47
+
48
+ def test_radio_button_tag
49
+ actual = radio_button_tag "people", "david"
50
+ expected = %(<input id="people" name="people" type="radio" value="david" />)
51
+ assert_equal expected, actual
52
+ end
53
+
54
+ def test_select_tag
55
+ actual = select_tag "people", "<option>david</option>"
56
+ expected = %(<select id="people" name="people"><option>david</option></select>)
57
+ assert_equal expected, actual
58
+ end
59
+
60
+ def test_text_area_tag_size_string
61
+ actual = text_area_tag "body", "hello world", "size" => "20x40"
62
+ expected = %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>)
63
+ assert_equal expected, actual
64
+ end
65
+
66
+ def test_text_area_tag_size_symbol
67
+ actual = text_area_tag "body", "hello world", :size => "20x40"
68
+ expected = %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>)
69
+ assert_equal expected, actual
70
+ end
71
+
72
+ def test_text_field_tag
73
+ actual = text_field_tag "title", "Hello!"
74
+ expected = %(<input id="title" name="title" type="text" value="Hello!" />)
75
+ assert_equal expected, actual
76
+ end
77
+
78
+ def test_text_field_tag_class_string
79
+ actual = text_field_tag "title", "Hello!", "class" => "admin"
80
+ expected = %(<input class="admin" id="title" name="title" type="text" value="Hello!" />)
81
+ assert_equal expected, actual
82
+ end
83
+
84
+ def test_boolean_optios
85
+ assert_equal %(<input checked="checked" disabled="disabled" id="admin" name="admin" readonly="readonly" type="checkbox" value="1" />), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes")
86
+ assert_equal %(<input checked="checked" id="admin" name="admin" type="checkbox" value="1" />), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil)
87
+ assert_equal %(<select id="people" multiple="multiple" name="people"><option>david</option></select>), select_tag("people", "<option>david</option>", :multiple => true)
88
+ assert_equal %(<select id="people" name="people"><option>david</option></select>), select_tag("people", "<option>david</option>", :multiple => nil)
22
89
  end
23
90
  end
91
+