Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
portalmec
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
10
Issues
10
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
Operations
Operations
Incidents
Environments
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
PortalMEC
portalmec
Commits
ea479a2b
Commit
ea479a2b
authored
Apr 05, 2016
by
Mauricio Giacomini Girardello
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding authentication helper test method for devise_auth_token
parent
9e5a8662
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
9 deletions
+33
-9
app/controllers/concerns/followable_controller.rb
app/controllers/concerns/followable_controller.rb
+22
-0
app/controllers/v1/users_controller.rb
app/controllers/v1/users_controller.rb
+4
-9
test/fixtures/users.yml
test/fixtures/users.yml
+1
-0
test/test_helper.rb
test/test_helper.rb
+6
-0
No files found.
app/controllers/concerns/followable_controller.rb
0 → 100644
View file @
ea479a2b
## 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
app/controllers/v1/users_controller.rb
View file @
ea479a2b
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
...
...
test/fixtures/users.yml
View file @
ea479a2b
john
:
name
:
'
John'
email
:
'
john@test.com'
confirmed_at
:
'
2015-10-10
15:30:22'
jack
:
name
:
'
Jack'
...
...
test/test_helper.rb
View file @
ea479a2b
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment