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

Add support for text columns for secure matchers #1479

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

maxehmookau
Copy link

Issue

Currently, using the text datatype for the has_secure_token functionality is supported in Rails, but when used alongside shoulda-matchers it fails as the datatype must be string.

On codebases that use postgresql, there's no difference between using text or string and in most cases it makes sense to use text.

Proposed solution

Add support for text datatypes when using the have_secure_token matcher.

@maxehmookau maxehmookau marked this pull request as ready for review January 18, 2022 13:52
@maxehmookau
Copy link
Author

I'm really struggling to get appraisals working to run the specs locally so I'm not convinced this works yet. 😢

@@ -110,7 +110,7 @@ def has_expected_instance_methods?
end

def has_expected_db_column?
matcher = HaveDbColumnMatcher.new(token_attribute).of_type(:string)
matcher = HaveDbColumnMatcher.new(token_attribute).of_type(:string) || HaveDbColumnMatcher.new(token_attribute).of_type(:text)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is always going to return the first one, the one for :string. The reason is that this line merely returns a matcher object; it doesn't actually perform the matching. That happens in the next line.

What you probably want to do is:

matchers = [
  HaveDbColumnMatcher.new(token_attribute).of_type(:string),
  HaveDbColumnMatcher.new(token_attribute).of_type(:text)
]
matchers.any? { |matcher| matcher.matches?(@subject) }

@krainboltgreene
Copy link

Mind if I copy this PR with the requested changes so we can get this merged in?

@matsales28
Copy link
Collaborator

@krainboltgreene, sorry for the delayed response. I wasn't following this PR.

I'd say to feel free to copy this PR with the requested changes just make sure to also give credits to @maxehmookau

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.

None yet

4 participants