Created
January 30, 2016 12:25
-
-
Save abitdodgy/9c21421bb9789d9dd522 to your computer and use it in GitHub Desktop.
A MiniTest version of API on Rails Chapter 5, listing 5.11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
class DummyController < ApplicationController | |
include Authable | |
end | |
class AuthableTest < ActionController::TestCase | |
setup do | |
include_default_request_headers | |
@dummy = DummyController.new | |
end | |
test "#current_user returns the use from the authorization header" do | |
user = create(:user) | |
request.headers['Authorization'] = user.auth_token | |
@dummy.stub(:request, request) do | |
assert_equal user.auth_token, @dummy.current_user.auth_token | |
end | |
end | |
test "#authenticate_with_token!" do | |
response.stub :response_code, 401 do | |
response.stub :body, { errors: "Not authenticated" }.to_json do | |
@dummy.stub :current_user, nil do | |
@dummy.stub :response, response do | |
assert_equal json_response_body[:errors], "Not authenticated" | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment