user_info_spec.rb 1003 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. require 'rails_helper'
  2. RSpec.describe UserInfo do
  3. describe '#current_user_id' do
  4. it 'is nil by default' do
  5. expect(described_class.current_user_id).to be nil
  6. end
  7. it 'takes a User ID as paramter and returns it' do
  8. test_id = 99
  9. described_class.current_user_id = test_id
  10. expect(described_class.current_user_id).to eq(test_id)
  11. end
  12. end
  13. describe '#ensure_current_user_id' do
  14. it 'uses and keeps set User IDs' do
  15. test_id = 99
  16. described_class.current_user_id = test_id
  17. described_class.ensure_current_user_id do
  18. expect(described_class.current_user_id).to eq(test_id)
  19. end
  20. expect(described_class.current_user_id).to eq(test_id)
  21. end
  22. it 'sets and resets temporary User ID 1' do
  23. described_class.current_user_id = nil
  24. described_class.ensure_current_user_id do
  25. expect(described_class.current_user_id).to eq(1)
  26. end
  27. expect(described_class.current_user_id).to be nil
  28. end
  29. end
  30. end