Class: AuthTokenableTest

Inherits:
Minitest::Test
  • Object
show all
Includes:
Rack::Test::Methods
Defined in:
lib/tests/controllers/auth_tokenable_test.rb

Instance Method Summary collapse

Instance Method Details

#appObject



56
57
58
# File 'lib/tests/controllers/auth_tokenable_test.rb', line 56

def app
  Rubee::Application.instance
end

#setupObject



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/tests/controllers/auth_tokenable_test.rb', line 60

def setup
  Rubee::Autoload.call
  Rubee::Router.draw do |route|
    route.post('/test/login', to: 'test#login')
    route.post('/test/logout', to: 'test#logout')
    route.get('/test/show', to: 'test#show')
    route.post('/testtwo/login', to: 'testtwo#login')
    route.post('/testtwo/logout', to: 'testtwo#logout')
    route.get('/testtwo/show', to: 'testtwo#show')
  end
  User.create(email: '9oU8S@example.com', password: '123456')
  Client.create(name: '9o@example.com', digest_password: '123456')
end

#test_test_controller_included_auth_tokenableObject



74
75
76
77
78
# File 'lib/tests/controllers/auth_tokenable_test.rb', line 74

def test_test_controller_included_auth_tokenable
  get('/test/show')

  assert_equal(last_response.status, 401)
end

#test_test_controller_included_auth_tokenable_authenticatedObject



80
81
82
83
84
85
86
# File 'lib/tests/controllers/auth_tokenable_test.rb', line 80

def test_test_controller_included_auth_tokenable_authenticated
  post('/test/login', { email: '9oU8S@example.com', password: '123456' })
  rack_mock_session.cookie_jar["jwt"] = last_response.cookies["jwt"].value.last
  get('/test/show')

  assert_equal(last_response.status, 200)
end

#test_test_controller_included_auth_tokenable_authenticated_custom_modelObject



94
95
96
97
98
99
100
# File 'lib/tests/controllers/auth_tokenable_test.rb', line 94

def test_test_controller_included_auth_tokenable_authenticated_custom_model
  post('/testtwo/login', { name: '9o@example.com', digest_password: '123456' })
  rack_mock_session.cookie_jar["jwt"] = last_response.cookies["jwt"].value.last
  get('/testtwo/show')

  assert_equal(last_response.status, 200)
end

#test_test_controller_included_auth_tokenable_unauthenticated_custom_modelObject



88
89
90
91
92
# File 'lib/tests/controllers/auth_tokenable_test.rb', line 88

def test_test_controller_included_auth_tokenable_unauthenticated_custom_model
  get('/testtwo/show')

  assert_equal(last_response.status, 401)
end