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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

matcher.matches?(@subject)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
expect(valid_model.new).to have_secure_token
end

it 'matches when the subject configures has_secure_token with the db using a text datatype' do
create_table(:users) do |t|
t.string :token
t.index :text, unique: true
end

valid_model = define_model_class(:User) { has_secure_token }

expect(valid_model.new).to have_secure_token
end

it 'matches when the subject configures has_secure_token with the db for ' \
'a custom attribute' do
create_table(:users) do |t|
Expand Down