mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
![Kapil Sachdev](/assets/img/avatar_default.png)
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
63 lines
1.3 KiB
Ruby
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
|