require 'test_helper'

class ValidationPredicatesLessThanOrEqualToTest < TestBase
  class Foo
    include Wardrobe
    plugin :validation
    attribute :integer, Integer, validates { lteq?(1) }
    attribute :float, Float, validates { lteq?(1.0) }
  end

  def test_nil
    no_log do
      assert_raises(NoMethodError) {
        Foo.new(
          integer: nil, float: nil
        )._validation_errors
      }
    end
  end

  def test_fail
    errors = Foo.new(
      integer: 2, float: 1.1
    )._validation_errors

    assert_equal 'must be less than or equal to 1', errors[:integer][0]
    assert_equal 'must be less than or equal to 1.0', errors[:float][0]
  end

  def test_success
    errors = Foo.new(
      integer: 1, float: 1.0
    )._validation_errors

    refute errors.has_key?(:integer)
    refute errors.has_key?(:float)
  end
end
