#= require ultimate/underscore/underscore
#= require ultimate/underscore/underscore.string
#= require ultimate/helpers/url
module "Ultimate.Helpers.Url"
_.extend @, Ultimate.Helpers.Url
test "url_for", ->
strictEqual url_for(), 'javascript:;'
strictEqual url_for({}), 'javascript:;'
strictEqual url_for(gamma: 2.2), '?gamma=2.2'
strictEqual url_for(gamma: 2.2, url: 'some_url'), 'some_url?gamma=2.2'
# strictEqual url_for(host: "www.example.com"), 'http://www.example.com/'
strictEqual url_for(url: -> 'some_url'), 'some_url'
options = gamma: 2.2, anchor: 'comments', url: 'some_url', lambda: false
strictEqual url_for(options), 'some_url?gamma=2.2&lambda=false#comments'
deepEqual options, gamma: 2.2, anchor: 'comments', url: 'some_url', lambda: false
strictEqual url_for("back"), 'javascript:history.back();'
strictEqual url_for("/back"), '/back'
test "link_to", ->
equal link_to('Hello', 'http://www.example.com'), 'Hello'
equal link_to('Test Link', '/'), 'Test Link'
equal link_to(null, 'http://ya.ru/'), 'http://ya.ru/'
equal link_to('caption'), 'caption'
equal link_to('caption', null, class: 'link'), 'caption'
equal link_to("Hello", "http://www.example.com", class: "red", data: {confirm: 'You cant possibly be sure,\n can you?'}),
'Hello'
equal link_to(null, -> 'caption'), 'caption'
equal link_to(-> 'caption'), 'caption'
test "link_to_js", ->
equal link_to_js('caption'), 'caption'
equal link_to_js('caption', class: 'link'), 'caption'
equal link_to_js("Hello", class: "red", data: {confirm: 'You cant possibly be sure,\n can you?'}),
'Hello'
equal link_to_js(null, -> 'caption'), 'caption'
equal link_to_js(class: 'link', -> 'caption'), 'caption'
equal link_to_js(-> 'caption'), 'caption'
test "mail_to", ->
equal mail_to("david@loudthinking.com"),
'david@loudthinking.com'
equal mail_to("david@loudthinking.com", "David Heinemeier Hansson"),
'David Heinemeier Hansson'
equal mail_to("david@loudthinking.com", "David Heinemeier Hansson", class: "admin"),
'David Heinemeier Hansson'
equal mail_to("me@domain.com", "My email", encode: "javascript"),
""
# equal mail_to("unicode@example.com", "Ășnicode", encode: "javascript"),
# ""
equal mail_to("me@example.com", "My email", cc: "ccaddress@example.com", bcc: "bccaddress@example.com", subject: "This is an example email", body: "This is the body of the message."),
'My email'
equal mail_to('feedback@example.com', ''),
''
equal mail_to("me@domain.com", "My email", encode: "hex"),
'My email'
equal mail_to("me@domain.com", null, encode: "hex"),
'me@domain.com'
equal mail_to("wolfgang@stufenlos.net", null, replace_at: "(at)", replace_dot: "(dot)"),
'wolfgang(at)stufenlos(dot)net'
equal mail_to("me@domain.com", null, encode: "hex", replace_at: "(at)"),
'me(at)domain.com'
equal mail_to("me@domain.com", "My email", encode: "hex", replace_at: "(at)"),
'My email'
equal mail_to("me@domain.com", null, encode: "hex", replace_at: "(at)", replace_dot: "(dot)"),
'me(at)domain(dot)com'
equal mail_to("me@domain.com", "My email", encode: "javascript", replace_at: "(at)", replace_dot: "(dot)"),
""
equal mail_to("me@domain.com", null, encode: "javascript", replace_at: "(at)", replace_dot: "(dot)"),
""