diff --git a/app/helpers/rendering_helper.rb b/app/helpers/rendering_helper.rb index 9c6f0d97..18853805 100644 --- a/app/helpers/rendering_helper.rb +++ b/app/helpers/rendering_helper.rb @@ -10,7 +10,7 @@ module RenderingHelper right = $' # detect already linked URLs and URLs in the middle of a tag if left =~ /<[^>]+$/ && right =~ /^[^>]*>/ - # do not change string; URL is alreay linked + # do not change string; URL is already linked href else content_tag(:a, h(href), :href => h(href)) diff --git a/test/controllers/todos_controller_test.rb b/test/controllers/todos_controller_test.rb index b95b1354..1781a0b0 100644 --- a/test/controllers/todos_controller_test.rb +++ b/test/controllers/todos_controller_test.rb @@ -978,77 +978,16 @@ class TodosControllerTest < ActionController::TestCase # todo notes ############ - def test_url_with_slash_in_query_string_are_parsed_correctly - # See http://blog.swivel.com/code/2009/06/rails-auto_link-and-certain-query-strings.html + def test_format_note login_as(:admin_user) todo = users(:admin_user).todos.first - url = 'http://example.com/foo?bar=/baz' - todo.notes = "foo #{url} bar" + todo.notes = "Normal *bold* http://foo.bar/baz" todo.save! get :index - assert_select "a[href='#{url}']" - end - - def test_link_opened_in_new_window - # issue #1747 - login_as(:admin_user) - todo = users(:admin_user).todos.first - url = 'http://example.com/' - todo.notes = "foo #{url} bar" - todo.save! - get :index - assert_select "a[target='_blank']" - end - - def test_format_note_normal - login_as(:admin_user) - todo = users(:admin_user).todos.first - todo.notes = "A normal description." - todo.save! - get :index - assert_select("div#notes_todo_#{todo.id}", "A normal description.") - end - - def test_format_note_textile - login_as(:admin_user) - todo = users(:admin_user).todos.first - todo.notes = "A *bold description*." - todo.save! - get :index - assert_select("div#notes_todo_#{todo.id}", "A bold description.") - assert_select("div#notes_todo_#{todo.id} strong", "bold description") - end - - def test_format_note_link - login_as(:admin_user) - todo = users(:admin_user).todos.first - todo.notes = "A link to http://github.com/." - todo.save! - get :index - assert_select("div#notes_todo_#{todo.id}", 'A link to http://github.com/.') - assert_select("div#notes_todo_#{todo.id} a[href='http://github.com/']", 'http://github.com/') - end - - def test_format_note_link_message - login_as(:admin_user) - todo = users(:admin_user).todos.first - todo.raw_notes = "A Mail.app message:// link" - todo.save! - get :index - assert_select("div#notes_todo_#{todo.id}", 'A Mail.app message:// link') - assert_select("div#notes_todo_#{todo.id} a", 'message://') - assert_select("div#notes_todo_#{todo.id} a[href='message://']", "message://") - end - - def test_format_note_link_onenote - login_as(:admin_user) - todo = users(:admin_user).todos.first - todo.notes = ' "link me to onenote":onenote:///E:\OneNote\dir\notes.one#PAGE§ion-id={FD597D3A-3793-495F-8345-23D34A00DD3B}&page-id={1C95A1C7-6408-4804-B3B5-96C28426022B}&end' - todo.save! - get :index - assert_select("div#notes_todo_#{todo.id}", 'link me to onenote') - assert_select("div#notes_todo_#{todo.id} a", 'link me to onenote') - assert_select("div#notes_todo_#{todo.id} a[href='onenote:///E:%5COneNote%5Cdir%5Cnotes.one#PAGE§ion-id=%7BFD597D3A-3793-495F-8345-23D34A00DD3B%7D&page-id=%7B1C95A1C7-6408-4804-B3B5-96C28426022B%7D&end']", 'link me to onenote') + assert_select("div#notes_todo_#{todo.id}", "Normal bold http://foo.bar/baz") + assert_select("a[href='http://foo.bar/baz']", "http://foo.bar/baz") + assert_select("a[target='_blank']") + assert_select("strong", "bold") end ############## diff --git a/test/helpers/rendering_helper_test.rb b/test/helpers/rendering_helper_test.rb index 358e3c68..5e558736 100644 --- a/test/helpers/rendering_helper_test.rb +++ b/test/helpers/rendering_helper_test.rb @@ -3,33 +3,71 @@ require "test_helper" class RenderingHelperTest < ActionView::TestCase include RenderingHelper - test "auto_link_message" do - html = "This is a sample with a message - message://<123456789>. There we go." - rendered_html = auto_link_message(html) - assert( - rendered_html.include?(%|message://<123456789>|), - "Message was not correctly rendered. Rendered message:\n#{rendered_html}" - ) - - html = %|This message is already tagged: Call bob."| - rendered_html = auto_link_message(html) - assert_equal(html, rendered_html) + test "textile markup" do + actual = render_text("This is *strong*.") + assert_equal("

