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

Update transaction_from after #update. #100

Closed
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
1 change: 1 addition & 0 deletions lib/activerecord-bitemporal/bitemporal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ def _update_row(attribute_names, attempted_action = 'update')
# update 後に新しく生成したインスタンスのデータを移行する
@_swapped_id = after_instance.swapped_id
self.valid_from = after_instance.valid_from
self.transaction_from = after_instance.transaction_from

1
# MEMO: Must return false instead of nil, if `#_update_row` failure.
Expand Down
6 changes: 4 additions & 2 deletions spec/activerecord-bitemporal/bitemporal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -793,11 +793,13 @@ def employee.wrapped_name
end
end

describe "changed `valid_from` columns" do
describe "changed `valid_from` and `transaction_from` columns" do
let(:employee) { Employee.create(name: "Jane", emp_code: "001") }
subject { -> { employee.update(name: "Tom") } }
subject { -> { employee.update!(name: "Tom") } }

it { is_expected.to change(employee, :name).from("Jane").to("Tom") }
it { is_expected.to change(employee, :valid_from) }
it { is_expected.to change(employee, :transaction_from) }
# valid_to is fixed "9999/12/31"
it { is_expected.not_to change(employee, :valid_to) }
it { is_expected.not_to change(employee, :emp_code) }
Expand Down