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
base: main
Are you sure you want to change the base?
Conversation
end | ||
|
||
def test_sanitize_sql_for_order_from_docs | ||
skip "See https://github.com/rails/rails/issues/44312" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
84b6832
to
2c15acf
Compare
end | ||
|
||
def test_sanitize_sql_for_order_from_docs | ||
skip "See https://github.com/rails/rails/issues/44312" |
There was a problem hiding this comment.
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.
…ss MySQL/SQLite3/PostgreSQL adapters
2c15acf
to
c3ad4ca
Compare
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