base_spec.rb 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. require 'rails_helper'
  2. RSpec.describe Sessions::Backend::Base do
  3. subject(:backend) { described_class.new(agent, {}, false, client_id, ttl) }
  4. let(:agent) { create(:agent) }
  5. let(:client_id) { '123-1' }
  6. let(:ttl) { 3 } # seconds
  7. let!(:ticket) { Ticket.first || create(:ticket) }
  8. describe '#asset_needed?' do
  9. context 'before #asset_push has ever been called for the given record' do
  10. it 'returns true' do
  11. expect(backend.asset_needed?(ticket)).to be(true)
  12. end
  13. end
  14. context 'when #asset_push was previously called for the given record' do
  15. before { backend.asset_push(ticket, {}) }
  16. it 'returns false' do
  17. expect(backend.asset_needed?(ticket)).to be(false)
  18. end
  19. context 'within two hours of the backend’s #time_now value' do
  20. before { backend.time_now = (2.hours - 1.second).from_now.to_i }
  21. it 'returns false' do
  22. expect(backend.asset_needed?(ticket)).to be(false)
  23. end
  24. end
  25. context 'over two hours before the backend’s #time_now value' do
  26. before { backend.time_now = (2.hours + 1.second).from_now.to_i }
  27. it 'returns true' do
  28. expect(backend.asset_needed?(ticket)).to be(true)
  29. end
  30. end
  31. context 'prior to the record’s last update' do
  32. before { ticket.touch }
  33. it 'returns true' do
  34. expect(backend.asset_needed?(ticket)).to be(true)
  35. end
  36. end
  37. end
  38. end
  39. describe '#asset_needed_by_updated_at?' do
  40. let(:method_args) { [ticket.class.name, ticket.id, ticket.updated_at] }
  41. context 'before #asset_push has ever been called for the given record' do
  42. it 'returns true' do
  43. expect(backend.asset_needed_by_updated_at?(*method_args)).to be(true)
  44. end
  45. end
  46. context 'when #asset_push was previously called for the given record' do
  47. before { backend.asset_push(ticket, {}) }
  48. it 'returns false' do
  49. expect(backend.asset_needed_by_updated_at?(*method_args)).to be(false)
  50. end
  51. context 'within two hours of the backend’s #time_now value' do
  52. before { backend.time_now = (2.hours - 1.second).from_now.to_i }
  53. it 'returns false' do
  54. expect(backend.asset_needed_by_updated_at?(*method_args)).to be(false)
  55. end
  56. end
  57. context 'over two hours before the backend’s #time_now value' do
  58. before { backend.time_now = (2.hours + 1.second).from_now.to_i }
  59. it 'returns true' do
  60. expect(backend.asset_needed_by_updated_at?(*method_args)).to be(true)
  61. end
  62. end
  63. context 'prior to the record’s last update' do
  64. before { ticket.touch }
  65. it 'returns true' do
  66. expect(backend.asset_needed_by_updated_at?(*method_args)).to be(true)
  67. end
  68. end
  69. end
  70. end
  71. describe '#asset_push' do
  72. it 'returns the assets for the given record' do
  73. expect(backend.asset_push(ticket, {})).to eq(ticket.assets({}))
  74. end
  75. end
  76. end