-
Notifications
You must be signed in to change notification settings - Fork 64
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
Do not "touch" models when not updating the base table content. #65
Conversation
@jmfederico I don't believe your solution works because it does not save the nilified One thing to try would be to use a persistence method that doesn't run callbacks when nillifying the |
At this point there are only 2 tests failing. How can I detect that there are skipped fields that need saving on a model? |
After studying the code of Draftsman I decided that PAPERTRAIL saving or not saving versions has nothing to do with how this gem works. Instead I have to implement my own "versioning" logic. But, in the process, I noticed that the "updated_at" column of the original model was always being changed, even when the model itself wasn't changing. I then decided to change this so that it only is changed when the model itself changes. The idea is:
I wrote the necessary tests, BUT, for some reason there is one test failing on Travis, which is not failing on my local machine, and, from what I understand, it shouldn't be failing. There is an issue for it on Rails. Until I know which environment is misbehaving (my laptop or Travis) I am not making any changes to that specific test. |
And: thanks! |
Thank you. I will take a look here in a week or two to see if I can see something that you're not seeing. |
@jmfederico This is next on my list. I'm getting a Docker container set up so I can try running the specs on Linux. |
I have to say, Ruby and Rails are not my strong suit, but this makes no sense to me. time = skipper.updated_at
expect(subject.updated_at).to eq time
If they should behave differently, I would appreciate if you let me know why. (I feel a bit ignorant right now). Anyway, tests pass. I hope you find this useful. |
@jmfederico I believe that those two snippets should behave differently. Let me explain what's going on in the first example with comments: # Caches `skipper.updated_at` into a variable named `time` before query is
# run.
time = skipper.updated_at
# Runs query, reloads `skipper` record, and then compares its `updated_at`
# value to the cached `time` value.
expect(subject.updated_at).to eq time And the second example: # Runs query, reloads `skipper` record, then compares it with itself.
expect(subject.updated_at).to eq skipper.updated_at To me, this is evidence that perhaps the functionality is wrong, even if the test is passing. What do you think? |
Needed to force DB precison on Datetime values.
First, thanks for the explanation, it helped a lot. Second, I think I found the problem. It has to do with microseconds precision. I will try to explain it to best of my abilities. When creating a new Object that has not been persisted, the updated_at property has 7 decimals for microseconds, but as soon as it gets reloaded, the precision changes to 6 decimals. But this only happens in Linux, not on MacOS, thats why it wasn't failing for me. Example, given this code (Line 155 of spec/models/skipper_spec.rb): context 'with existing `create` draft' do
before do
skipper.save_draft
print skipper.updated_at.to_f
print "\n"
skipper.reload
print skipper.updated_at.to_f
print "\n"
end Output for Docker:
Output for MacOS:
The test was ok before, but skipper needs to be reloaded as soon as |
@jmfederico I think I am going to name the next release after you. Many thanks for your persistence on this. |
@chrisdpeters I am glad you find this useful. Thank you for a great gem! |
* 'master' of github.com:liveeditor/draftsman: Do not "touch" models when not updating the base table content. (#65)
I use this GEM next to PAPER TRAIL, and found too may versions being stored by PAPER TRAIL with no changes between them. I tracked it down to this gem saving a widget after destroying a draft when the record was changed back to the original values.
To me it makes sense not to save the widget, as no changes are being saved to it.
Makes sense?