Skip to content

Commit

Permalink
Check all attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
osyo-manga committed Aug 31, 2020
1 parent 8bd896b commit e125e1b
Showing 1 changed file with 56 additions and 12 deletions.
68 changes: 56 additions & 12 deletions spec/activerecord-bitemporal/transaction_at_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,48 +43,92 @@
let(:_04_01) { "2020/04/01".to_time }
let(:_08_01) { "2020/08/01".to_time }
let(:_12_01) { "2020/12/01".to_time }
subject { Company.create(params) }
let(:time_current) { Time.current.round(6) }
subject { Timecop.freeze(time_current) { Company.create(params) } }

context "params is empty" do
let(:params) { {} }
it { expect(subject.created_at.iso8601(6)).to eq subject.transaction_from.iso8601(6) }
it { expect(subject.deleted_at).to eq nil }
it { expect(subject.transaction_to).to eq ActiveRecord::Bitemporal::DEFAULT_TRANSACTION_TO }
it { is_expected.to have_attributes(
created_at: time_current,
transaction_from: time_current,
deleted_at: nil,
transaction_to: ActiveRecord::Bitemporal::DEFAULT_TRANSACTION_TO
) }
end

context "set `created_at`" do
let(:params) { { created_at: _01_01 } }
it { is_expected.to have_attributes(created_at: _01_01, transaction_from: _01_01) }
it { is_expected.to have_attributes(
created_at: _01_01,
transaction_from: _01_01,
deleted_at: nil,
transaction_to: ActiveRecord::Bitemporal::DEFAULT_TRANSACTION_TO
) }
end
context "set `transaction_from`" do
let(:params) { { transaction_from: _01_01 } }
it { is_expected.to have_attributes(created_at: _01_01, transaction_from: _01_01) }
it { is_expected.to have_attributes(
created_at: _01_01,
transaction_from: _01_01,
deleted_at: nil,
transaction_to: ActiveRecord::Bitemporal::DEFAULT_TRANSACTION_TO
) }
end
context "set `created_at` and `transaction_from`" do
let(:params) { { created_at: _01_01, transaction_from: _04_01 } }
it { is_expected.to have_attributes(created_at: _01_01, transaction_from: _01_01) }
it { is_expected.to have_attributes(
created_at: _01_01,
transaction_from: _01_01,
deleted_at: nil,
transaction_to: ActiveRecord::Bitemporal::DEFAULT_TRANSACTION_TO
) }
end

context "set `deleted_at`" do
let(:params) { { deleted_at: _01_01 } }
it { is_expected.to have_attributes(deleted_at: _01_01, transaction_to: _01_01) }
it { is_expected.to have_attributes(
created_at: time_current,
transaction_from: time_current,
deleted_at: _01_01,
transaction_to: _01_01
) }

context "to `nil`" do
let(:params) { { deleted_at: nil } }
it { is_expected.to have_attributes(deleted_at: nil, transaction_to: ActiveRecord::Bitemporal::DEFAULT_TRANSACTION_TO) }
it { is_expected.to have_attributes(
created_at: time_current,
transaction_from: time_current,
deleted_at: nil,
transaction_to: ActiveRecord::Bitemporal::DEFAULT_TRANSACTION_TO
) }
end
end
context "set `transaction_to`" do
let(:params) { { transaction_to: _01_01 } }
it { is_expected.to have_attributes(deleted_at: _01_01, transaction_to: _01_01) }
it { is_expected.to have_attributes(
created_at: time_current,
transaction_from: time_current,
deleted_at: _01_01,
transaction_to: _01_01
) }
end
context "set `deleted_at` and `transaction_to`" do
let(:params) { { deleted_at: _01_01, transaction_to: _04_01 } }
it { is_expected.to have_attributes(deleted_at: _01_01, transaction_to: _01_01) }
it { is_expected.to have_attributes(
created_at: time_current,
transaction_from: time_current,
deleted_at: _01_01,
transaction_to: _01_01
) }

context "`deleted_at` to `nil`" do
let(:params) { { deleted_at: nil, transaction_to: _04_01 } }
it { is_expected.to have_attributes(deleted_at: _04_01, transaction_to: _04_01) }
it { is_expected.to have_attributes(
created_at: time_current,
transaction_from: time_current,
deleted_at: _04_01,
transaction_to: _04_01
) }
end
end
end
Expand Down

0 comments on commit e125e1b

Please sign in to comment.