Skip to content

Commit

Permalink
add distinct of validator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Feb 28, 2023
1 parent 9e4739c commit 05bb6cb
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion test/test_validators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class SymmetricTestModel < Goo::Base::Resource
attribute :friends, enforce: [SymmetricTestModel, :symmetric, :list]
end

class DistinctOfTestModel < Goo::Base::Resource
model :symmetric_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 TestValidators < MiniTest::Unit::TestCase
Expand Down Expand Up @@ -217,7 +224,7 @@ def test_symmetric_validator_no_list
p1.save

assert p2.valid?

GooTestData.delete_all [SymmetricTestModel]
end

def test_symmetric_validator_list
Expand Down Expand Up @@ -261,6 +268,32 @@ def test_symmetric_validator_list
p2.save

assert p4.valid?
GooTestData.delete_all [SymmetricTestModel]
end

def test_distinct_of_validator
p = DistinctOfTestModel.new
p.name = "p1"
p.last_name = "p1"
p.names = ["p1", "p2"]
p.last_names = ["p1", "p2"]


refute p.valid?

p.last_name = "last name"
p.last_names = ["last name 1", "last name 2"]

assert p.valid?

p.last_name = "last name"
p.last_names = ["last name 1", "p2"]

refute p.valid?

p.last_name = ""
p.last_names = []

assert p.valid?
end
end

0 comments on commit 05bb6cb

Please sign in to comment.