require_relative '../../app/helpers/local_time_helper'
require 'active_support/all'
require 'action_view'
require 'minitest/autorun'
class LocalTimeHelperTest < Minitest::Test
include ActionView::Helpers::DateHelper, ActionView::Helpers::TagHelper
include LocalTimeHelper
def setup
@original_zone = Time.zone
Time.zone = ActiveSupport::TimeZone["Central Time (US & Canada)"]
@date = "2013-11-21"
@time = Time.zone.parse(@date)
@time_utc = "2013-11-21 06:00:00 UTC"
@time_js = "2013-11-21T06:00:00Z"
end
def teardown
Time.zone = @original_zone
end
def test_utc_time_with_a_date
date = Date.parse(@date)
assert_equal @time_utc, utc_time(date).to_s
end
def test_utc_time_with_a_local_time
assert_equal @time_utc, utc_time(@time).to_s
end
def test_utc_time_with_a_utc_time
assert_equal @time_utc, utc_time(@time.utc).to_s
end
def test_local_time
expected = %Q()
assert_equal expected, local_time(@time)
end
def test_local_time_with_format
expected = %Q()
assert_equal expected, local_time(@time, format: '%b %e')
end
def test_local_time_with_options
expected = %Q()
assert_equal expected, local_time(@time, format: '%b %e', style: 'display:none')
end
def test_local_date
expected = %Q()
assert_equal expected, local_date(@time)
assert_equal expected, local_date(@time.to_date)
end
def test_local_date_with_format
expected = %Q()
assert_equal expected, local_date(@time, format: '%b %e')
end
def test_local_time_ago
expected = %Q()
assert_equal expected, local_time_ago(@time)
end
end