mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 14:44:47 +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
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