Skip to content
This repository has been archived by the owner on Dec 23, 2020. It is now read-only.

Commit

Permalink
Merge pull request #26 from sanemat/feature/actionview-master-20131110
Browse files Browse the repository at this point in the history
Update for ActionPack v4.1 2013-11-10
  • Loading branch information
sanemat committed Nov 10, 2013
2 parents ad4dc59 + c8889f4 commit 2eae1ea
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions test/test_actionview-link_to_blank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def render_erb(string)
end
end

# Rails4.1, this code is here:
# actionview/test/template/url_helper_test.rb
# and base class is ActiveSupport::TestCase
class TestActionViewLinkToBlank < MiniTest::Unit::TestCase

# In a few cases, the helper proxies to 'controller'
Expand Down Expand Up @@ -110,6 +113,7 @@ def test_link_with_nil_html_options

def test_link_tag_with_custom_onclick
link = link_to_blank("Hello", "http://www.example.com", onclick: "alert('yay!')")
# NOTE: differences between AP v3 and v4
escaped_onclick = ActionPack::VERSION::MAJOR == 3 ? %{alert(&#x27;yay!&#x27;)} : %{alert(&#39;yay!&#39;)}
expected = %{<a href="http://www.example.com" onclick="#{escaped_onclick}" target="_blank">Hello</a>}
assert_dom_equal expected, link
Expand All @@ -132,7 +136,7 @@ def test_link_tag_with_javascript_confirm

def test_link_tag_with_deprecated_confirm
skip('Not deprecate in Rails3.2') if ActionPack::VERSION::MAJOR == 3
skip('Remove in Rails4.1') if ActionPack::VERSION::MAJOR == 4 && ActionPack::VERSION::MINOR >= 1
skip('Remove in Rails4.1') if ActionPack::VERSION::MAJOR >= 4 && ActionPack::VERSION::MINOR >= 1
assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do
assert_dom_equal(
%{<a href="http://www.example.com" data-confirm="Are you sure?" target="_blank">Hello</a>},
Expand Down Expand Up @@ -218,7 +222,7 @@ def test_link_tag_using_post_javascript_and_confirm

def test_link_tag_using_post_javascript_and_with_deprecated_confirm
skip('Not deprecate in Rails3.2') if ActionPack::VERSION::MAJOR == 3
skip('Remove in Rails4.1') if ActionPack::VERSION::MAJOR == 4 && ActionPack::VERSION::MINOR >= 1
skip('Remove in Rails4.1') if ActionPack::VERSION::MAJOR >= 4 && ActionPack::VERSION::MINOR >= 1
assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do
assert_dom_equal(
%{<a href="http://www.example.com" data-method="post" rel="nofollow" data-confirm="Are you serious?" target="_blank">Hello</a>},
Expand All @@ -236,7 +240,7 @@ def test_link_tag_using_delete_javascript_and_href_and_confirm

def test_link_tag_using_delete_javascript_and_href_and_with_deprecated_confirm
skip('Not deprecate in Rails3.2') if ActionPack::VERSION::MAJOR == 3
skip('Remove in Rails4.1') if ActionPack::VERSION::MAJOR == 4 && ActionPack::VERSION::MINOR >= 1
skip('Remove in Rails4.1') if ActionPack::VERSION::MAJOR >= 4 && ActionPack::VERSION::MINOR >= 1
assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do
assert_dom_equal(
%{<a href="\#" rel="nofollow" data-confirm="Are you serious?" data-method="delete" target="_blank">Destroy</a>},
Expand All @@ -255,6 +259,13 @@ def test_link_tag_with_block_and_html_options
link_to_blank('/', class: "special") { content_tag(:span, 'Example site') }
end

def test_link_tag_using_block_and_hash
assert_dom_equal(
%{<a href="/" target="_blank"><span>Example site</span></a>},
link_to_blank(url_hash) { content_tag(:span, 'Example site') }
)
end

def test_link_tag_using_block_in_erb
out = render_erb %{<%= link_to_blank('/') do %>Example site<% end %>}
assert_equal '<a href="/" target="_blank">Example site</a>', out
Expand Down Expand Up @@ -298,12 +309,17 @@ def test_link_to_unless
link_to_blank_unless(true, "Showing", url_hash) {
"test"
}

# FIXME
# assert_equal %{&lt;b&gt;Showing&lt;/b&gt;}, link_to_unless(true, "<b>Showing</b>", url_hash)
# assert_equal %{<a href="/">&lt;b&gt;Showing&lt;/b&gt;</a>}, link_to_unless(false, "<b>Showing</b>", url_hash)
# assert_equal %{<b>Showing</b>}, link_to_unless(true, "<b>Showing</b>".html_safe, url_hash)
# assert_equal %{<a href="/"><b>Showing</b></a>}, link_to_unless(false, "<b>Showing</b>".html_safe, url_hash)
end

def test_link_to_if
assert_equal "Showing", link_to_blank_if(false, "Showing", url_hash)
assert_dom_equal %{<a href="/" target="_blank">Listing</a>}, link_to_blank_if(true, "Listing", url_hash)
assert_equal "Showing", link_to_blank_if(false, "Showing", url_hash)
end

def request_for_url(url, opts = {})
Expand Down

0 comments on commit 2eae1ea

Please sign in to comment.