Sha256: ff400ac9b251ffdb3c8ca6d5e1912024db7cb54fb562d3250a875b636b07067d

Contents?: true

Size: 1.46 KB

Versions: 9

Compression:

Stored size: 1.46 KB

Contents

require 'helper'
require 'fixtures/markup_app/app'

class TestFormatHelpers < Test::Unit::TestCase
  def app
    MarkupDemo.tap { |app| app.set :environment, :test }
  end

  include SinatraMore::FormatHelpers

  context 'for #relative_time_ago method' do
    should "display today" do
      assert_equal 'today', relative_time_ago(Time.now)
    end
    should "display yesterday" do
      assert_equal 'yesterday', relative_time_ago(1.day.ago)
    end
    should "display tomorrow" do
      assert_equal 'tomorrow', relative_time_ago(1.day.from_now)
    end
    should "return future number of days" do
      assert_equal 'in 4 days', relative_time_ago(4.days.from_now)
    end
    should "return past days ago" do
      assert_equal '4 days ago', relative_time_ago(4.days.ago)
    end
    should "return formatted archived date" do
      assert_equal 100.days.ago.strftime('%A, %B %e'), relative_time_ago(100.days.ago)
    end
    should "return formatted archived year date" do
      assert_equal 500.days.ago.strftime('%A, %B %e, %Y'), relative_time_ago(500.days.ago)
    end
  end

  context 'for #escape_javascript method' do
    should "escape double quotes" do
      assert_equal "\"hello\"", escape_javascript('"hello"')
    end
    should "escape single quotes" do
      assert_equal "\"hello\"", escape_javascript("'hello'")
    end
    should "escape html tags and breaks" do
      assert_equal "\"\\n<p>hello<\\/p>\\n\"", escape_javascript("\n\r<p>hello</p>\r\n")
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sinatra_more-0.1.9 test/markup_plugin/test_format_helpers.rb
sinatra_more-0.1.8 test/markup_plugin/test_format_helpers.rb
sinatra_more-0.1.7 test/markup_plugin/test_format_helpers.rb
sinatra_more-0.1.6 test/markup_plugin/test_format_helpers.rb
sinatra_more-0.1.5 test/markup_plugin/test_format_helpers.rb
sinatra_more-0.1.4 test/markup_plugin/test_format_helpers.rb
sinatra_more-0.1.3 test/markup_plugin/test_format_helpers.rb
sinatra_more-0.1.2 test/markup_plugin/test_format_helpers.rb
sinatra_more-0.1.1 test/markup_plugin/test_format_helpers.rb