-
-
Notifications
You must be signed in to change notification settings - Fork 525
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
Don't save templated journal entries if the received raw text is the same as the template itself #1653
Conversation
…same as the template itself
@Briscoooe I just wanted to say that, even though this is a small PR, we really appreciate the thoughtfulness that's clearly apparent in your contribution. Your filed issue was clear and concise, your considerations in this PR are right on the mark, and you match the style of the codebase perfectly. Thank you, and I hope you'll consider continuing to contribute to jrnl! |
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.
Thanks for this. Looks great to me so far, and I appreciate your thoughtful comments about this issue.
I think the performance issue you mentioned is acceptable, since jrnl already has much larger I/O performance issues (like loading an entire journal even when only a subset of the data needs to be retrieved) that I don't think this would ever be noticeable to a user. However, if you'd like to tackle it, you're more than welcome to do so.
I do think a test is necessary for this PR to be complete, however. I've just added a template test feature file and it's been merged into develop. Feel free to add on a test to that file for this, and let us know if you'd like any help with it.
First, thanks @wren and @micahellison! Huge fan of the project and happy to continue contributing. And @micahellison I see the test feature you've added but my changes cause all of them to fail, which is actually the intended behaviour on my end. The expected output of the test is simply the contents of the template, unchanged. Is there any way to make a templated entry, with additions, from the command line without requiring an external editor? i.e. something like:
Which would make the entry:
Without this I'm not sure how my PR could pass this test fixture |
I see what you mean. Do feel free to modify the test as necessary, since this PR is very much intended to change that behavior. I just wanted to get some scaffolding in there for further template testing.
No, there isn't. Maybe there should be, but that would be a separate enhancement. I think to get this PR covered by tests, there needs to be a version of the current template test that ensures no entries are modified, plus another similar test that confirms entries are modified when using this step:
There's a good example of this in |
My bad I temporarily discarded my changes during merge, accidentally closing the PR. Reopening. Can you expand on what you mean by
|
Sorry, I should've said "no entry" rather than "no entries." Basically, it should test the "happy path" of this feature, that if the entry is the same as the template, the entry isn't saved to the journal. Then there should be an opposite test that confirms that when the entry differs from the template, the entry is saved to the journal. |
EditIn pursuit of understanding how the
This is the test I can't produce. The changes in my PR cause the current version of this test ( Here is the current test:
This will always fail for my feature as there are no changes made to the template. The test attempts to simply save the unmodified template as an entry. To try and change the templated entry contents during the test I tried some of the Here is what I mean.
And the output:
You can see that if you try and I can easily write a happy path test for this feature as the current template test already satisfies it. The problem is now successfully saving a templated entry, with changes from the original template, during a test. |
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.
The tests look great! Thanks for your work on this.
…same as the template itself (jrnl-org#1653)
…same as the template itself
Checklist
for the same issue.
Issue number #1652
I did not add tests for this as I wasn't sure if adding a blocking processes for testing the external editor was the correct thing to do. I also noticed there are currently no tests that test templates. Let me know if this is correct and I can add.
One thing that's not optimised about the PR is that
_get_editor_template
function, which performs file I/O, is called twice:The alternative to calling it twice is changing the
_write_in_editor
and/orwrite_mode
function(s) to read the template in once at the start and pass it as a variable. I can make this change if necessary but thought it was safer to just check again and allow the duplicate I/O operation.