Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecation warning for uniqueness matcher (Rails 4.2) #1073

Merged
merged 1 commit into from
Jan 24, 2018

Conversation

mcmire
Copy link
Collaborator

@mcmire mcmire commented Jan 24, 2018

The uniqueness matcher needs to set the attributes under test (which is
not only the attribute you give to the matcher, but also any scope
attributes as well) to arbitrary values so that it can test the
underlying uniqueness validation logic. To set an attribute correctly,
it needs to check what type of column that attribute is and then
generate a value that matches the column (otherwise unpredictable
results happen). The matcher was doing this for scope attributes, but
not for the main attribute. One of the consequences of this
inconsistency is that when setting a boolean attribute, it was using a
string value, which generates a warning under Rails 4.2.

This commit fixes this so that the main attribute is set the same way as
scope attributes, thereby removing the warning.


This fixes #949.

Copy link

@houndci-bot houndci-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some files could not be reviewed due to errors:

.rubocop.yml: Style/AccessModifierIndentation has the wrong namespace - shoul...
.rubocop.yml: Style/AccessModifierIndentation has the wrong namespace - should be Layout
.rubocop.yml: Style/AlignHash has the wrong namespace - should be Layout
.rubocop.yml: Style/AlignParameters has the wrong namespace - should be Layout
.rubocop.yml: Style/CaseIndentation has the wrong namespace - should be Layout
.rubocop.yml: Style/DotPosition has the wrong namespace - should be Layout
.rubocop.yml: Style/EmptyLineBetweenDefs has the wrong namespace - should be Layout
.rubocop.yml: Style/EmptyLinesAroundBlockBody has the wrong namespace - should be Layout
.rubocop.yml: Style/EmptyLinesAroundClassBody has the wrong namespace - should be Layout
.rubocop.yml: Style/EmptyLinesAroundModuleBody has the wrong namespace - should be Layout
.rubocop.yml: Style/FileName has the wrong namespace - should be Naming
.rubocop.yml: Style/FirstParameterIndentation has the wrong namespace - should be Layout
.rubocop.yml: Style/IndentationWidth has the wrong namespace - should be Layout
.rubocop.yml: Style/IndentHash has the wrong namespace - should be Layout
.rubocop.yml: Style/MethodName has the wrong namespace - should be Naming
.rubocop.yml: Style/MultilineMethodCallIndentation has the wrong namespace - should be Layout
.rubocop.yml: Style/MultilineOperationIndentation has the wrong namespace - should be Layout
.rubocop.yml: Style/PredicateName has the wrong namespace - should be Naming
.rubocop.yml: Style/SpaceAroundBlockParameters has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceAroundEqualsInParameterDefault has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceBeforeBlockBraces has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceInsideBlockBraces has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceInsideHashLiteralBraces has the wrong namespace - should be Layout
.rubocop.yml: Style/TrailingBlankLines has the wrong namespace - should be Layout
.rubocop.yml: Style/VariableName has the wrong namespace - should be Naming
.rubocop.yml: Style/ExtraSpacing has the wrong namespace - should be Layout
.rubocop.yml: Style/AccessorMethodName has the wrong namespace - should be Naming
.rubocop.yml: Style/AlignArray has the wrong namespace - should be Layout
.rubocop.yml: Style/AsciiIdentifiers has the wrong namespace - should be Naming
.rubocop.yml: Style/BlockEndNewline has the wrong namespace - should be Layout
.rubocop.yml: Style/ClassAndModuleCamelCase has the wrong namespace - should be Naming
.rubocop.yml: Style/CommentIndentation has the wrong namespace - should be Layout
.rubocop.yml: Style/ConstantName has the wrong namespace - should be Naming
.rubocop.yml: Style/ElseAlignment has the wrong namespace - should be Layout
.rubocop.yml: Style/EmptyLines has the wrong namespace - should be Layout
.rubocop.yml: Style/EmptyLinesAroundAccessModifier has the wrong namespace - should be Layout
.rubocop.yml: Style/EmptyLinesAroundMethodBody has the wrong namespace - should be Layout
.rubocop.yml: Style/EndOfLine has the wrong namespace - should be Layout
.rubocop.yml: Style/IndentationConsistency has the wrong namespace - should be Layout
.rubocop.yml: Style/IndentArray has the wrong namespace - should be Layout
.rubocop.yml: Style/LeadingCommentSpace has the wrong namespace - should be Layout
.rubocop.yml: Style/MultilineBlockLayout has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceBeforeFirstArg has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceAfterColon has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceAfterComma has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceAroundKeyword has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceAfterMethodName has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceAfterNot has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceAfterSemicolon has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceBeforeComma has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceBeforeComment has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceBeforeSemicolon has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceAroundOperators has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceInsideBrackets has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceInsideParens has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceInsideRangeLiteral has the wrong namespace - should be Layout
.rubocop.yml: Style/Tab has the wrong namespace - should be Layout
.rubocop.yml: Style/TrailingWhitespace has the wrong namespace - should be Layout
Error: The `Lint/InvalidCharacterLiteral` cop has been removed since it was never being actually triggered.
(obsolete configuration found in .rubocop.yml, please update it)
The `Style/OpMethod` cop has been renamed and moved to `Naming/BinaryOperatorParameterName`.
obsolete parameter EnforcedStyle (for Style/Encoding) found in .rubocop.yml
Style/Encoding no longer supports styles. The "never" behavior is always assumed.
obsolete parameter SupportedStyles (for Style/Encoding) found in .rubocop.yml

