pessimistic_spec.rb 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe ActiveRecord::Locking::Pessimistic do
  4. let!(:ticket) { create(:ticket) }
  5. def set_old_ticket_store
  6. # set old store
  7. ActiveRecord::Base.connection.execute("UPDATE tickets SET preferences = '--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
  8. form: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
  9. remote_ip: 111.111.98.123
  10. fingerprint_md5: 66638aad396c60ecb24f96de1e59d111' WHERE id = #{ticket.id}")
  11. # kill cache
  12. Rails.cache.clear
  13. # reload ticket and make sure that the store is deserialized
  14. ticket.reload.preferences
  15. end
  16. it 'does raise the error for changes before lock' do
  17. ticket.updated_at = Time.zone.now
  18. expect { ticket.lock! }.to raise_error(RuntimeError)
  19. end
  20. it 'does not raise the error if the store has changes but only structure changed' do
  21. set_old_ticket_store
  22. expect do
  23. ticket.lock!
  24. ticket.update(title: SecureRandom.uuid)
  25. end.not_to raise_error
  26. end
  27. end