actionpack 1.5.0 → 1.5.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.
- data/CHANGELOG +35 -0
- data/lib/action_controller.rb +4 -7
- data/lib/action_controller/base.rb +0 -3
- data/lib/action_controller/caching.rb +3 -1
- data/lib/action_controller/cgi_process.rb +13 -8
- data/lib/action_controller/components.rb +3 -3
- data/lib/action_controller/request.rb +5 -1
- data/lib/action_controller/routing.rb +4 -4
- data/lib/action_controller/session/active_record_store.rb +23 -10
- data/lib/action_view/helpers/active_record_helper.rb +15 -13
- data/lib/action_view/helpers/asset_tag_helper.rb +6 -6
- data/lib/action_view/helpers/date_helper.rb +26 -30
- data/lib/action_view/helpers/form_helper.rb +82 -54
- data/lib/action_view/helpers/form_options_helper.rb +27 -23
- data/lib/action_view/helpers/form_tag_helper.rb +18 -18
- data/lib/action_view/helpers/tag_helper.rb +4 -4
- data/lib/action_view/helpers/text_helper.rb +11 -11
- data/lib/action_view/helpers/url_helper.rb +48 -33
- data/rakefile +2 -2
- data/test/controller/request_test.rb +12 -1
- data/test/controller/routing_tests.rb +24 -0
- data/test/template/active_record_helper_test.rb +1 -1
- data/test/template/asset_tag_helper_test.rb +4 -4
- data/test/template/form_helper_test.rb +32 -25
- data/test/template/form_options_helper_test.rb +14 -10
- data/test/template/form_tag_helper_test.rb +3 -2
- data/test/template/tag_helper_test.rb +8 -5
- data/test/template/text_helper_test.rb +7 -7
- data/test/template/url_helper_test.rb +51 -18
- metadata +4 -5
- data/test/template/url_helper_test.rb.rej +0 -105
@@ -7,14 +7,14 @@ module ActionView
|
|
7
7
|
module TagHelper
|
8
8
|
include ERB::Util
|
9
9
|
|
10
|
-
# Examples:
|
10
|
+
# Examples:
|
11
11
|
# * <tt>tag("br") => <br /></tt>
|
12
12
|
# * <tt>tag("input", { "type" => "text"}) => <input type="text" /></tt>
|
13
13
|
def tag(name, options = {}, open = false)
|
14
14
|
"<#{name}#{tag_options(options)}" + (open ? ">" : " />")
|
15
15
|
end
|
16
|
-
|
17
|
-
# Examples:
|
16
|
+
|
17
|
+
# Examples:
|
18
18
|
# * <tt>content_tag("p", "Hello world!") => <p>Hello world!</p></tt>
|
19
19
|
# * <tt>content_tag("div", content_tag("p", "Hello world!"), "class" => "strong") => </tt>
|
20
20
|
# <tt><div class="strong"><p>Hello world!</p></div></tt>
|
@@ -26,7 +26,7 @@ module ActionView
|
|
26
26
|
def tag_options(options)
|
27
27
|
unless options.empty?
|
28
28
|
" " + options.map { |key, value|
|
29
|
-
%(#{key}="#{html_escape(value)}")
|
29
|
+
%(#{key}="#{html_escape(value.to_s)}")
|
30
30
|
}.sort.join(" ")
|
31
31
|
end
|
32
32
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ActionView
|
2
2
|
module Helpers #:nodoc:
|
3
3
|
# Provides a set of methods for working with text strings that can help unburden the level of inline Ruby code in the
|
4
|
-
# templates. In the example below we iterate over a collection of posts provided to the template and prints each title
|
4
|
+
# templates. In the example below we iterate over a collection of posts provided to the template and prints each title
|
5
5
|
# after making sure it doesn't run longer than 20 characters:
|
6
6
|
# <% for post in @posts %>
|
7
7
|
# Title: <%= truncate(post.title, 20) %>
|
@@ -29,14 +29,14 @@ module ActionView
|
|
29
29
|
if text.nil? || phrase.nil? then return end
|
30
30
|
text.gsub(/(#{escape_regexp(phrase)})/i, highlighter) unless text.nil?
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
# Extracts an excerpt from the +text+ surrounding the +phrase+ with a number of characters on each side determined
|
34
|
-
# by +radius+. If the phrase isn't found, nil is returned. Ex:
|
34
|
+
# by +radius+. If the phrase isn't found, nil is returned. Ex:
|
35
35
|
# excerpt("hello my world", "my", 3) => "...lo my wo..."
|
36
36
|
def excerpt(text, phrase, radius = 100, excerpt_string = "...")
|
37
37
|
if text.nil? || phrase.nil? then return end
|
38
38
|
phrase = escape_regexp(phrase)
|
39
|
-
|
39
|
+
|
40
40
|
if found_pos = text =~ /(#{phrase})/i
|
41
41
|
start_pos = [ found_pos - radius, 0 ].max
|
42
42
|
end_pos = [ found_pos + phrase.length + radius, text.length ].min
|
@@ -58,7 +58,7 @@ module ActionView
|
|
58
58
|
plural
|
59
59
|
elsif Object.const_defined?("Inflector")
|
60
60
|
Inflector.pluralize(singular)
|
61
|
-
else
|
61
|
+
else
|
62
62
|
singular + "s"
|
63
63
|
end
|
64
64
|
end
|
@@ -66,13 +66,13 @@ module ActionView
|
|
66
66
|
begin
|
67
67
|
require "redcloth"
|
68
68
|
|
69
|
-
# Returns the text with all the Textile codes turned into HTML-tags.
|
69
|
+
# Returns the text with all the Textile codes turned into HTML-tags.
|
70
70
|
# <i>This method is only available if RedCloth can be required</i>.
|
71
71
|
def textilize(text)
|
72
72
|
text.empty? ? "" : RedCloth.new(text, [ :hard_breaks ]).to_html
|
73
73
|
end
|
74
74
|
|
75
|
-
# Returns the text with all the Textile codes turned into HTML-tags, but without the regular bounding <p> tag.
|
75
|
+
# Returns the text with all the Textile codes turned into HTML-tags, but without the regular bounding <p> tag.
|
76
76
|
# <i>This method is only available if RedCloth can be required</i>.
|
77
77
|
def textilize_without_paragraph(text)
|
78
78
|
textiled = textilize(text)
|
@@ -87,7 +87,7 @@ module ActionView
|
|
87
87
|
begin
|
88
88
|
require "bluecloth"
|
89
89
|
|
90
|
-
# Returns the text with all the Markdown codes turned into HTML-tags.
|
90
|
+
# Returns the text with all the Markdown codes turned into HTML-tags.
|
91
91
|
# <i>This method is only available if BlueCloth can be required</i>.
|
92
92
|
def markdown(text)
|
93
93
|
text.empty? ? "" : BlueCloth.new(text).to_html
|
@@ -101,7 +101,7 @@ module ActionView
|
|
101
101
|
#
|
102
102
|
# Example:
|
103
103
|
# auto_link("Go to http://www.rubyonrails.com and say hello to david@loudthinking.com") =>
|
104
|
-
# Go to <a href="http://www.rubyonrails.com">http://www.rubyonrails.com</a> and
|
104
|
+
# Go to <a href="http://www.rubyonrails.com">http://www.rubyonrails.com</a> and
|
105
105
|
# say hello to <a href="mailto:david@loudthinking.com">david@loudthinking.com</a>
|
106
106
|
def auto_link(text, link = :all)
|
107
107
|
case link
|
@@ -115,7 +115,7 @@ module ActionView
|
|
115
115
|
def strip_links(text)
|
116
116
|
text.gsub(/<a.*>(.*)<\/a>/m, '\1')
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
private
|
120
120
|
# Returns a version of the text that's safe to use in a regular expression without triggering engine features.
|
121
121
|
def escape_regexp(text)
|
@@ -133,4 +133,4 @@ module ActionView
|
|
133
133
|
end
|
134
134
|
end
|
135
135
|
end
|
136
|
-
end
|
136
|
+
end
|
@@ -5,43 +5,46 @@ module ActionView
|
|
5
5
|
# synchronously, so link_to uses that same url as is generated by url_for, which again is the same url used for
|
6
6
|
# redirection in redirect_to.
|
7
7
|
module UrlHelper
|
8
|
-
# Returns the URL for the set of +options+ provided.
|
8
|
+
# Returns the URL for the set of +options+ provided. This takes the same options
|
9
|
+
# as url_for. For a list, see the url_for documentation in link:classes/ActionController/Base.html#M000079.
|
9
10
|
def url_for(options = {}, *parameters_for_method_reference)
|
10
|
-
if Hash === options then options = { :only_path => true }.
|
11
|
+
if Hash === options then options = { :only_path => true }.update(options.stringify_keys) end
|
11
12
|
@controller.send(:url_for, options, *parameters_for_method_reference)
|
12
13
|
end
|
13
14
|
|
14
15
|
# Creates a link tag of the given +name+ using an URL created by the set of +options+. See the valid options in
|
15
16
|
# link:classes/ActionController/Base.html#M000021. It's also possible to pass a string instead of an options hash to
|
16
|
-
# get a link tag that just points without consideration. If nil is passed as a name, the link itself will become the name.
|
17
|
-
# The html_options have a special feature for creating javascript confirm alerts where if you pass :confirm => 'Are you sure?',
|
17
|
+
# get a link tag that just points without consideration. If nil is passed as a name, the link itself will become the name.
|
18
|
+
# The html_options have a special feature for creating javascript confirm alerts where if you pass :confirm => 'Are you sure?',
|
18
19
|
# the link will be guarded with a JS popup asking that question. If the user accepts, the link is processed, otherwise not.
|
19
20
|
#
|
20
21
|
# Example:
|
21
22
|
# link_to "Delete this page", { :action => "destroy", :id => @page.id }, :confirm => "Are you sure?"
|
22
|
-
def link_to(name, options = {}, html_options =
|
23
|
-
|
23
|
+
def link_to(name, options = {}, html_options = nil, *parameters_for_method_reference)
|
24
|
+
html_options = (html_options || {}).stringify_keys
|
25
|
+
convert_confirm_option_to_javascript!(html_options)
|
24
26
|
if options.is_a?(String)
|
25
|
-
content_tag "a", name || options, (html_options || {}).merge(
|
27
|
+
content_tag "a", name || options, (html_options || {}).merge("href" => options)
|
26
28
|
else
|
27
29
|
content_tag(
|
28
|
-
"a", name || url_for(options, *parameters_for_method_reference),
|
29
|
-
(html_options || {}).merge(
|
30
|
+
"a", name || url_for(options, *parameters_for_method_reference),
|
31
|
+
(html_options || {}).merge("href" => url_for(options, *parameters_for_method_reference))
|
30
32
|
)
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
|
-
# Creates a link tag on the image residing at the +src+ using an URL created by the set of +options+.
|
35
|
-
# link:classes/ActionController/Base.html#
|
36
|
-
# get a link tag that just points without consideration.
|
37
|
-
#
|
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:
|
38
41
|
#
|
39
42
|
# * <tt>:alt</tt> - If no alt text is given, the file name part of the +src+ is used (capitalized and without the extension)
|
40
43
|
# * <tt>:size</tt> - Supplied as "XxY", so "30x45" becomes width="30" and height="45"
|
41
|
-
# * <tt>:border</tt> -
|
44
|
+
# * <tt>:border</tt> - Draws a border around the link
|
42
45
|
# * <tt>:align</tt> - Sets the alignment, no special features
|
43
46
|
#
|
44
|
-
# The +src+ can be supplied as a...
|
47
|
+
# The +src+ can be supplied as a...
|
45
48
|
# * full path, like "/my_images/image.gif"
|
46
49
|
# * file name, like "rss.gif", that gets expanded to "/images/rss.gif"
|
47
50
|
# * file name without extension, like "logo", that gets expanded to "/images/logo.png"
|
@@ -51,8 +54,9 @@ module ActionView
|
|
51
54
|
# link_image_to "delete", { :action => "destroy" }, :size => "10x10", :confirm => "Are you sure?", "class" => "admin"
|
52
55
|
def link_image_to(src, options = {}, html_options = {}, *parameters_for_method_reference)
|
53
56
|
image_options = { "src" => src.include?("/") ? src : "/images/#{src}" }
|
54
|
-
image_options["src"]
|
55
|
-
|
57
|
+
image_options["src"] += ".png" unless image_options["src"].include?(".")
|
58
|
+
|
59
|
+
html_options = html_options.stringify_keys
|
56
60
|
if html_options["alt"]
|
57
61
|
image_options["alt"] = html_options["alt"]
|
58
62
|
html_options.delete "alt"
|
@@ -68,10 +72,8 @@ module ActionView
|
|
68
72
|
if html_options["border"]
|
69
73
|
image_options["border"] = html_options["border"]
|
70
74
|
html_options.delete "border"
|
71
|
-
else
|
72
|
-
image_options["border"] = "0"
|
73
75
|
end
|
74
|
-
|
76
|
+
|
75
77
|
if html_options["align"]
|
76
78
|
image_options["align"] = html_options["align"]
|
77
79
|
html_options.delete "align"
|
@@ -82,18 +84,32 @@ module ActionView
|
|
82
84
|
|
83
85
|
alias_method :link_to_image, :link_image_to # deprecated name
|
84
86
|
|
85
|
-
# Creates a link tag of the given +name+ using an URL created by the set of +options+, unless the current
|
87
|
+
# Creates a link tag of the given +name+ using an URL created by the set of +options+, unless the current
|
86
88
|
# request uri is the same as the link's, in which case only the name is returned (or the
|
87
|
-
# given block is yielded, if one exists). This is useful for creating link bars where you don't want to link
|
89
|
+
# given block is yielded, if one exists). This is useful for creating link bars where you don't want to link
|
88
90
|
# to the page currently being viewed.
|
89
|
-
def link_to_unless_current(name, options = {}, html_options = {}, *parameters_for_method_reference)
|
90
|
-
|
91
|
-
|
92
|
-
|
91
|
+
def link_to_unless_current(name, options = {}, html_options = {}, *parameters_for_method_reference, &block)
|
92
|
+
link_to_unless current_page?(options), name, options, html_options, *parameters_for_method_reference, &block
|
93
|
+
end
|
94
|
+
|
95
|
+
# Create a link tag of the given +name+ using an URL created by the set of +options+, unless +condition+
|
96
|
+
# is true, in which case only the name is returned (or the given block is yielded, if one exists).
|
97
|
+
def link_to_unless(condition, name, options = {}, html_options = {}, *parameters_for_method_reference, &block)
|
98
|
+
if condition
|
99
|
+
if block_given?
|
100
|
+
block.arity <= 1 ? yield(name) : yield(name, options, html_options, *parameters_for_method_reference)
|
101
|
+
else
|
93
102
|
html_escape(name)
|
103
|
+
end
|
94
104
|
else
|
95
105
|
link_to(name, options, html_options, *parameters_for_method_reference)
|
96
|
-
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Create a link tag of the given +name+ using an URL created by the set of +options+, if +condition+
|
110
|
+
# is true, in which case only the name is returned (or the given block is yielded, if one exists).
|
111
|
+
def link_to_if(condition, name, options = {}, html_options = {}, *parameters_for_method_reference, &block)
|
112
|
+
link_to_unless !condition, name, options, html_options, *parameters_for_method_reference, &block
|
97
113
|
end
|
98
114
|
|
99
115
|
# Creates a link tag for starting an email to the specified <tt>email_address</tt>, which is also used as the name of the
|
@@ -107,8 +123,8 @@ module ActionView
|
|
107
123
|
# mail_to "me@domain.com", "My email", :encode => "hex" # =>
|
108
124
|
# <a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>
|
109
125
|
def mail_to(email_address, name = nil, html_options = {})
|
110
|
-
|
111
|
-
html_options.delete(
|
126
|
+
html_options = html_options.stringify_keys
|
127
|
+
encode = html_options.delete("encode")
|
112
128
|
string = ''
|
113
129
|
if encode == 'javascript'
|
114
130
|
tmp = "document.write('#{content_tag("a", name || email_address, html_options.merge({ "href" => "mailto:"+email_address.to_s }))}');"
|
@@ -137,11 +153,10 @@ module ActionView
|
|
137
153
|
|
138
154
|
private
|
139
155
|
def convert_confirm_option_to_javascript!(html_options)
|
140
|
-
if html_options.
|
141
|
-
html_options["onclick"] = "return confirm('#{
|
142
|
-
html_options.delete(:confirm)
|
156
|
+
if confirm = html_options.delete("confirm")
|
157
|
+
html_options["onclick"] = "return confirm('#{confirm.gsub(/'/, '\\\\\'')}');"
|
143
158
|
end
|
144
159
|
end
|
145
160
|
end
|
146
161
|
end
|
147
|
-
end
|
162
|
+
end
|
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.
|
11
|
+
PKG_VERSION = '1.5.1' + 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.
|
60
|
+
s.add_dependency('activesupport', '= 1.0.1' + PKG_BUILD)
|
61
61
|
|
62
62
|
s.require_path = 'lib'
|
63
63
|
s.autorequire = 'action_controller'
|
@@ -54,6 +54,17 @@ class RequestTest < Test::Unit::TestCase
|
|
54
54
|
assert_equal "/", @request.path
|
55
55
|
end
|
56
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
|
+
|
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
|
66
|
+
end
|
67
|
+
|
57
68
|
def test_host_with_port
|
58
69
|
@request.env['HTTP_HOST'] = "rubyonrails.org:8080"
|
59
70
|
assert_equal "rubyonrails.org:8080", @request.host_with_port
|
@@ -67,4 +78,4 @@ class RequestTest < Test::Unit::TestCase
|
|
67
78
|
@request.port = 81
|
68
79
|
assert_equal "rubyonrails.org:81", @request.host_with_port
|
69
80
|
end
|
70
|
-
end
|
81
|
+
end
|
@@ -479,6 +479,30 @@ class RouteSetTests < Test::Unit::TestCase
|
|
479
479
|
@request.path_parameters = {:controller => 'admin/users', :action => 'index'}
|
480
480
|
verify_generate 'admin/users', {}
|
481
481
|
end
|
482
|
+
|
483
|
+
def test_url_with_spaces_in_controller
|
484
|
+
@request.path = 'not%20a%20valid/controller/name'
|
485
|
+
@set.add_route(@rails_route) if @set.empty?
|
486
|
+
assert_raises(ActionController::RoutingError) {@set.recognize!(@request)}
|
487
|
+
end
|
488
|
+
def test_url_with_dots_in_controller
|
489
|
+
@request.path = 'not.valid/controller/name'
|
490
|
+
@set.add_route(@rails_route) if @set.empty?
|
491
|
+
assert_raises(ActionController::RoutingError) {@set.recognize!(@request)}
|
492
|
+
end
|
493
|
+
|
494
|
+
def test_generate_of_empty_url
|
495
|
+
@set.connect '', :controller => 'content', :action => 'view', :id => "1"
|
496
|
+
@set.add_route(@rails_route)
|
497
|
+
verify_generate('content/view/2', {:controller => 'content', :action => 'view', :id => 2})
|
498
|
+
verify_generate('', {:controller => 'content', :action => 'view', :id => 1})
|
499
|
+
end
|
500
|
+
def test_generate_of_empty_url_with_numeric_requirement
|
501
|
+
@set.connect '', :controller => 'content', :action => 'view', :id => 1
|
502
|
+
@set.add_route(@rails_route)
|
503
|
+
verify_generate('content/view/2', {:controller => 'content', :action => 'view', :id => 2})
|
504
|
+
verify_generate('', {:controller => 'content', :action => 'view', :id => 1})
|
505
|
+
end
|
482
506
|
end
|
483
507
|
|
484
508
|
#require '../assertions/action_pack_assertions.rb'
|
@@ -9,16 +9,16 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
9
9
|
def setup
|
10
10
|
@controller = Class.new do
|
11
11
|
def url_for(options, *parameters_for_method_reference)
|
12
|
-
"http://www.
|
12
|
+
"http://www.example.com"
|
13
13
|
end
|
14
14
|
end
|
15
15
|
@controller = @controller.new
|
16
16
|
end
|
17
17
|
|
18
18
|
AutoDiscoveryToTag = {
|
19
|
-
%(auto_discovery_link_tag) => %(<link href="http://www.
|
20
|
-
%(auto_discovery_link_tag(:atom)) => %(<link href="http://www.
|
21
|
-
%(auto_discovery_link_tag(:rss, :action => "feed")) => %(<link href="http://www.
|
19
|
+
%(auto_discovery_link_tag) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
|
20
|
+
%(auto_discovery_link_tag(:atom)) => %(<link href="http://www.example.com" rel="alternate" title="ATOM" type="application/atom+xml" />),
|
21
|
+
%(auto_discovery_link_tag(:rss, :action => "feed")) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
|
22
22
|
}
|
23
23
|
|
24
24
|
JavascriptIncludeToTag = {
|
@@ -15,7 +15,7 @@ class FormHelperTest < Test::Unit::TestCase
|
|
15
15
|
$VERBOSE = old_verbose
|
16
16
|
|
17
17
|
def setup
|
18
|
-
@post = Post.new
|
18
|
+
@post = Post.new
|
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
|
@@ -47,31 +47,29 @@ class FormHelperTest < Test::Unit::TestCase
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def test_text_field_with_options
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
)
|
50
|
+
expected = '<input id="post_title" name="post[title]" size="35" type="text" value="Hello World" />'
|
51
|
+
assert_equal expected, text_field("post", "title", "size" => 35)
|
52
|
+
assert_equal expected, text_field("post", "title", :size => 35)
|
54
53
|
end
|
55
|
-
|
54
|
+
|
56
55
|
def test_text_field_assuming_size
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
)
|
56
|
+
expected = '<input id="post_title" maxlength="35" name="post[title]" size="35" type="text" value="Hello World" />'
|
57
|
+
assert_equal expected, text_field("post", "title", "maxlength" => 35)
|
58
|
+
assert_equal expected, text_field("post", "title", :maxlength => 35)
|
61
59
|
end
|
62
|
-
|
60
|
+
|
63
61
|
def test_check_box
|
64
62
|
assert_equal(
|
65
63
|
'<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
|
66
64
|
check_box("post", "secret")
|
67
65
|
)
|
68
|
-
|
66
|
+
|
69
67
|
@post.secret = 0
|
70
68
|
assert_equal(
|
71
69
|
'<input id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
|
72
|
-
check_box("post", "secret")
|
70
|
+
check_box("post", "secret")
|
73
71
|
)
|
74
|
-
|
72
|
+
|
75
73
|
@post.secret = true
|
76
74
|
assert_equal(
|
77
75
|
'<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
|
@@ -81,20 +79,20 @@ class FormHelperTest < Test::Unit::TestCase
|
|
81
79
|
|
82
80
|
def test_radio_button
|
83
81
|
assert_equal('<input checked="checked" id="post_title" name="post[title]" size="30" type="radio" value="Hello World" />',
|
84
|
-
radio_button("post", "title", "Hello World")
|
82
|
+
radio_button("post", "title", "Hello World")
|
85
83
|
)
|
86
84
|
assert_equal('<input id="post_title" name="post[title]" size="30" type="radio" value="Goodbye World" />',
|
87
|
-
radio_button("post", "title", "Goodbye World")
|
85
|
+
radio_button("post", "title", "Goodbye World")
|
88
86
|
)
|
89
87
|
end
|
90
|
-
|
88
|
+
|
91
89
|
def test_text_area
|
92
90
|
assert_equal(
|
93
91
|
'<textarea cols="40" id="post_body" name="post[body]" rows="20" wrap="virtual">Back to the hill and over it again!</textarea>',
|
94
92
|
text_area("post", "body")
|
95
93
|
)
|
96
94
|
end
|
97
|
-
|
95
|
+
|
98
96
|
def test_text_area_with_escapes
|
99
97
|
@post.body = "Back to <i>the</i> hill and over it again!"
|
100
98
|
assert_equal(
|
@@ -109,12 +107,11 @@ class FormHelperTest < Test::Unit::TestCase
|
|
109
107
|
text_area("post", "body")
|
110
108
|
)
|
111
109
|
end
|
112
|
-
|
113
|
-
|
110
|
+
|
114
111
|
def test_explicit_name
|
115
112
|
assert_equal(
|
116
113
|
'<input id="post_title" name="dont guess" size="30" type="text" value="Hello World" />', text_field("post", "title", "name" => "dont guess")
|
117
|
-
)
|
114
|
+
)
|
118
115
|
assert_equal(
|
119
116
|
'<textarea cols="40" id="post_body" name="really!" rows="20" wrap="virtual">Back to the hill and over it again!</textarea>',
|
120
117
|
text_area("post", "body", "name" => "really!")
|
@@ -123,12 +120,18 @@ class FormHelperTest < Test::Unit::TestCase
|
|
123
120
|
'<input checked="checked" id="post_secret" name="i mean it" type="checkbox" value="1" /><input name="i mean it" type="hidden" value="0" />',
|
124
121
|
check_box("post", "secret", "name" => "i mean it")
|
125
122
|
)
|
123
|
+
assert_equal text_field("post", "title", "name" => "dont guess"),
|
124
|
+
text_field("post", "title", :name => "dont guess")
|
125
|
+
assert_equal text_area("post", "body", "name" => "really!"),
|
126
|
+
text_area("post", "body", :name => "really!")
|
127
|
+
assert_equal check_box("post", "secret", "name" => "i mean it"),
|
128
|
+
check_box("post", "secret", :name => "i mean it")
|
126
129
|
end
|
127
|
-
|
130
|
+
|
128
131
|
def test_explicit_id
|
129
132
|
assert_equal(
|
130
133
|
'<input id="dont guess" name="post[title]" size="30" type="text" value="Hello World" />', text_field("post", "title", "id" => "dont guess")
|
131
|
-
)
|
134
|
+
)
|
132
135
|
assert_equal(
|
133
136
|
'<textarea cols="40" id="really!" name="post[body]" rows="20" wrap="virtual">Back to the hill and over it again!</textarea>',
|
134
137
|
text_area("post", "body", "id" => "really!")
|
@@ -137,6 +140,12 @@ class FormHelperTest < Test::Unit::TestCase
|
|
137
140
|
'<input checked="checked" id="i mean it" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
|
138
141
|
check_box("post", "secret", "id" => "i mean it")
|
139
142
|
)
|
143
|
+
assert_equal text_field("post", "title", "id" => "dont guess"),
|
144
|
+
text_field("post", "title", :id => "dont guess")
|
145
|
+
assert_equal text_area("post", "body", "id" => "really!"),
|
146
|
+
text_area("post", "body", :id => "really!")
|
147
|
+
assert_equal check_box("post", "secret", "id" => "i mean it"),
|
148
|
+
check_box("post", "secret", :id => "i mean it")
|
140
149
|
end
|
141
150
|
|
142
151
|
def test_auto_index
|
@@ -159,7 +168,5 @@ class FormHelperTest < Test::Unit::TestCase
|
|
159
168
|
assert_equal("<input id=\"post_#{pid}_title\" name=\"post[#{pid}][title]\" size=\"30\" type=\"radio\" value=\"Goodbye World\" />",
|
160
169
|
radio_button("post[]", "title", "Goodbye World")
|
161
170
|
)
|
162
|
-
|
163
171
|
end
|
164
|
-
|
165
172
|
end
|