Allow model to set table_name after acts_as_paranoid macro #131
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I originally opened #117 without tests, and since then have deleted my fork, so reforked and opened this PR with a spec @mvz
Thought about also asserting that
ParanoidWithExplicitTableNameAfterMacro.only_deleted
is working since that's how I found the error, but I think this test is clearer what exactly we're testing. Lemme know what ya thinkparanoid_column_reference is currently a class attribute which is set
when a class is loaded and the acts_as_paranoid method is invoked. A
rails model can set its table_name after it declares itself as
acts_as_paranoid. This means that whenever paranoid_column_reference is
referenced in the gem it does not match the table_name for the model
which can cause errors.
e.g. ActsAsParanoid::Core#only_deleted references
paranoid_column_reference
so in the below examples when we call thismethod on the paranoid class it tries to look up a table_name matching
the model name. If the table doesn't exist a sql error is raised because
the table does not exist. If the table does exist (maybe you're moving
data to a new table and deprecating old ones) you'll end up returning
the old records.
This change makes it a method so that it returns whatever the current
value of table_name is