1 # frozen_string_literal: true
 
   5 class ApplicationHelperTest < ActionView::TestCase
 
   6   attr_accessor :current_user
 
   9     %w[http://example.com/test ftp://example.com/test https://example.com/test].each do |link|
 
  10       text = "Test #{link} is <b>made</b> into a link"
 
  13       assert_predicate html, :html_safe?
 
  14       assert_dom_equal "Test <a href=\"#{link}\" rel=\"nofollow\" dir=\"auto\">#{link}</a> is <b>made</b> into a link", html
 
  16       html = linkify(text.html_safe)
 
  17       assert_predicate html, :html_safe?
 
  18       assert_dom_equal "Test <a href=\"#{link}\" rel=\"nofollow\" dir=\"auto\">#{link}</a> is <b>made</b> into a link", html
 
  21     %w[test@example.com mailto:test@example.com].each do |link|
 
  22       text = "Test #{link} is not <b>made</b> into a link"
 
  25       assert_predicate html, :html_safe?
 
  26       assert_dom_equal "Test #{link} is not <b>made</b> into a link", html
 
  28       html = linkify(text.html_safe)
 
  29       assert_predicate html, :html_safe?
 
  30       assert_dom_equal "Test #{link} is not <b>made</b> into a link", html
 
  35     link = rss_link_to(:controller => :diary_entries, :action => :rss)
 
  36     assert_dom_equal "<a href=\"/diary/rss\"><img height=\"16\" src=\"/images/RSS.png\" width=\"16\" class=\"align-text-bottom\" /></a>", link
 
  40     link = atom_link_to(:controller => :changesets, :action => :feed)
 
  41     assert_dom_equal "<a href=\"/history/feed\"><img height=\"16\" src=\"/images/RSS.png\" width=\"16\" class=\"align-text-bottom\" /></a>", link
 
  45     assert_equal "ltr", dir
 
  48     assert_equal "rtl", dir
 
  51     I18n.with_locale "he" do
 
  52       assert_equal "rtl", dir
 
  55       assert_equal "ltr", dir
 
  60   def test_friendly_date
 
  61     date = friendly_date(Time.utc(2014, 3, 5, 18, 58, 23))
 
  62     assert_match %r{^<time title=" *5 March 2014 at 18:58" datetime="2014-03-05T18:58:23Z">.*</time>$}, date
 
  64     date = friendly_date(Time.now.utc - 1.hour)
 
  65     assert_match %r{^<time title=".*">about 1 hour</time>$}, date
 
  67     date = friendly_date(Time.now.utc - 2.days)
 
  68     assert_match %r{^<time title=".*">2 days</time>$}, date
 
  70     date = friendly_date(Time.now.utc - 3.weeks)
 
  71     assert_match %r{^<time title=".*">21 days</time>$}, date
 
  73     date = friendly_date(Time.now.utc - 4.months)
 
  74     assert_match %r{^<time title=".*">4 months</time>$}, date
 
  77   def test_friendly_date_ago
 
  78     date = friendly_date_ago(Time.utc(2014, 3, 5, 18, 58, 23))
 
  79     assert_match %r{^<time title=" *5 March 2014 at 18:58" datetime="2014-03-05T18:58:23Z">.*</time>$}, date
 
  81     date = friendly_date_ago(Time.now.utc - 1.hour)
 
  82     assert_match %r{^<time title=".*">about 1 hour ago</time>$}, date
 
  84     date = friendly_date_ago(Time.now.utc - 2.days)
 
  85     assert_match %r{^<time title=".*">2 days ago</time>$}, date
 
  87     date = friendly_date_ago(Time.now.utc - 3.weeks)
 
  88     assert_match %r{^<time title=".*">21 days ago</time>$}, date
 
  90     date = friendly_date_ago(Time.now.utc - 4.months)
 
  91     assert_match %r{^<time title=".*">4 months ago</time>$}, date