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

Add next_id field to timestamp record #195

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion lib/glueby/contract/active_record/timestamp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ class Timestamp < ::ActiveRecord::Base

attr_reader :tx

belongs_to :prev, class_name: 'Glueby::Contract::AR::Timestamp', optional: true
belongs_to :prev, class_name: 'Glueby::Contract::AR::Timestamp', inverse_of: :next, optional: true
has_one :next, class_name: 'Glueby::Contract::AR::Timestamp', foreign_key: 'prev_id'

def next_id
self.next&.id
end

validate :validate_prev

Expand Down Expand Up @@ -114,6 +119,7 @@ def save_with_broadcast!(fee_estimator: Glueby::Contract::FeeEstimator::Fixed.ne

if update_trackable?
prev.latest = false
prev.next = self
prev.save!
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,14 @@
expect(timestamp.p2c_address).not_to be_nil
expect(timestamp.payment_base).not_to be_nil
expect(timestamp.latest).to be_truthy
expect(timestamp.next_id).to be_nil
end

it 'update previous timestamp\'s latest falg to false' do
it 'update previous timestamp\'s latest falg and next_id' do
Yamaguchi marked this conversation as resolved.
Show resolved Hide resolved
subject
expect(prev.reload.latest).to be_falsey
prev.reload
expect(prev.latest).to be_falsey
expect(prev.next_id).to eq timestamp.id
end

context 'previous timestamp type is not trackable' do
Expand Down
Loading