Skip to content

Instantly share code, notes, and snippets.

@abitdodgy
Created January 30, 2016 12:25
Show Gist options
  • Save abitdodgy/9c21421bb9789d9dd522 to your computer and use it in GitHub Desktop.
Save abitdodgy/9c21421bb9789d9dd522 to your computer and use it in GitHub Desktop.
A MiniTest version of API on Rails Chapter 5, listing 5.11
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