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

Update tests and docs for ActiveRecord::Sanitization #44429

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

Conversation

kmcphillips
Copy link
Contributor

Summary

In trying to write some failing test cases for #44312, I found that most of ActiveRecord::Sanitization is untested. Only a subset of it has test coverage, and much of that coverage is agnostic to the underlying connection adapter.

And that last part is the interesting part. The result of all but one of the public sanitization methods in this module depend on the current ActiveRecord::Base.connection to decide how to escape the string, and that is not reflected in docs or in tests.

I have added comprehensive test coverage local to each adapter. The tests use all the examples in the inline docs, many of which were wrong.

Next, I will use the tests to work on #44404, and they also would have caught the regression in #44312. I updated the docs to reflect the connection dependent behaviour, and updated the cases where the output shown was not what is actually output. I have opted to use the SQLite3/PostgreSQL behaviour in docs as they are both (currently) the same, and presumably SQLite3 is the simplest use case.

I understand that typically PRs of just tests are not merged. Feedback welcome.

@rafaelfranca @byroot

end

def test_sanitize_sql_for_order_from_docs
skip "See https://github.com/rails/rails/issues/44312"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is currently broken #44312 and is what I am working to fix next.

Copy link
Member

Choose a reason for hiding this comment

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

Best to fix it all in the same PR, I'd be worried the skip may be forgotten otherwise.

assert_equal expected, actual
end

def test_sanitize_sql_like_from_docs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically the like tests do not depend on the connection adapter. But they easily could in future. I always opt for better and proactive test coverage, so added the same tests in all three adapters.

@kmcphillips kmcphillips force-pushed the ar-sanitization-docs branch 2 times, most recently from 84b6832 to 2c15acf Compare February 14, 2022 19:26
activerecord/test/cases/adapters/mysql2/sanitize_test.rb Outdated Show resolved Hide resolved
end

def test_sanitize_sql_for_order_from_docs
skip "See https://github.com/rails/rails/issues/44312"
Copy link
Member

Choose a reason for hiding this comment

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

Best to fix it all in the same PR, I'd be worried the skip may be forgotten otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants