Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cleaning-portalmec
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Richard Fernando Heise Ferreira
cleaning-portalmec
Commits
7e9ca8f8
Commit
7e9ca8f8
authored
9 years ago
by
Mauricio Giacomini Girardello
Browse files
Options
Downloads
Patches
Plain Diff
adding missing tests and followable concerns for controllers and routes
parent
ea479a2b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/controllers/concerns/followable_controller.rb
+7
-1
7 additions, 1 deletion
app/controllers/concerns/followable_controller.rb
config/routes.rb
+9
-1
9 additions, 1 deletion
config/routes.rb
test/controllers/v1/users_controller_test.rb
+9
-4
9 additions, 4 deletions
test/controllers/v1/users_controller_test.rb
with
25 additions
and
6 deletions
app/controllers/concerns/followable_controller.rb
+
7
−
1
View file @
7e9ca8f8
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
config/routes.rb
+
9
−
1
View file @
7e9ca8f8
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
This diff is collapsed.
Click to expand it.
test/controllers/v1/users_controller_test.rb
+
9
−
4
View file @
7e9ca8f8
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment