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
d08a7ef4
Commit
d08a7ef4
authored
9 years ago
by
Giovanne Marcelo
Browse files
Options
Downloads
Patches
Plain Diff
fixing taggable controller
parent
74a195f2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/controllers/concerns/taggable_controller.rb
+11
-6
11 additions, 6 deletions
app/controllers/concerns/taggable_controller.rb
test/controllers/v1/collections_controller_test.rb
+2
-2
2 additions, 2 deletions
test/controllers/v1/collections_controller_test.rb
with
13 additions
and
8 deletions
app/controllers/concerns/taggable_controller.rb
+
11
−
6
View file @
d08a7ef4
...
@@ -3,25 +3,26 @@ module TaggableController
...
@@ -3,25 +3,26 @@ module TaggableController
included
do
included
do
before_action
:authenticate_user!
,
only:
[
:tagging
,
:untagging
]
before_action
:authenticate_user!
,
only:
[
:tagging
,
:untagging
]
before_action
:set_user_tags
,
only:
[
:tagging
,
:untagging
]
end
end
# POST /v1/learning_objects/1/tagging
# POST /v1/learning_objects/1/tagging
# POST /v1/learning_objects/1/tagging.json
# POST /v1/learning_objects/1/tagging.json
def
tagging
def
tagging
if
current_user
.
tag
(
taggable
,
with:
taggable
.
owner_tags_on
(
current_
user
,
:
tags
)
<<
tag_params
[
:name
],
on: :tags
)
if
current_user
.
tag
(
taggable
,
with:
@
user
_
tags
<<
tag_params
[
:name
],
on: :tags
)
render
json:
@
taggable
,
status: :created
render
json:
taggable
,
status: :created
else
else
render
json:
@
taggable
.
errors
,
status: :unprocessable_entity
render
json:
taggable
.
errors
,
status: :unprocessable_entity
end
end
end
end
# DELETE /v1/learning_objects/1/untagging
# DELETE /v1/learning_objects/1/untagging
# DELETE /v1/learning_objects/1/untagging.json
# DELETE /v1/learning_objects/1/untagging.json
def
untagging
def
untagging
if
current_user
.
tag
(
taggable
,
with:
taggable
.
owner_tags_on
(
current_
user
,
:
tags
)
.
delete
(
tag_
params
[
:name
]),
on: :tags
)
if
current_user
.
tag
(
taggable
,
with:
@
user
_
tags
.
delete
(
params
[
:name
]),
on: :tags
)
render
json:
@
taggable
,
status: :ok
render
json:
taggable
,
status: :ok
else
else
render
json:
@
taggable
.
errors
,
status: :unprocessable_entity
render
json:
taggable
.
errors
,
status: :unprocessable_entity
end
end
end
end
...
@@ -34,4 +35,8 @@ module TaggableController
...
@@ -34,4 +35,8 @@ module TaggableController
def
tag_params
def
tag_params
params
.
require
(
:tag
).
permit
(
:name
)
params
.
require
(
:tag
).
permit
(
:name
)
end
end
def
set_user_tags
@user_tags
=
taggable
.
owner_tags_on
(
current_user
,
:tags
)
end
end
end
This diff is collapsed.
Click to expand it.
test/controllers/v1/collections_controller_test.rb
+
2
−
2
View file @
d08a7ef4
...
@@ -60,7 +60,7 @@ class V1::CollectionsControllerTest < ActionController::TestCase
...
@@ -60,7 +60,7 @@ class V1::CollectionsControllerTest < ActionController::TestCase
auth_request
users
(
:john
)
auth_request
users
(
:john
)
delete
:untagging
,
id:
collections
(
:ufpr
).
id
,
tag:
{
name:
'Test'
}
delete
:untagging
,
id:
collections
(
:ufpr
).
id
,
tag:
{
name:
'Test'
}
assert
ok
_response
:unprocessable_entity
assert_response
:unprocessable_entity
end
end
test
'should user untagging a tag that does not exist'
do
test
'should user untagging a tag that does not exist'
do
...
@@ -70,7 +70,7 @@ class V1::CollectionsControllerTest < ActionController::TestCase
...
@@ -70,7 +70,7 @@ class V1::CollectionsControllerTest < ActionController::TestCase
assert_response
:created
assert_response
:created
delete
:untagging
,
id:
collections
(
:ufpr
).
id
,
tag:
{
name:
'Test2'
}
delete
:untagging
,
id:
collections
(
:ufpr
).
id
,
tag:
{
name:
'Test2'
}
assert
ok
_response
:unprocessable_entity
assert_response
:unprocessable_entity
end
end
private
private
...
...
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