Skip to content

Commit

Permalink
add superior_equal_to validator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Feb 28, 2023
1 parent fb62419 commit 5cd980d
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion test/test_validators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 5cd980d

Please sign in to comment.