mirror of
https://github.com/internetee/registry.git
synced 2025-06-08 05:34:46 +02:00
added test for jobs, validators and helper
This commit is contained in:
parent
d53d4f2412
commit
14b8dd6ade
6 changed files with 170 additions and 4 deletions
|
@ -2,15 +2,61 @@ require 'test_helper'
|
|||
|
||||
class DateTimeIso8601Validatable
|
||||
include ActiveModel::Validations
|
||||
validates_with DateTimeIso8601Validator, :attributes=>[:code]
|
||||
attr_accessor :code
|
||||
validates :code, iso8601: { date_only: true }
|
||||
validates_with DateTimeIso8601Validator, :attributes=>[:errors]
|
||||
attr_accessor :code, :type
|
||||
validates :code, iso8601: { date_only: true }, if: :birthday?
|
||||
|
||||
def birthday?
|
||||
type == "birthday"
|
||||
end
|
||||
|
||||
def empty?
|
||||
code.empty?
|
||||
end
|
||||
end
|
||||
|
||||
class DateTimeIso8601ValidatorTest < ActiveSupport::TestCase
|
||||
def test_check_invalid_date
|
||||
def test_check_invalid_reverse_date
|
||||
obj = DateTimeIso8601Validatable.new
|
||||
obj.type = "birthday"
|
||||
obj.code = "22-12-2020"
|
||||
assert_not obj.valid?
|
||||
end
|
||||
|
||||
def test_check_date_without_separate_symbols
|
||||
obj = DateTimeIso8601Validatable.new
|
||||
obj.type = "birthday"
|
||||
obj.code = "24521012"
|
||||
assert_not obj.valid?
|
||||
end
|
||||
|
||||
def test_check_empty_date
|
||||
obj = DateTimeIso8601Validatable.new
|
||||
obj.type = "birthday"
|
||||
obj.code = ""
|
||||
assert_not obj.valid?
|
||||
end
|
||||
|
||||
def test_check_valid_date
|
||||
obj = DateTimeIso8601Validatable.new
|
||||
obj.code = Date.new(2000,5,25).iso8601
|
||||
obj.type = "birthday"
|
||||
assert obj.valid?
|
||||
end
|
||||
|
||||
def test_return_code_2005_in_epp_validate
|
||||
obj = DateTimeIso8601Validatable.new
|
||||
obj.code = Date.new(2000,5,25).iso8601
|
||||
obj.type = "birthday"
|
||||
epp_resp = DateTimeIso8601Validator.validate_epp(obj, obj.code)
|
||||
assert_equal epp_resp[:msg], "Expiry absolute must be compatible to ISO 8601"
|
||||
end
|
||||
|
||||
def test_epp_request_with_empty_data
|
||||
obj = DateTimeIso8601Validatable.new
|
||||
obj.code = ""
|
||||
obj.type = "birthday"
|
||||
epp_resp = DateTimeIso8601Validator.validate_epp(obj, obj.code)
|
||||
assert_nil epp_resp
|
||||
end
|
||||
end
|
57
test/lib/validators/duration_iso8601_validator_test.rb
Normal file
57
test/lib/validators/duration_iso8601_validator_test.rb
Normal file
|
@ -0,0 +1,57 @@
|
|||
require 'test_helper'
|
||||
|
||||
class DurationIso8601Validatable
|
||||
include ActiveModel::Validations
|
||||
validates_with DurationIso8601Validator, :attributes=>[:errors]
|
||||
attr_accessor :duration
|
||||
validates :duration, inclusion: { in: Proc.new { |price| price.class.durations } }
|
||||
|
||||
def self.durations
|
||||
[
|
||||
'3 mons',
|
||||
'6 mons',
|
||||
'9 mons',
|
||||
'1 year',
|
||||
'2 years',
|
||||
'3 years',
|
||||
'4 years',
|
||||
'5 years',
|
||||
'6 years',
|
||||
'7 years',
|
||||
'8 years',
|
||||
'9 years',
|
||||
'10 years',
|
||||
]
|
||||
end
|
||||
|
||||
def empty?
|
||||
duration.empty?
|
||||
end
|
||||
end
|
||||
|
||||
class DurationIso8601ValidatorTest < ActiveSupport::TestCase
|
||||
def test_valid_duration
|
||||
dura = DurationIso8601Validatable.new
|
||||
dura.duration = '1 year'
|
||||
assert dura.valid?
|
||||
end
|
||||
|
||||
def test_invalid_duration
|
||||
dura = DurationIso8601Validatable.new
|
||||
dura.duration = 'one millinons years'
|
||||
assert_not dura.valid?
|
||||
end
|
||||
|
||||
def test_empty_duration
|
||||
dura = DurationIso8601Validatable.new
|
||||
dura.duration = ''
|
||||
assert_not dura.valid?
|
||||
end
|
||||
|
||||
def test_return_epp_response_code_2005
|
||||
dura = DurationIso8601Validatable.new
|
||||
dura.duration = '1 year'
|
||||
epp_resp = DurationIso8601Validator.validate_epp(dura, dura.duration)
|
||||
assert_equal epp_resp[:msg], "Expiry relative must be compatible to ISO 8601"
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue