Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
28158f95
Commit
28158f95
authored
Sep 13, 2019
by
Peter Leitzen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set default http status of a successful ServiceResponse
parent
a4e3f81f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
2 deletions
+16
-2
app/services/service_response.rb
app/services/service_response.rb
+2
-2
spec/services/service_response_spec.rb
spec/services/service_response_spec.rb
+14
-0
No files found.
app/services/service_response.rb
View file @
28158f95
# frozen_string_literal: true
class
ServiceResponse
def
self
.
success
(
message:
nil
,
payload:
{})
new
(
status: :success
,
message:
message
,
payload:
payload
)
def
self
.
success
(
message:
nil
,
payload:
{}
,
http_status: :ok
)
new
(
status: :success
,
message:
message
,
payload:
payload
,
http_status:
http_status
)
end
def
self
.
error
(
message
:,
payload:
{},
http_status:
nil
)
...
...
spec/services/service_response_spec.rb
View file @
28158f95
...
...
@@ -23,6 +23,20 @@ describe ServiceResponse do
expect
(
response
).
to
be_success
expect
(
response
.
payload
).
to
eq
(
good:
'orange'
)
end
it
'creates a successful response with default HTTP status'
do
response
=
described_class
.
success
expect
(
response
).
to
be_success
expect
(
response
.
http_status
).
to
eq
(
:ok
)
end
it
'creates a successful response with custom HTTP status'
do
response
=
described_class
.
success
(
http_status:
204
)
expect
(
response
).
to
be_success
expect
(
response
.
http_status
).
to
eq
(
204
)
end
end
describe
'.error'
do
...
...
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