Skip to content
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

Suppress changes after creating with bitemporal_id #144

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/activerecord-bitemporal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ def load_schema!
module InstanceMethods
include ActiveRecord::Bitemporal::Persistence

def swap_id!(without_clear_changes_information: false)
def swap_id!
@_swapped_id_previously_was = nil
@_swapped_id = self.id
self.id = self.send(bitemporal_id_key)
clear_attribute_changes([:id]) unless without_clear_changes_information
clear_attribute_changes([:id])
end

def swapped_id
Expand Down Expand Up @@ -140,7 +140,7 @@ def bitemporalize(
after_create do
# MEMO: #update_columns is not call #_update_row (and validations, callbacks)
update_columns(bitemporal_id_key => swapped_id) unless send(bitemporal_id_key)
swap_id!(without_clear_changes_information: true)
swap_id!
end

after_find do
Expand Down
2 changes: 2 additions & 0 deletions spec/activerecord-bitemporal/bitemporal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
it {
is_expected.to have_attributes(
bitemporal_id: subject.id,
changes: be_empty,
previous_changes: include(
"id" => [nil, subject.swapped_id],
"valid_from" => [nil, be_present],
Expand All @@ -42,6 +43,7 @@
it {
is_expected.to have_attributes(
bitemporal_id: subject.id,
changes: be_empty,
previous_changes: include(
"id" => [nil, subject.id],
"valid_from" => [nil, be_present],
Expand Down