Sha256: 2bdbe6e941b7e2b7aa62690369d057ce3e383233c290c57b27659489bb3510da

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

# coding: utf-8

require 'test_helper'

class Thinreports::Core::Shape::TextBlock::Formatter::TestDatetime < Minitest::Test
  include Thinreports::TestHelper

  # Aliases
  TextBlock = Thinreports::Core::Shape::TextBlock
  Formatter = TextBlock::Formatter::Datetime

  def setup
    @datetime_format = '%Y/%m/%d %H:%M:%S'
    @time = Time.now
  end

  def text_block_format(format = {})
    default = {'base' => '', 'datetime' => {'format' => '%Y/%m/%d %H:%M:%S'}}
    TextBlock::Format.new('format' => default.merge(format))
  end

  def test_apply_datetime_format_without_basic_format
    formatter = Formatter.new(text_block_format)

    assert_equal @time.strftime(@datetime_format),
                 formatter.apply(@time)
  end

  def test_apply_datetime_format_with_basic_format
    formatter = Formatter.new(text_block_format('base' => 'Now: {value}'))

    assert_equal "Now: #{@time.strftime(@datetime_format)}",
                 formatter.apply(@time)

  end

  def test_not_apply_datetime_format_and_return_raw_value
    # When value is invalid
    formatter = Formatter.new(text_block_format)

    assert_same formatter.apply(val = 'invalid value'), val
    assert_same formatter.apply(val = 123456), val

    # When format is empty
    formatter = Formatter.new(text_block_format('datetime' => {'format' => ''}))

    assert_same formatter.apply(@time), @time
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
thinreports-0.9.1 test/unit/core/shape/text_block/formatter/test_datetime.rb
thinreports-0.9.0 test/unit/core/shape/text_block/formatter/test_datetime.rb