The uniqueness matcher needs to set the attributes under test (which is
not only the attribute you give to the matcher, but also any scope
attributes as well) to arbitrary values so that it can test the
underlying uniqueness validation logic. To set an attribute correctly,
it needs to check what type of column that attribute is and then
generate a value that matches the column (otherwise unpredictable
results happen). The matcher was doing this for scope attributes, but
not for the main attribute. One of the consequences of this
inconsistency is that when setting a boolean attribute, it was using a
string value, which generates a warning under Rails 4.2.

This commit fixes this so that the main attribute is set the same way as
scope attributes, thereby removing the warning.
@mcmire mcmire force-pushed the fix-deprecation-warning-for-uniqueness branch from 0b40e0e to 9103ead Compare January 24, 2018 05:16
Copy link

@houndci-bot houndci-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some files could not be reviewed due to errors:

.rubocop.yml: Style/AccessModifierIndentation has the wrong namespace - shoul...
.rubocop.yml: Style/AccessModifierIndentation has the wrong namespace - should be Layout
.rubocop.yml: Style/AlignHash has the wrong namespace - should be Layout
.rubocop.yml: Style/AlignParameters has the wrong namespace - should be Layout
.rubocop.yml: Style/CaseIndentation has the wrong namespace - should be Layout
.rubocop.yml: Style/DotPosition has the wrong namespace - should be Layout
.rubocop.yml: Style/EmptyLineBetweenDefs has the wrong namespace - should be Layout
.rubocop.yml: Style/EmptyLinesAroundBlockBody has the wrong namespace - should be Layout
.rubocop.yml: Style/EmptyLinesAroundClassBody has the wrong namespace - should be Layout
.rubocop.yml: Style/EmptyLinesAroundModuleBody has the wrong namespace - should be Layout
.rubocop.yml: Style/FileName has the wrong namespace - should be Naming
.rubocop.yml: Style/FirstParameterIndentation has the wrong namespace - should be Layout
.rubocop.yml: Style/IndentationWidth has the wrong namespace - should be Layout
.rubocop.yml: Style/IndentHash has the wrong namespace - should be Layout
.rubocop.yml: Style/MethodName has the wrong namespace - should be Naming
.rubocop.yml: Style/MultilineMethodCallIndentation has the wrong namespace - should be Layout
.rubocop.yml: Style/MultilineOperationIndentation has the wrong namespace - should be Layout
.rubocop.yml: Style/PredicateName has the wrong namespace - should be Naming
.rubocop.yml: Style/SpaceAroundBlockParameters has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceAroundEqualsInParameterDefault has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceBeforeBlockBraces has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceInsideBlockBraces has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceInsideHashLiteralBraces has the wrong namespace - should be Layout
.rubocop.yml: Style/TrailingBlankLines has the wrong namespace - should be Layout
.rubocop.yml: Style/VariableName has the wrong namespace - should be Naming
.rubocop.yml: Style/ExtraSpacing has the wrong namespace - should be Layout
.rubocop.yml: Style/AccessorMethodName has the wrong namespace - should be Naming
.rubocop.yml: Style/AlignArray has the wrong namespace - should be Layout
.rubocop.yml: Style/AsciiIdentifiers has the wrong namespace - should be Naming
.rubocop.yml: Style/BlockEndNewline has the wrong namespace - should be Layout
.rubocop.yml: Style/ClassAndModuleCamelCase has the wrong namespace - should be Naming
.rubocop.yml: Style/CommentIndentation has the wrong namespace - should be Layout
.rubocop.yml: Style/ConstantName has the wrong namespace - should be Naming
.rubocop.yml: Style/ElseAlignment has the wrong namespace - should be Layout
.rubocop.yml: Style/EmptyLines has the wrong namespace - should be Layout
.rubocop.yml: Style/EmptyLinesAroundAccessModifier has the wrong namespace - should be Layout
.rubocop.yml: Style/EmptyLinesAroundMethodBody has the wrong namespace - should be Layout
.rubocop.yml: Style/EndOfLine has the wrong namespace - should be Layout
.rubocop.yml: Style/IndentationConsistency has the wrong namespace - should be Layout
.rubocop.yml: Style/IndentArray has the wrong namespace - should be Layout
.rubocop.yml: Style/LeadingCommentSpace has the wrong namespace - should be Layout
.rubocop.yml: Style/MultilineBlockLayout has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceBeforeFirstArg has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceAfterColon has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceAfterComma has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceAroundKeyword has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceAfterMethodName has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceAfterNot has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceAfterSemicolon has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceBeforeComma has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceBeforeComment has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceBeforeSemicolon has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceAroundOperators has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceInsideBrackets has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceInsideParens has the wrong namespace - should be Layout
.rubocop.yml: Style/SpaceInsideRangeLiteral has the wrong namespace - should be Layout
.rubocop.yml: Style/Tab has the wrong namespace - should be Layout
.rubocop.yml: Style/TrailingWhitespace has the wrong namespace - should be Layout
Error: The `Lint/InvalidCharacterLiteral` cop has been removed since it was never being actually triggered.
(obsolete configuration found in .rubocop.yml, please update it)
The `Style/OpMethod` cop has been renamed and moved to `Naming/BinaryOperatorParameterName`.
obsolete parameter EnforcedStyle (for Style/Encoding) found in .rubocop.yml
Style/Encoding no longer supports styles. The "never" behavior is always assumed.
obsolete parameter SupportedStyles (for Style/Encoding) found in .rubocop.yml

@mcmire mcmire merged commit 9103ead into master Jan 24, 2018
@mcmire mcmire deleted the fix-deprecation-warning-for-uniqueness branch January 24, 2018 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rails 5 depreciation warning validate_uniqueness_of for multiple scopes
2 participants