Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
wattsworth
/
lumen-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
697bd4ec
authored
Feb 28, 2017
by
John Doe
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
finished user group endpoints
parent
cc0192b2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
2 deletions
app/controllers/user_groups_controller.rb
config/routes.rb
spec/controllers/user_groups_controller_spec.rb
app/controllers/user_groups_controller.rb
View file @
697bd4ec
...
...
@@ -50,7 +50,14 @@ class UserGroupsController < ApplicationController
# PATCH/PUT /user_groups/1.json
def
update
# TODO
@service
=
StubService
.
new
if
@user_group
.
update
(
user_group_params
)
@service
.
add_notice
(
'updated group'
)
render
:show
,
status: :ok
else
@service
.
errors
=
@user_group
.
errors
.
full_messages
render
:show
,
status: :unprocessable_entity
end
end
# DELETE /user_groups/1.json
...
...
config/routes.rb
View file @
697bd4ec
...
...
@@ -7,7 +7,7 @@ Rails.application.routes.draw do
mount_devise_token_auth_for
'User'
,
at:
'auth'
resources
:users
,
only:
[
:index
,
:create
,
:destroy
]
resources
:user_groups
,
only:
[
:index
,
:create
,
:destroy
]
do
resources
:user_groups
,
only:
[
:index
,
:
update
,
:
create
,
:destroy
]
do
member
do
put
'add_member'
put
'remove_member'
...
...
spec/controllers/user_groups_controller_spec.rb
View file @
697bd4ec
...
...
@@ -221,6 +221,54 @@ end
expect
(
UserGroup
.
exists?
(
group
.
id
)).
to
be
true
end
end
end
describe
'PUT update'
do
context
'with owner'
do
it
'updates the group'
do
@auth_headers
=
owner
.
create_new_auth_token
put
"/user_groups/
#{
group
.
id
}
.json"
,
params:
{
name:
'new'
,
description:
'changed'
},
headers:
@auth_headers
expect
(
response
).
to
have_http_status
(
:ok
)
expect
(
response
).
to
have_notice_message
expect
(
group
.
reload
.
name
).
to
eq
(
'new'
)
expect
(
group
.
description
).
to
eq
(
'changed'
)
#check to make sure JSON renders the members
body
=
JSON
.
parse
(
response
.
body
)
expect
(
body
[
'data'
][
'members'
].
count
).
to
eq
group
.
users
.
count
end
it
'returns error if unsuccesful'
do
@auth_headers
=
owner
.
create_new_auth_token
orig_name
=
group
.
name
# name cannot be blank
put
"/user_groups/
#{
group
.
id
}
.json"
,
params:
{
name:
''
,
description:
'changed'
},
headers:
@auth_headers
expect
(
response
).
to
have_http_status
(
:unprocessable_entity
)
expect
(
response
).
to
have_error_message
expect
(
group
.
reload
.
name
).
to
eq
(
orig_name
)
end
end
context
'with anybody else'
do
it
'returns unauthorized'
do
@auth_headers
=
member1
.
create_new_auth_token
orig_name
=
group
.
name
put
"/user_groups/
#{
group
.
id
}
.json"
,
params:
{
name:
'new'
,
description:
'changed'
},
headers:
@auth_headers
expect
(
response
).
to
have_http_status
(
:unauthorized
)
expect
(
group
.
reload
.
name
).
to
eq
orig_name
end
end
context
'without sign-in'
do
it
'returns unauthorized'
do
orig_name
=
group
.
name
put
"/user_groups/
#{
group
.
id
}
.json"
,
params:
{
name:
'new'
,
description:
'changed'
}
expect
(
response
).
to
have_http_status
(
:unauthorized
)
expect
(
group
.
reload
.
name
).
to
eq
orig_name
end
end
end
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