-
Notifications
You must be signed in to change notification settings - Fork 44
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
Apply irrelevant changes caused by touch #140
base: master
Are you sure you want to change the base?
Conversation
@@ -329,6 +329,10 @@ def _update_row(attribute_names, attempted_action = 'update') | |||
self.transaction_from = after_instance.transaction_from | |||
self.transaction_to = after_instance.transaction_to | |||
|
|||
if attempted_action == 'touch' | |||
@_touch_attr_names += Set.new(['valid_from', 'valid_to', 'transaction_from', 'transaction_to']) |
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.
Append to an instance variable used by ActiveRecord::AttributeMethods::Dirty#_touch_row
.
https://github.com/rails/rails/blob/v7.0.6/activerecord/lib/active_record/attribute_methods/dirty.rb#L187
This is probably not a good approach, but it's the only way to write out to the saved_changes
at once with minimal changes.
@@ -27,10 +27,13 @@ | |||
it { | |||
is_expected.to have_attributes( | |||
bitemporal_id: subject.id, | |||
# changes: be_empty, |
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.
Perhaps the expected is be_empty
, but unfortunately that is not the case at this time. This will be fixed in another PR.
@@ -1052,6 +1072,8 @@ class EmployeeWithUniquness < Employee | |||
it { expect { subject }.to change { Employee.ignore_valid_datetime.within_deleted.count }.by(1) } | |||
it { expect { subject }.to change(employee, :swapped_id).from(@swapped_id_before_destroy).to(kind_of(Integer)) } | |||
it { expect { subject }.to change(employee, :swapped_id_previously_was).from(kind_of(Integer)).to(@swapped_id_before_destroy) } | |||
xit { expect { subject }.to change(employee, :changes).to(be_empty) } |
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.
Perhaps the expected is be_empty
, but unfortunately that is not the case at this time. This will be fixed in another PR.
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.
LGTM
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.
LGTM
204ac82
to
7d96d90
Compare
This PR is frozen because #148 may fix this issue. |
While doing some research, I noticed that models that include
ActiveRecord::Bitemporal
have unintended changes after being touched:Perhaps adding changes unintentionally is not the expected behavior.
This PR changes the
changes
caused bytouch
to be movedsaved_changes
:As a side note, I noticed that unlike the non-bitemporal model, there was an issue where the dirty state before
touch
was unintentionally saved, but that's an issue that should be addressed in another PR.