adding authentication helper test method for devise_auth_token

parent 9e5a8662
## This concern has +follow+ and +unfollow+ controller actions
## When you use it, be sure that +set_followable+ method is implemented in your controller, otherwise an fatal error will raise.
module FollowableController
extend ActiveSupport::Concern
included do
before_action :set_followable, only: [:follow, :unfollow]
end
# POST /v1/users/1/follow
# POST /v1/users/1/follow.json
def follow
current_user.follow(@followable) unless current_user.following? @followable
end
# DELETE /v1/users/1/unfollow
# DELETE /v1/users/1/unfollow.json
def unfollow
current_user.unfollow(@followable) if current_user.following? @followable
end
end
\ No newline at end of file
class V1::UsersController < ApplicationController
include ::FollowableController
before_action :set_user, only: [:show, :update, :destroy]
# GET /v1/users
......@@ -43,18 +44,12 @@ class V1::UsersController < ApplicationController
render nothing: true, status: :ok
end
# POST /v1/users/1/follow
# POST /v1/users/1/follow.json
def follow
end
private
# POST /v1/users/1/unfollow
# POST /v1/users/1/unfollow.json
def unfollow
def set_followable
@followable = set_user
end
private
def set_user
@user = User.find(params[:id])
end
......
john:
name: 'John'
email: 'john@test.com'
confirmed_at: '2015-10-10 15:30:22'
jack:
name: 'Jack'
......
......@@ -17,6 +17,12 @@ class ActiveSupport::TestCase
assert_equal expected.to_i, actual.count
end
# authenticate requests using devise_token_auth
def auth_request(user)
sign_in user
request.headers.merge!(user.create_new_auth_token)
end
def mock
MiniTest::Mock.new
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment