From 5cd980d6a7014975a95d893fa32cdb5209f17859 Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Tue, 28 Feb 2023 09:05:12 +0100 Subject: [PATCH] add superior_equal_to validator tests --- test/test_validators.rb | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/test/test_validators.rb b/test/test_validators.rb index 02b5ed8a..c0989180 100644 --- a/test/test_validators.rb +++ b/test/test_validators.rb @@ -33,13 +33,20 @@ class SymmetricTestModel < Goo::Base::Resource end class DistinctOfTestModel < Goo::Base::Resource - model :symmetric_test_model, name_with: :name + model :distinct_of_test_model, name_with: :name attribute :name, enforce: [:unique, :existence, :string] attribute :last_name, enforce: [:distinct_of_name, :string] attribute :names, enforce: [:list, :string] attribute :last_names, enforce: [:list, :distinct_of_names, :string] end +class SuperiorToTestModel < Goo::Base::Resource + model :superior_to_test_model, name_with: :name + attribute :name, enforce: [:unique, :existence, :string] + attribute :birth_date, enforce: [:date_time] + attribute :death_date, enforce: [:superior_equal_to_birth_date, :date_time] +end + class TestValidators < MiniTest::Unit::TestCase @@ -296,4 +303,22 @@ def test_distinct_of_validator assert p.valid? end + + def test_superior_equal_to_validator + p = SuperiorToTestModel.new + p.name = "p" + p.birth_date = DateTime.parse('1998-12-02') + p.death_date = DateTime.parse('1995-12-02') + + refute p.valid? + assert p.errors[:death_date][:superior_equal_to_birth_date] + + p.death_date = DateTime.parse('2023-12-02') + + assert p.valid? + + p.birth_date = nil + + assert p.valid? + end end