-
Notifications
You must be signed in to change notification settings - Fork 6
Add field counters to allow you to check if a field was referenced #37
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
Conversation
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.
Looks good, left some minor comments
| # @mission Infrastructure | ||
| # @team DEx | ||
|
|
||
| require 'logger' |
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.
Do you still need this?
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.
Yes, unfortunately there's a requirement from active_record in pre-Rails 7.1 versions :/
| # - Anything with ` {field} = ` (this could be a select, update, delete) | ||
| # - Anything with `, field,` in an INSERT (we need to check the values) | ||
| select_field_query = sql.match(MODEL_FIELDS_PATTERN) | ||
| # debugger if sql.match(/INSERT/) |
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.
Is this debugger line needed?
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.
For now it can stay, I do need to clean up the TODO.
Co-authored-by: Emily Chen <[email protected]>
|
@tenshiemi - mind re-approving this one if possible? 😄 |
Summary
The intent of this PR is to enable field counters and create two helpers:
query_by_fieldandquery_by_field_at_least. When trying to analyze changes to models, we may want to check if there's expected changes by looking for specific fields. In doing so, we can use this to test for changes by using the helpers above:query_by_fieldmatches the changes in fields to the expected changes exactly. If they do not match, the test will fail.query_by_field_at_leastmatches the changes in fields to the expected changes, but only matches the fields the expected changes have mentioned. For example, if fields A and B are changed but we only expect field A to change, if the actual values and the expected values for A are the same, we'll pass this test - regardless of what field B changes have been made, if any.query_by_field_at_least_ignore_notfoundmatches the changes in fields to the expected changes, similarly toquery_by_field_at_least, but when checking for changes to field A, if the expected changes are included in the actual changes but not the same, we will pass this test. For example, if field A is expected to contain the values [1,2] and the actual values are [1,2,3],query_by_field_at_least_ignore_notfoundwill succeed butquery_by_field_at_leastwould fail.