Class: Shoulda::ActiveRecord::Matchers::EnsureLengthOfMatcher
Overview
Instance Attribute Summary
#failure_message
Instance Method Summary
collapse
Methods included from Helpers
#default_error_message, #pretty_error_messages
#initialize, #negative_failure_message
Instance Method Details
#description ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb', line 69
def description
description = "ensure #{@attribute} has a length "
if @minimum && @maximum
if @minimum == @maximum
description << "of exactly #{@minimum}"
else
description << "between #{@minimum} and #{@maximum}"
end
else
description << "of at least #{@minimum}" if @minimum
description << "of at most #{@maximum}" if @maximum
end
description
end
|
#is_at_least(length) ⇒ Object
39
40
41
42
43
|
# File 'lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb', line 39
def is_at_least(length)
@minimum = length
@short_message ||= :too_short
self
end
|
#is_at_most(length) ⇒ Object
45
46
47
48
49
|
# File 'lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb', line 45
def is_at_most(length)
@maximum = length
@long_message ||= :too_long
self
end
|
#is_equal_to(length) ⇒ Object
51
52
53
54
55
56
|
# File 'lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb', line 51
def is_equal_to(length)
@minimum = length
@maximum = length
@short_message ||= :wrong_length
self
end
|
#matches?(subject) ⇒ Boolean
84
85
86
87
88
89
90
91
92
|
# File 'lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb', line 84
def matches?(subject)
super(subject)
translate_messages!
disallows_lower_length &&
allows_minimum_length &&
((@minimum == @maximum) ||
(disallows_higher_length &&
allows_maximum_length))
end
|
#with_long_message(message) ⇒ Object
64
65
66
67
|
# File 'lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb', line 64
def with_long_message(message)
@long_message = message if message
self
end
|
#with_short_message(message) ⇒ Object
Also known as:
with_message
58
59
60
61
|
# File 'lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb', line 58
def with_short_message(message)
@short_message = message if message
self
end
|