Class: Shoulda::Matchers::ActiveModel::Validator
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ActiveModel::Validator
show all
- Includes:
- Helpers
- Defined in:
- lib/shoulda/matchers/active_model/validator.rb
Instance Method Summary
collapse
Methods included from Helpers
#default_error_message, #format_validation_errors, #pretty_error_messages
Constructor Details
#initialize(record, attribute, options = {}) ⇒ Validator
Returns a new instance of Validator.
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/shoulda/matchers/active_model/validator.rb', line 8
def initialize(record, attribute, options = {})
@record = record
@attribute = attribute
@context = options[:context]
@expects_strict = options[:expects_strict]
@expected_message = options[:expected_message]
@_validation_result = nil
@captured_validation_exception = false
@captured_range_error = false
end
|
Instance Method Details
40
41
42
|
# File 'lib/shoulda/matchers/active_model/validator.rb', line 40
def all_formatted_validation_error_messages
format_validation_errors(all_validation_errors)
end
|
#call ⇒ Object
20
21
22
|
# File 'lib/shoulda/matchers/active_model/validator.rb', line 20
def call
!messages_match? && !captured_range_error?
end
|
#captured_validation_exception? ⇒ Boolean
32
33
34
|
# File 'lib/shoulda/matchers/active_model/validator.rb', line 32
def captured_validation_exception?
@captured_validation_exception
end
|
#has_any_errors? ⇒ Boolean
28
29
30
|
# File 'lib/shoulda/matchers/active_model/validator.rb', line 28
def has_any_errors?
record.errors.any?
end
|
#has_messages? ⇒ Boolean
24
25
26
|
# File 'lib/shoulda/matchers/active_model/validator.rb', line 24
def has_messages?
messages.any?
end
|
#type_of_message_matched? ⇒ Boolean
36
37
38
|
# File 'lib/shoulda/matchers/active_model/validator.rb', line 36
def type_of_message_matched?
expects_strict? == captured_validation_exception?
end
|
#validation_exception_message ⇒ Object
44
45
46
|
# File 'lib/shoulda/matchers/active_model/validator.rb', line 44
def validation_exception_message
validation_result[:validation_exception_message]
end
|