aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/template')
-rw-r--r--actionpack/test/template/active_record_helper_test.rb2
-rw-r--r--actionpack/test/template/form_helper_test.rb57
-rw-r--r--actionpack/test/template/form_options_helper_test.rb24
-rw-r--r--actionpack/test/template/form_tag_helper_test.rb5
-rw-r--r--actionpack/test/template/tag_helper_test.rb13
-rw-r--r--actionpack/test/template/text_helper_test.rb14
-rw-r--r--actionpack/test/template/url_helper_test.rb23
7 files changed, 80 insertions, 58 deletions
diff --git a/actionpack/test/template/active_record_helper_test.rb b/actionpack/test/template/active_record_helper_test.rb
index e650b4f0b8..67001082b8 100644
--- a/actionpack/test/template/active_record_helper_test.rb
+++ b/actionpack/test/template/active_record_helper_test.rb
@@ -48,7 +48,7 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
@controller = Class.new do
def url_for(options, *parameters_for_method_reference)
- options[:action]
+ options[:action] || options["action"]
end
end
@controller = @controller.new
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 6b1deb575e..7f7f473564 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -15,7 +15,7 @@ class FormHelperTest < Test::Unit::TestCase
$VERBOSE = old_verbose
def setup
- @post = Post.new
+ @post = Post.new
def @post.errors() Class.new{ def on(field) field == "author_name" end }.new end
def @post.id; 123; end
@@ -47,31 +47,29 @@ class FormHelperTest < Test::Unit::TestCase
end
def test_text_field_with_options
- assert_equal(
- '<input id="post_title" name="post[title]" size="35" type="text" value="Hello World" />',
- text_field("post", "title", "size" => "35")
- )
+ expected = '<input id="post_title" name="post[title]" size="35" type="text" value="Hello World" />'
+ assert_equal expected, text_field("post", "title", "size" => 35)
+ assert_equal expected, text_field("post", "title", :size => 35)
end
-
+
def test_text_field_assuming_size
- assert_equal(
- '<input id="post_title" maxlength="35" name="post[title]" size="35" type="text" value="Hello World" />',
- text_field("post", "title", "maxlength" => 35)
- )
+ expected = '<input id="post_title" maxlength="35" name="post[title]" size="35" type="text" value="Hello World" />'
+ assert_equal expected, text_field("post", "title", "maxlength" => 35)
+ assert_equal expected, text_field("post", "title", :maxlength => 35)
end
-
+
def test_check_box
assert_equal(
'<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
check_box("post", "secret")
)
-
+
@post.secret = 0
assert_equal(
'<input id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
- check_box("post", "secret")
+ check_box("post", "secret")
)
-
+
@post.secret = true
assert_equal(
'<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
def test_radio_button
assert_equal('<input checked="checked" id="post_title" name="post[title]" size="30" type="radio" value="Hello World" />',
- radio_button("post", "title", "Hello World")
+ radio_button("post", "title", "Hello World")
)
assert_equal('<input id="post_title" name="post[title]" size="30" type="radio" value="Goodbye World" />',
- radio_button("post", "title", "Goodbye World")
+ radio_button("post", "title", "Goodbye World")
)
end
-
+
def test_text_area
assert_equal(
'<textarea cols="40" id="post_body" name="post[body]" rows="20" wrap="virtual">Back to the hill and over it again!</textarea>',
text_area("post", "body")
)
end
-
+
def test_text_area_with_escapes
@post.body = "Back to <i>the</i> hill and over it again!"
assert_equal(
@@ -109,12 +107,11 @@ class FormHelperTest < Test::Unit::TestCase
text_area("post", "body")
)
end
-
-
+
def test_explicit_name
assert_equal(
'<input id="post_title" name="dont guess" size="30" type="text" value="Hello World" />', text_field("post", "title", "name" => "dont guess")
- )
+ )
assert_equal(
'<textarea cols="40" id="post_body" name="really!" rows="20" wrap="virtual">Back to the hill and over it again!</textarea>',
text_area("post", "body", "name" => "really!")
@@ -123,12 +120,18 @@ class FormHelperTest < Test::Unit::TestCase
'<input checked="checked" id="post_secret" name="i mean it" type="checkbox" value="1" /><input name="i mean it" type="hidden" value="0" />',
check_box("post", "secret", "name" => "i mean it")
)
+ assert_equal text_field("post", "title", "name" => "dont guess"),
+ text_field("post", "title", :name => "dont guess")
+ assert_equal text_area("post", "body", "name" => "really!"),
+ text_area("post", "body", :name => "really!")
+ assert_equal check_box("post", "secret", "name" => "i mean it"),
+ check_box("post", "secret", :name => "i mean it")
end
-
+
def test_explicit_id
assert_equal(
'<input id="dont guess" name="post[title]" size="30" type="text" value="Hello World" />', text_field("post", "title", "id" => "dont guess")
- )
+ )
assert_equal(
'<textarea cols="40" id="really!" name="post[body]" rows="20" wrap="virtual">Back to the hill and over it again!</textarea>',
text_area("post", "body", "id" => "really!")
@@ -137,6 +140,12 @@ class FormHelperTest < Test::Unit::TestCase
'<input checked="checked" id="i mean it" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
check_box("post", "secret", "id" => "i mean it")
)
+ assert_equal text_field("post", "title", "id" => "dont guess"),
+ text_field("post", "title", :id => "dont guess")
+ assert_equal text_area("post", "body", "id" => "really!"),
+ text_area("post", "body", :id => "really!")
+ assert_equal check_box("post", "secret", "id" => "i mean it"),
+ check_box("post", "secret", :id => "i mean it")
end
def test_auto_index
@@ -159,7 +168,5 @@ class FormHelperTest < Test::Unit::TestCase
assert_equal("<input id=\"post_#{pid}_title\" name=\"post[#{pid}][title]\" size=\"30\" type=\"radio\" value=\"Goodbye World\" />",
radio_button("post[]", "title", "Goodbye World")
)
-
end
-
end
diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb
index 4203ab7079..a94f81a728 100644
--- a/actionpack/test/template/form_options_helper_test.rb
+++ b/actionpack/test/template/form_options_helper_test.rb
@@ -46,7 +46,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase
)
end
-
+
def test_collection_options_with_preselected_value
@posts = [
Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"),
@@ -75,14 +75,14 @@ class FormOptionsHelperTest < Test::Unit::TestCase
def test_array_options_for_select
assert_equal(
- "<option>&lt;Denmark&gt;</option>\n<option>USA</option>\n<option>Sweden</option>",
+ "<option>&lt;Denmark&gt;</option>\n<option>USA</option>\n<option>Sweden</option>",
options_for_select([ "<Denmark>", "USA", "Sweden" ])
)
end
def test_array_options_for_select_with_selection
assert_equal(
- "<option>Denmark</option>\n<option selected=\"selected\">&lt;USA&gt;</option>\n<option>Sweden</option>",
+ "<option>Denmark</option>\n<option selected=\"selected\">&lt;USA&gt;</option>\n<option>Sweden</option>",
options_for_select([ "Denmark", "<USA>", "Sweden" ], "<USA>")
)
end
@@ -96,21 +96,21 @@ class FormOptionsHelperTest < Test::Unit::TestCase
def test_hash_options_for_select
assert_equal(
- "<option value=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option>\n<option value=\"Dollar\">$</option>",
+ "<option value=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option>\n<option value=\"Dollar\">$</option>",
options_for_select({ "$" => "Dollar", "<DKR>" => "<Kroner>" })
)
end
def test_hash_options_for_select_with_selection
assert_equal(
- "<option value=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
+ "<option value=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
options_for_select({ "$" => "Dollar", "<DKR>" => "<Kroner>" }, "Dollar")
)
end
def test_hash_options_for_select_with_selection
assert_equal(
- "<option value=\"&lt;Kroner&gt;\" selected=\"selected\">&lt;DKR&gt;</option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
+ "<option value=\"&lt;Kroner&gt;\" selected=\"selected\">&lt;DKR&gt;</option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
options_for_select({ "$" => "Dollar", "<DKR>" => "<Kroner>" }, [ "Dollar", "<Kroner>" ])
)
end
@@ -197,7 +197,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase
@post = Post.new
@post.category = "<mus>"
assert_equal(
- "<select id=\"post_category\" name=\"post[category]\"><option>abe</option>\n<option selected=\"selected\">&lt;mus&gt;</option>\n<option>hest</option></select>",
+ "<select id=\"post_category\" name=\"post[category]\"><option>abe</option>\n<option selected=\"selected\">&lt;mus&gt;</option>\n<option>hest</option></select>",
select("post", "category", %w( abe <mus> hest))
)
end
@@ -206,7 +206,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase
@post = Post.new
@post.category = "<mus>"
assert_equal(
- "<select id=\"post_category\" name=\"post[category]\"><option></option>\n<option>abe</option>\n<option selected=\"selected\">&lt;mus&gt;</option>\n<option>hest</option></select>",
+ "<select id=\"post_category\" name=\"post[category]\"><option></option>\n<option>abe</option>\n<option selected=\"selected\">&lt;mus&gt;</option>\n<option>hest</option></select>",
select("post", "category", %w( abe <mus> hest), :include_blank => true)
)
end
@@ -222,7 +222,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase
@post.author_name = "Babe"
assert_equal(
- "<select id=\"post_author_name\" name=\"post[author_name]\"><option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
+ "<select id=\"post_author_name\" name=\"post[author_name]\"><option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
collection_select("post", "author_name", @posts, "author_name", "author_name")
)
end
@@ -238,7 +238,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase
@post.author_name = "Babe"
assert_equal(
- "<select id=\"post_author_name\" name=\"post[author_name]\" style=\"width: 200px\"><option></option>\n<option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
+ "<select id=\"post_author_name\" name=\"post[author_name]\" style=\"width: 200px\"><option></option>\n<option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true }, "style" => "width: 200px")
)
end
@@ -291,6 +291,8 @@ class FormOptionsHelperTest < Test::Unit::TestCase
"<option value=\"E\">E</option>" +
"</select>",
html
+ assert_equal html, time_zone_select("firm", "time_zone", nil, {},
+ :style => "color: red")
end
def test_time_zone_select_with_blank_and_style
@@ -306,6 +308,8 @@ class FormOptionsHelperTest < Test::Unit::TestCase
"<option value=\"E\">E</option>" +
"</select>",
html
+ assert_equal html, time_zone_select("firm", "time_zone", nil,
+ { :include_blank => true }, :style => "color: red")
end
def test_time_zone_select_with_priority_zones
diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb
index 6036dd4b50..8fd6300b82 100644
--- a/actionpack/test/template/form_tag_helper_test.rb
+++ b/actionpack/test/template/form_tag_helper_test.rb
@@ -11,12 +11,13 @@ class FormTagHelperTest < Test::Unit::TestCase
%(hidden_field_tag "id", 3) => %(<input id="id" name="id" type="hidden" value="3" />),
%(password_field_tag) => %(<input id="password" name="password" type="password" value="" />),
%(text_area_tag("body", "hello world", :size => "20x40")) => %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>),
+ %(text_area_tag("body", "hello world", "size" => "20x40")) => %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>),
%(check_box_tag("admin")) => %(<input id="admin" name="admin" type="checkbox" value="1" />),
%(radio_button_tag("people", "david")) => %(<input id="people" name="people" type="radio" value="david" />),
%(select_tag("people", "<option>david</option>")) => %(<select id="people" name="people"><option>david</option></select>),
}
def test_tags
- MethodToTag.each { |method, tag| assert_equal(eval(method), tag) }
+ MethodToTag.each { |method, tag| assert_equal(tag, eval(method)) }
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/template/tag_helper_test.rb b/actionpack/test/template/tag_helper_test.rb
index 2db1bac238..9d8d2644e8 100644
--- a/actionpack/test/template/tag_helper_test.rb
+++ b/actionpack/test/template/tag_helper_test.rb
@@ -8,23 +8,26 @@ class TagHelperTest < Test::Unit::TestCase
def test_tag
assert_equal "<p class=\"show\" />", tag("p", "class" => "show")
+ assert_equal tag("p", "class" => "show"), tag("p", :class => "show")
end
-
+
def test_content_tag
assert_equal "<a href=\"create\">Create</a>", content_tag("a", "Create", "href" => "create")
+ assert_equal content_tag("a", "Create", "href" => "create"),
+ content_tag("a", "Create", :href => "create")
end
def test_mail_to_with_javascript
- assert_equal "<script type=\"text/javascript\" language=\"javascript\">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b'))</script>", mail_to("me@domain.com", "My email", :encode => "javascript")
+ assert_equal "<script type=\"text/javascript\" language=\"javascript\">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b'))</script>", mail_to("me@domain.com", "My email", :encode => "javascript")
end
def test_mail_to_with_hex
- assert_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">My email</a>", mail_to("me@domain.com", "My email", :encode => "hex")
+ assert_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">My email</a>", mail_to("me@domain.com", "My email", :encode => "hex")
end
def test_mail_to
- assert_equal "<a href=\"mailto:me@domain.com\">My email</a>", mail_to("me@domain.com", "My email")
+ assert_equal "<a href=\"mailto:me@domain.com\">My email</a>", mail_to("me@domain.com", "My email")
end
# FIXME: Test form tag
-end \ No newline at end of file
+end
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index 2082f4aae8..aba0d99699 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -8,11 +8,11 @@ class TextHelperTest < Test::Unit::TestCase
assert_equal "Hello World!", truncate("Hello World!", 12)
assert_equal "Hello Worl...", truncate("Hello World!!", 12)
end
-
+
def test_strip_links
assert_equal "on my mind", strip_links("<a href='almost'>on my mind</a>")
end
-
+
def test_highlighter
assert_equal(
"This is a <strong class=\"highlight\">beautiful</strong> morning",
@@ -29,7 +29,7 @@ class TextHelperTest < Test::Unit::TestCase
highlight("This is a beautiful morning, but also a beautiful day", "beautiful", '<b>\1</b>')
)
end
-
+
def test_highlighter_with_regexp
assert_equal(
"This is a <strong class=\"highlight\">beautiful!</strong> morning",
@@ -46,7 +46,7 @@ class TextHelperTest < Test::Unit::TestCase
highlight("This is a beautiful? morning", "beautiful? morning")
)
end
-
+
def test_excerpt
assert_equal("...is a beautiful morni...", excerpt("This is a beautiful morning", "beautiful", 5))
assert_equal("This is a...", excerpt("This is a beautiful morning", "this", 5))
@@ -54,16 +54,16 @@ class TextHelperTest < Test::Unit::TestCase
assert_equal("...iful morning", excerpt("This is a beautiful morning", "morning", 5))
assert_nil excerpt("This is a beautiful morning", "day")
end
-
+
def test_pluralization
assert_equal("1 count", pluralize(1, "count"))
assert_equal("2 counts", pluralize(2, "count"))
end
-
+
def test_auto_linking
assert_equal %(hello <a href="mailto:david@loudthinking.com">david@loudthinking.com</a>), auto_link("hello david@loudthinking.com", :email_addresses)
assert_equal %(Go to <a href="http://www.rubyonrails.com">http://www.rubyonrails.com</a>), auto_link("Go to http://www.rubyonrails.com", :urls)
assert_equal %(Go to http://www.rubyonrails.com), auto_link("Go to http://www.rubyonrails.com", :email_addresses)
assert_equal %(Go to <a href="http://www.rubyonrails.com">http://www.rubyonrails.com</a> and say hello to <a href="mailto:david@loudthinking.com">david@loudthinking.com</a>), auto_link("Go to http://www.rubyonrails.com and say hello to david@loudthinking.com")
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb
index 6e94d98ebe..379db0b9b7 100644
--- a/actionpack/test/template/url_helper_test.rb
+++ b/actionpack/test/template/url_helper_test.rb
@@ -21,26 +21,31 @@ class UrlHelperTest < Test::Unit::TestCase
def test_link_tag_with_straight_url
assert_equal "<a href=\"http://www.world.com\">Hello</a>", link_to("Hello", "http://www.world.com")
end
-
+
def test_link_tag_with_javascript_confirm
assert_equal(
- "<a href=\"http://www.world.com\" onclick=\"return confirm('Are you sure?');\">Hello</a>",
+ "<a href=\"http://www.world.com\" onclick=\"return confirm('Are you sure?');\">Hello</a>",
link_to("Hello", "http://www.world.com", :confirm => "Are you sure?")
)
end
-
+
def test_link_to_image
assert_equal(
- "<a href=\"http://www.world.com\"><img alt=\"Rss\" border=\"0\" height=\"45\" src=\"/images/rss.png\" width=\"30\" /></a>",
+ "<a href=\"http://www.world.com\"><img alt=\"Rss\" border=\"0\" height=\"45\" src=\"/images/rss.png\" width=\"30\" /></a>",
link_to_image("rss", "http://www.world.com", "size" => "30x45")
)
assert_equal(
- "<a class=\"admin\" href=\"http://www.world.com\"><img alt=\"Feed\" border=\"0\" height=\"45\" src=\"/images/rss.gif\" width=\"30\" /></a>",
+ "<a class=\"admin\" href=\"http://www.world.com\"><img alt=\"Feed\" border=\"0\" height=\"45\" src=\"/images/rss.gif\" width=\"30\" /></a>",
link_to_image("rss.gif", "http://www.world.com", "size" => "30x45", "alt" => "Feed", "class" => "admin")
)
+
+ assert_equal link_to_image("rss", "http://www.world.com", "size" => "30x45"),
+ link_to_image("rss", "http://www.world.com", :size => "30x45")
+ assert_equal link_to_image("rss.gif", "http://www.world.com", "size" => "30x45", "alt" => "Feed", "class" => "admin"),
+ link_to_image("rss.gif", "http://www.world.com", :size => "30x45", :alt => "Feed", :class => "admin")
end
-
+
def test_link_unless_current
@request = RequestMock.new("http://www.world.com")
assert_equal "Showing", link_to_unless_current("Showing", :action => "show", :controller => "weblog")
@@ -55,11 +60,13 @@ class UrlHelperTest < Test::Unit::TestCase
assert_equal "<a href=\"mailto:david@loudthinking.com\">david@loudthinking.com</a>", mail_to("david@loudthinking.com")
assert_equal "<a href=\"mailto:david@loudthinking.com\">David Heinemeier Hansson</a>", mail_to("david@loudthinking.com", "David Heinemeier Hansson")
assert_equal(
- "<a class=\"admin\" href=\"mailto:david@loudthinking.com\">David Heinemeier Hansson</a>",
+ "<a class=\"admin\" href=\"mailto:david@loudthinking.com\">David Heinemeier Hansson</a>",
mail_to("david@loudthinking.com", "David Heinemeier Hansson", "class" => "admin")
)
+ assert_equal mail_to("david@loudthinking.com", "David Heinemeier Hansson", "class" => "admin"),
+ mail_to("david@loudthinking.com", "David Heinemeier Hansson", :class => "admin")
end
-
+
def test_link_with_nil_html_options
assert_equal "<a href=\"http://www.world.com\">Hello</a>", link_to("Hello", {:action => 'myaction'}, nil)
end