Sha256: 2699efec091ab19cd80af1fe2f62556b51772fcefad97e8070236d4a17e08c2b

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

require 'test_helper'

module BarkestCore
  class BoolParserTest < ActiveSupport::TestCase

    test 'should parse true values' do
      %w(TRUE true True YES yes Yes ON on On 1 -1 T t Y y).each do |val|
        assert BarkestCore::BooleanParser.parse_for_boolean_column(val), "#{val.inspect} should be true"
        assert_equal "1", BarkestCore::BooleanParser.parse_for_boolean_filter(val), "#{val.inspect} should be true"
      end
    end

    test 'should parse false values' do
      %w(FALSE false False NO no No OFF off Off 0 F f N n).each do |val|
        assert_not BarkestCore::BooleanParser.parse_for_boolean_column(val), "#{val.inspect} should be false"
        assert_equal "0", BarkestCore::BooleanParser.parse_for_boolean_filter(val), "#{val.inspect} should be false"
      end
    end

    test 'should parse nil values' do
      [ nil, '', '   ' ].each do |val|
        assert_nil BarkestCore::BooleanParser.parse_for_boolean_column(val), "#{val.inspect} should be nil"
        assert_equal "NULL", BarkestCore::BooleanParser.parse_for_boolean_filter(val), "#{val.inspect} should be nil"
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
barkest_core-1.5.4.0 test/models/barkest_core/bool_parser_test.rb
barkest_core-1.5.3.0 test/models/barkest_core/bool_parser_test.rb