API de comptabilité horaire.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

authenticable_test.rb 708B

1234567891011121314151617181920212223242526
  1. class MockController
  2. include Authenticable
  3. attr_accessor :request
  4. def initialize
  5. mock_request = Struct.new(:headers)
  6. self.request = mock_request.new({})
  7. end
  8. end
  9. class AuthenticableTest < ActionDispatch::IntegrationTest
  10. setup do
  11. @user = users(:one)
  12. @authentication = MockController.new
  13. end
  14. test 'should get user from Authorization token' do
  15. @authentication.request.headers['Authorization'] = JsonWebToken.encode(user_id: @user.id)
  16. assert_equal @user.id, @authentication.current_user.id
  17. end
  18. test 'should not get user from empty Authorization token' do
  19. @authentication.request.headers['Authorization'] = nil
  20. assert_nil @authentication.current_user
  21. end
  22. end