This is strong.

", actual) end - test "textile" do - raw_textile = "This should end up *strong*." - rendered_textile = textile(raw_textile) - assert_equal("

This should end up strong.

", rendered_textile) + test "onenote link" do + url = 'onenote:///E:\OneNote\dir\notes.one#PAGE§ion-id={FD597D3A-3793-495F-8345-23D34A00DD3B}&page-id={1C95A1C7-6408-4804-B3B5-96C28426022B}&end' + actual = render_text(url) + expected = '

onenote:///E:\OneNote\dir\notes.one#PAGE&section-id={FD597D3A-3793-495F-8345-23D34A00DD3B}&page-id={1C95A1C7-6408-4804-B3B5-96C28426022B}&end

' + assert_equal(expected, actual) end - test "render_text" do - simple_textile = render_text("This is *strong*.") - assert_equal("

This is strong.

", simple_textile) + test "textile onenote link" do + url = '"link me to onenote":onenote://foo/bar' + actual = render_text(url) + expected = '

link me to onenote

' + assert_equal(expected, actual) + end - autolink_message = render_text("Call message://<123>.") - assert_equal(%|

Call message://<123>.

|, autolink_message) + test "tagged onenote link" do + actual = render_text('Link to onenote here.') + assert_equal('

Link to onenote here.

', actual) + end - onenote_links = render_text(%|Link to onenote here.|) - assert_equal(%|

Link to onenote here.

|, onenote_links) + test "message link" do + actual = render_text("Call message://<123>.") + assert_equal('

Call message://<123>.

', actual) + end + + test "tagged message link" do + expected = '

This message is already tagged: Call bob.

' + actual = render_text(expected) + assert_equal(expected, actual) + end + + test "http link (in new window)" do + actual = render_text("A link to http://github.com/.") + expected = '

A link to http://github.com/.

' + assert_equal(expected, actual) + end + + test "http link (with double hyphens)" do + # not implemented, see issue #2056 + # actual = render_text("http://foo.bar/foo--bar") + # expected = '

http://foo.bar/foo--bar

' + # assert_equal(expected, actual) + end + + test "textile http link" do + actual = render_text('A link to "GitHub":http://github.com/.') + expected = '

A link to GitHub.

' + assert_equal(expected, actual) + end + + test "textile http link (in new window)" do + # not implemented, see issue #2066 + # actual = render_text('A link to "GitHub":http://github.com/.') + # expected = '

A link to GitHub.

' + # assert_equal(expected, actual) + end + + test "url with slash in query string" do + # See http://blog.swivel.com/code/2009/06/rails-auto_link-and-certain-query-strings.html + actual = render_text("foo http://example.com/foo?bar=/baz bar") + expected = '

foo http://example.com/foo?bar=/baz bar

' + assert_equal(expected, actual) end end