Skip to content

Commit

Permalink
add test-case for link_to_if behavior with a block.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
senny committed May 1, 2015
1 parent 14d0e07 commit e38dd7b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions actionview/test/template/url_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ def test_link_to_if
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)
Expand Down Expand Up @@ -479,6 +484,11 @@ def test_link_unless_current
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" }

This comment has been minimized.

Copy link
@kuldeepaggarwal

kuldeepaggarwal May 2, 2015

Contributor

@senny I think, it should assert_dom_equal instead of asset_equal. wdyt?

This comment has been minimized.

Copy link
@senny

senny May 2, 2015

Author Member

@kuldeepaggarwal jup, I messed the order up, we can replace the following assert_dom_equal with an assert_equal as well.

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")
Expand Down

0 comments on commit e38dd7b

Please sign in to comment.