Skip to content
Snippets Groups Projects
Commit 7e9ca8f8 authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

adding missing tests and followable concerns for controllers and routes

parent ea479a2b
No related branches found
No related tags found
No related merge requests found
......@@ -5,12 +5,18 @@ module FollowableController
included do
before_action :set_followable, only: [:follow, :unfollow]
before_action :authenticate_user!, 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
if !current_user.following?(@followable)
current_user.follow(@followable)
render nothing: true, status: :created
else
render nothing: true, status: :forbidden
end
end
# DELETE /v1/users/1/unfollow
......
Rails.application.routes.draw do
devise_for :users
require 'sidekiq/web'
concern :followable do
member do
post :follow
delete :unfollow
end
end
# devise_for :users, :controllers => { :omniauth_callbacks => "callbacks" }
namespace :v1 do
mount_devise_token_auth_for 'User', skip: [:omniauth_callbacks], at: :auth
resources :users
resources :users, concerns: :followable
end
end
......@@ -2,12 +2,10 @@ require 'test_helper'
class V1::UsersControllerTest < ActionController::TestCase
tests V1::UsersController
include Devise::TestHelpers
test 'should get index' do
skip('Unsolved issue: ArgumentError: wrong number of arguments (2 for 0)')
#get :index
#assert_response :success
#assert_not_nil assigns(:users)
end
test 'should post user to create and return :created code' do
......@@ -32,7 +30,7 @@ class V1::UsersControllerTest < ActionController::TestCase
password: 'test123455',
password_confirmation: 'test123455',
terms_of_service: '1'
}, id: user.id
}, id: user.id
assert_response :ok
end
......@@ -50,4 +48,11 @@ class V1::UsersControllerTest < ActionController::TestCase
assert_response :ok
end
test 'should user follow an user jack' do
user = users(:john)
auth_request user
post :follow, id: users(:jack).id
assert_response :created
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment