Class: SequelSpec::Matchers::Validation::ValidateLengthMatcher
Instance Attribute Summary collapse
Instance Method Summary
collapse
#allowing_blank, #allowing_missing, #allowing_nil, #args_to_called_attributes, #valid?, #with_message
Methods inherited from Base
#failure_message, #hash_to_nice_string, #initialize, #matches?, #negative_failure_message, #with_options
Instance Attribute Details
#validation_type ⇒ Object
Returns the value of attribute validation_type.
5
6
7
|
# File 'lib/sequel_spec/validation/validate_length_matcher.rb', line 5
def validation_type
@validation_type
end
|
Instance Method Details
#additionnal_param_check ⇒ Object
24
25
26
27
28
|
# File 'lib/sequel_spec/validation/validate_length_matcher.rb', line 24
def additionnal_param_check
unless validation_type && @additionnal
raise ArgumentError, "You should specify the type of validation using #is, #is_at_least, #is_at_most or #is_between"
end
end
|
#additionnal_param_required? ⇒ Boolean
20
21
22
|
# File 'lib/sequel_spec/validation/validate_length_matcher.rb', line 20
def additionnal_param_required?
true
end
|
#description ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/sequel_spec/validation/validate_length_matcher.rb', line 7
def description
desc = "validate that length of #{@attribute.inspect} "
desc << case validation_type
when :validates_exact_length then "is exactly"
when :validates_min_length then "is greater than or equal to"
when :validates_max_length then "is less than or equal to"
when :validates_length_range then "is included in"
end << " #{@additionnal.inspect}"
desc << " with option(s) #{hash_to_nice_string @options}" unless @options.empty?
desc
end
|
#is(value) ⇒ Object
Also known as:
is_equal_to
30
31
32
33
34
35
36
37
38
|
# File 'lib/sequel_spec/validation/validate_length_matcher.rb', line 30
def is(value)
unless value.is_a?(Fixnum)
raise ArgumentError, "#is expects a Fixnum, #{value.class} given"
end
@additionnal = value
@validation_type = :validates_exact_length
self
end
|
#is_at_least(value) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/sequel_spec/validation/validate_length_matcher.rb', line 42
def is_at_least(value)
unless value.is_a?(Fixnum)
raise ArgumentError, "#is_at_least expects a Fixnum, #{value.class} given"
end
@additionnal = value
@validation_type = :validates_min_length
self
end
|
#is_at_most(value) ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/sequel_spec/validation/validate_length_matcher.rb', line 52
def is_at_most(value)
unless value.is_a?(Fixnum)
raise ArgumentError, "#is_at_most expects a Fixnum, #{value.class} given"
end
@additionnal = value
@validation_type = :validates_max_length
self
end
|
#is_between(value) ⇒ Object
62
63
64
65
66
67
68
69
70
|
# File 'lib/sequel_spec/validation/validate_length_matcher.rb', line 62
def is_between(value)
unless value.is_a?(Range)
raise ArgumentError, "#is_between expects a Range, #{value.class} given"
end
@additionnal = value
@validation_type = :validates_length_range
self
end
|