Skip to content

Commit

Permalink
Add unauthorized_entity to authenticate_for's default for called by c…
Browse files Browse the repository at this point in the history
…allback (nsarno#228)

- Add failing test authenticate_for namespaced model
  • Loading branch information
sakuraineed committed Oct 28, 2018
1 parent 66b6043 commit 749ce01
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/dummy/test/controllers/v1/test_namespaced_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@

module Knock
class TestNamespacedControllerTest < ActionDispatch::IntegrationTest

setup do
@user = V1::User.first
@token = Knock::AuthToken.new(payload: { sub: @user.id }).token
end

test "allow namespaced models" do
token = Knock::AuthToken.new(payload: { sub: @user.id }).token
get v1_test_namespaced_index_url, headers: {'Authorization': "Bearer #{token}"}
get v1_test_namespaced_index_url, headers: {'Authorization': "Bearer #{@token}"}
assert_response :ok
assert_equal @user, @controller.current_v1_user
end

test 'responds with unauthorized' do
get v1_test_namespaced_index_url
assert_response :unauthorized
end

test 'responds with unauthorized with invalid token in header' do
get v1_test_namespaced_index_url, headers: {'Authorization': 'Bearer invalid'}
assert_response :unauthorized
end
end
end

0 comments on commit 749ce01

Please sign in to comment.