aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test/template
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2015-05-01 11:10:31 +0200
committerYves Senn <yves.senn@gmail.com>2015-05-01 11:12:56 +0200
commite38dd7bfa4360e241eadf0cf44abdf86ea33a393 (patch)
tree161e98c028a7b1d145aec2af3722cde37a71e51e /actionview/test/template
parent14d0e0702651de4d825769bddd574aa5066e86f3 (diff)
downloadrails-e38dd7bfa4360e241eadf0cf44abdf86ea33a393.tar.gz
rails-e38dd7bfa4360e241eadf0cf44abdf86ea33a393.tar.bz2
rails-e38dd7bfa4360e241eadf0cf44abdf86ea33a393.zip
add test-case for `link_to_if` behavior with a block.
This illustrates the purpose of the block for `link_to_if` and `link_to_unless` helper methods. It should help to prevent further mistakes like #19844.
Diffstat (limited to 'actionview/test/template')
-rw-r--r--actionview/test/template/url_helper_test.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb
index ef4df0407a..9ba837d4e7 100644
--- a/actionview/test/template/url_helper_test.rb
+++ b/actionview/test/template/url_helper_test.rb
@@ -379,6 +379,11 @@ class UrlHelperTest < ActiveSupport::TestCase
assert_dom_equal %{<a href="/">Listing</a>}, link_to_if(true, "Listing", url_hash)
end
+ def test_link_to_if_with_block
+ assert_equal "Fallback", link_to_if(false, "Showing", url_hash) { "Fallback" }
+ assert_dom_equal %{<a href="/">Listing</a>}, link_to_if(true, "Listing", url_hash) { "Fallback" }
+ end
+
def request_for_url(url, opts = {})
env = Rack::MockRequest.env_for("http://www.example.com#{url}", opts)
ActionDispatch::Request.new(env)
@@ -479,6 +484,11 @@ class UrlHelperTest < ActiveSupport::TestCase
link_to_unless_current("Listing", "http://www.example.com/")
end
+ def test_link_to_unless_with_block
+ assert_equal %{<a href="/">Showing</a>}, link_to_unless(false, "Showing", url_hash) { "Fallback" }
+ assert_dom_equal "Fallback", link_to_unless(true, "Listing", url_hash) { "Fallback" }
+ end
+
def test_mail_to
assert_dom_equal %{<a href="mailto:david@loudthinking.com">david@loudthinking.com</a>}, mail_to("david@loudthinking.com")
assert_dom_equal %{<a href="mailto:david@loudthinking.com">David Heinemeier Hansson</a>}, mail_to("david@loudthinking.com", "David Heinemeier Hansson")