1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00
thoughtbot--shoulda-matchers/lib/shoulda/matchers/active_model/validation_message_finder.rb
Kapil Sachdev 3e88500318 fix(rubocop): Fix Style, Layout, Lint and other offenses [ci skip]
Updated Layout/LineLength cop to Max 120 lenght and ignore everything 
inside specs/**/*

Added rules for below cops in .rubocop.yml
Lint/AmbiguousBlockAssociation
Naming/HeredocDelimiterNaming
Rails/SkipsModelValidations
Style/FormatStringToken


Fixed below mentioned cops:
- Layout/CaseIndentation
- Layout/DotPosition
- Layout/ElseAlignment
- Layout/IndentationWidth
- Layout/LineLength
- Layout/MultilineBlockLayout
- Layout/MultilineOperationIndentation
- Lint/AmbiguousBlockAssociation
- Lint/MissingCopEnableDirective
- Lint/NestedMethodDefinition
- Lint/RedundantCopDisableDirective
- Lint/RedundantRequireStatement
- Lint/UnusedBlockArgument
- Lint/UnusedMethodArgument
- Metrics/ModuleLength
- Naming/MemoizedInstanceVariableName
- Naming/RescuedExceptionsVariableName
- Rails/Output
- Rails/Presence
- Security/Eval
- Security/Open
- Style/ClassCheck
- Style/CollectionMethods
- Style/ConditionalAssignment
- Style/EvalWithLocation
- Style/FormatStringToken
- Style/InverseMethods
- Style/MutableConstant
- Style/ParallelAssignment
- Style/RedundantBegin
- Style/RedundantCondition
- Style/RedundantInterpolation
- Style/RedundantSelf
- Style/RedundantSort
- Style/RescueStandardError
- Style/SafeNavigation
- Style/StringLiteralsInInterpolation
- Style/SymbolProc
2020-11-03 10:05:25 -07:00

63 lines
1.3 KiB
Ruby

module Shoulda
module Matchers
module ActiveModel
# @private
class ValidationMessageFinder
include Helpers
def initialize(instance, attribute, context = nil)
@instance = instance
@attribute = attribute
@context = context
end
def allow_description(allowed_values)
"allow #{@attribute} to be set to #{allowed_values}"
end
def expected_message_from(attribute_message)
attribute_message
end
def has_messages?
errors.present?
end
def source_description
'errors'
end
def messages_description
if errors.empty?
' no errors'
else
" errors:\n#{pretty_error_messages(validated_instance)}"
end
end
def messages
Array(messages_for_attribute)
end
private
def messages_for_attribute
errors[@attribute]
end
def errors
validated_instance.errors
end
def validated_instance
@_validated_instance ||= validate_instance
end
def validate_instance
@instance.valid?(*@context)
@instance
end
end
end
end
end