Sha256: 0126b568bced333eda1a8ac8e4bd0c15c3de6e6181ac6804456f9b8d3565f80e

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

# coding: utf-8

require 'test/unit/helper'

class ThinReports::Core::Shape::Tblock::Formatter::TestDatetime < MiniTest::Unit::TestCase
  include ThinReports::TestHelpers
  
  # Alias
  Formatter = ThinReports::Core::Shape::Tblock::Formatter::Datetime
  
  def setup
    @datetime_format = '%Y/%m/%d %H:%M:%S'
    @time            = Time.now

    @format = flexmock(:format_base => '', 
                       :format_datetime_format => @datetime_format)
  end
  
  def test_apply_datetime_format_without_basic_format
    formatter = Formatter.new(@format)
    
    assert_equal formatter.apply(@time), @time.strftime(@datetime_format)
  end
  
  def test_apply_datetime_format_with_basic_format
    # Partial mock
    format = flexmock(@format, :format_base => 'Now: {value}')
    
    formatter = Formatter.new(format)
    
    assert_equal formatter.apply(@time),
                 "Now: #{@time.strftime(@datetime_format)}"
  end
  
  def test_not_apply_datetime_format_and_return_raw_value
    # When value is invalid
    formatter = Formatter.new(@format)
    
    assert_same formatter.apply(val = 'invalid value'), val
    assert_same formatter.apply(val = 123456), val
    
    # When format is empty
    format = flexmock(@format, :format_datetime_format => '')
    
    assert_same formatter.apply(@time), @time
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thinreports-0.6.0.pre3 test/unit/core/shape/tblock/formatter/test_datetime.rb