You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This test is failing sometimes. Maybe 50% of the time?
RSpec.describe Model, type: :model do
let(:model) { create(:model) }
it 'has paper trial' do
model.first_event!('updated_by_test')
model.second_event!('updated_by_test')
expect(model.versions.count).to eq(3)
end
end
Papertrail should have 3 version; the nil -> create, and the two from the events. When it works, Papertrail has the expected values. When it doesn't, papertrail has zero versions.
To Reproduce
(Note: Code is sanitized from our codebase. It's possible there's something else in our codebase that's messing with things)
Model:
class Model< ApplicationRecord
include AASM
has_paper_trail
after_commit do
puts "PT shows #{self.versions.count} versions"
end
aasm column: :state do
state :first_state, initial: true
state :second_state
state :third_state
end
before_all_events do |attribution|
self.paper_trail_event = aasm.current_event
self.updated_by = attribution
end
event :first_event do
transitions from: :first_state, to: :second_state
end
event :second_event do
transitions from: :second_state, to: :third_state
end
end
end
On success, console shows:
% rspec spec/models/model_spec.rb:7
Model
PT shows 1 versions
PT shows 2 versions
PT shows 3 versions
has paper trial
Finished in 0.06665 seconds (files took 2.22 seconds to load)
1 example, 0 failures
On failure, console shows:
% rspec spec/models/model_spec.rb:7
Model
PT shows 0 versions
PT shows 0 versions
PT shows 0 versions
has paper trial (FAILED - 1)
Failures:
1) Model has paper trial
Failure/Error: expect(transfer.versions.count).to eq(3)
expected: 3
got: 0
(compared using ==)
# ./spec/models/model_spec.rb:12:in `block (2 levels) in <top (required)>'
Finished in 0.0655 seconds (files took 2.19 seconds to load)
1 example, 1 failure
Expected behavior
Papertrail should reliably record versions when AASM events cause database updates.
Additional context
We have another model in our codebase that uses PT and does not use AASM, and it appears to function fine with PT (reran a test checking that on creation there's one PT version ~15 times, all passed)
Update:
Explicitly adding the PT update callback a second time, at the bottom of the model:
paper_trail.on_update
end
causes there to be (1,3,5) versions (consistent with two update callbacks being triggered) or all zero, as in the above. So it seems like something is blocking Papertrail's callbacks from running at all.
Describe the bug
This test is failing sometimes. Maybe 50% of the time?
Papertrail should have 3 version; the nil -> create, and the two from the events. When it works, Papertrail has the expected values. When it doesn't, papertrail has zero versions.
To Reproduce
(Note: Code is sanitized from our codebase. It's possible there's something else in our codebase that's messing with things)
Model:
On success, console shows:
On failure, console shows:
Expected behavior
Papertrail should reliably record versions when AASM events cause database updates.
Additional context
We have another model in our codebase that uses PT and does not use AASM, and it appears to function fine with PT (reran a test checking that on creation there's one PT version ~15 times, all passed)
Versions:
ruby '3.0.4'
aasm (5.2.0)
rails (6.0.4.7)
paper_trail (12.3.0)
The text was updated successfully, but these errors were encountered: