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

Change created_at and deleted_at to transaction_from and transaction_to #38

Merged
merged 22 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
108a853
Add columns `transaction_from` `transaction_to`.
osyo-manga Oct 31, 2019
2127209
Assign `deleted_at` to `transaction_to` when create.
osyo-manga Nov 14, 2019
3a2b1bb
Fix assign `transaction_form` `transaction_to`
osyo-manga Nov 14, 2019
213bf00
`update_columns` once.
osyo-manga Apr 8, 2020
9ec222b
Assign `Time.current` to `transaction_from` (`created_at`) when `vali…
osyo-manga Nov 18, 2019
9e94e4b
Assing `created_at` to `transaction_from` when created.
osyo-manga Nov 19, 2019
c13a249
Flooring to time.
osyo-manga Nov 19, 2019
4d63b64
No assign `transacton_from` to `created_at` when before create record.
osyo-manga Nov 20, 2019
1ab0916
Add test deleted_at equal transaction_to.
osyo-manga Nov 20, 2019
9c41b72
Assigne to `created_at` `deleted_at` when before create record.
osyo-manga Nov 20, 2019
d9f798e
Assign only if defined created_at and deleted_at.
osyo-manga Nov 20, 2019
1d4308e
Fix default transaction_from.
osyo-manga Jul 20, 2020
6a5225b
Add pending.
osyo-manga Aug 27, 2020
8bd896b
`deleted_at` value assign to `transaction_to`.
osyo-manga Aug 28, 2020
e125e1b
Check all attributes
osyo-manga Aug 28, 2020
27a5ac7
`create` is class method.
osyo-manga Aug 28, 2020
64cbb20
Set `precision` so that there is no difference between DB and applica…
osyo-manga Aug 28, 2020
35dc2ae
default value is same for `valid_from` and `transaction_from`.
osyo-manga Aug 28, 2020
cf96505
Don't `return` in block.
osyo-manga Aug 31, 2020
8546730
Fix deprecated warning.
osyo-manga Aug 31, 2020
0d18569
association `transaction_from` (`created_at`) have same value when cr…
osyo-manga Sep 1, 2020
962d3a9
Revert 0d18569ddfc0a527e8563c811da12b1e11a4b067 `association `transa…
osyo-manga Sep 2, 2020
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
Prev Previous commit
Next Next commit
Assing created_at to transaction_from when created.
  • Loading branch information
osyo-manga committed Aug 31, 2020
commit 9e94e4bed0ebda11ec72d322ef2e34ecad324523
2 changes: 2 additions & 0 deletions lib/activerecord-bitemporal/bitemporal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ def _create_record(attribute_names = self.attribute_names)
# 自身の `valid_from` を設定
self.valid_from = valid_datetime || Time.current if self.valid_from == ActiveRecord::Bitemporal::DEFAULT_VALID_FROM

self.transaction_from = self.created_at if changes.key?("created_at")

# アソシエーションの子に対して `valid_from` を設定
# MEMO: cache が存在しない場合、 public_send(reflection.name) のタイミングで新しくアソシエーションオブジェクトが生成されるが
# この時に何故か生成できずに落ちるケースがあるので cache しているアソシエーションに対してのみイテレーションする
Expand Down
25 changes: 23 additions & 2 deletions spec/activerecord-bitemporal/bitemporal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
end

describe ".create" do
let(:attributes) { {} }

context "creating" do
let(:attributes) { {} }
subject { -> { Employee.create!(name: "Tom", **attributes) } }
it { is_expected.to change(Employee, :call_after_save_count).by(1) }
end

context "created" do
let(:attributes) { {} }
subject { Employee.create!(name: "Tom", **attributes) }

context "with `bitemporal_id`" do
Expand Down Expand Up @@ -56,6 +56,27 @@
it { is_expected.to have_attributes(valid_from: time, valid_to: Time.utc(9999, 12, 31).in_time_zone) }
end
end

context "with transaction_from, created_at" do
context "only transaction_from" do
let(:transaction_from) { "2019/01/01".to_time }
subject { Employee.create(transaction_from: transaction_from) }
it { is_expected.to have_attributes(transaction_from: transaction_from, created_at: transaction_from) }
end

context "only created_at" do
let(:created_at) { "2019/01/01".to_time }
subject { Employee.create(created_at: created_at) }
it { is_expected.to have_attributes(created_at: created_at, transaction_from: created_at) }
end

context "created_at and transaction_from" do
let(:created_at) { "2019/01/01".to_time }
let(:transaction_from) { "2019/08/01".to_time }
subject { Employee.create(transaction_from: transaction_from, created_at: created_at) }
it { is_expected.to have_attributes(created_at: created_at, transaction_from: created_at) }
end
end
end

describe ".find" do
Expand Down