Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
Pierre Boudes
mastodon
Commits
1dcfb902
Commit
1dcfb902
authored
7 years ago
by
Matt Jankowski
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Clean up api/salmon controller (#3449)
parent
22cf18e1
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/api/salmon_controller.rb
+12
-6
12 additions, 6 deletions
app/controllers/api/salmon_controller.rb
spec/controllers/api/salmon_controller_spec.rb
+33
-20
33 additions, 20 deletions
spec/controllers/api/salmon_controller_spec.rb
with
45 additions
and
26 deletions
app/controllers/api/salmon_controller.rb
+
12
−
6
View file @
1dcfb902
...
...
@@ -5,10 +5,8 @@ class Api::SalmonController < ApiController
respond_to
:txt
def
update
payload
=
request
.
body
.
read
if
!
payload
.
nil?
&&
verify?
(
payload
)
SalmonWorker
.
perform_async
(
@account
.
id
,
payload
.
force_encoding
(
'UTF-8'
))
if
verify_payload?
process_salmon
head
201
else
head
202
...
...
@@ -21,7 +19,15 @@ class Api::SalmonController < ApiController
@account
=
Account
.
find
(
params
[
:id
])
end
def
verify?
(
payload
)
VerifySalmonService
.
new
.
call
(
payload
)
def
payload
@_payload
||=
request
.
body
.
read
end
def
verify_payload?
payload
.
present?
&&
VerifySalmonService
.
new
.
call
(
payload
)
end
def
process_salmon
SalmonWorker
.
perform_async
(
@account
.
id
,
payload
.
force_encoding
(
'UTF-8'
))
end
end
This diff is collapsed.
Click to expand it.
spec/controllers/api/salmon_controller_spec.rb
+
33
−
20
View file @
1dcfb902
...
...
@@ -13,29 +13,42 @@ RSpec.describe Api::SalmonController, type: :controller do
end
describe
'POST #update'
do
before
do
request
.
env
[
'RAW_POST_DATA'
]
=
File
.
read
(
File
.
join
(
Rails
.
root
,
'spec'
,
'fixtures'
,
'salmon'
,
'mention.xml'
))
post
:update
,
params:
{
id:
account
.
id
}
context
'with valid post data'
do
before
do
request
.
env
[
'RAW_POST_DATA'
]
=
File
.
read
(
File
.
join
(
Rails
.
root
,
'spec'
,
'fixtures'
,
'salmon'
,
'mention.xml'
))
post
:update
,
params:
{
id:
account
.
id
}
end
it
'contains XML in the request body'
do
expect
(
request
.
body
.
read
).
to
be_a
String
end
it
'returns http success'
do
expect
(
response
).
to
have_http_status
(
:success
)
end
it
'creates remote account'
do
expect
(
Account
.
find_by
(
username:
'gargron'
,
domain:
'quitter.no'
)).
to_not
be_nil
end
it
'creates status'
do
expect
(
Status
.
find_by
(
uri:
'tag:quitter.no,2016-03-20:noticeId=1276923:objectType=note'
)).
to_not
be_nil
end
it
'creates mention for target account'
do
expect
(
account
.
mentions
.
count
).
to
eq
1
end
end
it
'contains XML in the request body'
do
expect
(
request
.
body
.
read
).
to
be_a
String
end
it
'returns http success'
do
expect
(
response
).
to
have_http_status
(
:success
)
end
it
'creates remote account'
do
expect
(
Account
.
find_by
(
username:
'gargron'
,
domain:
'quitter.no'
)).
to_not
be_nil
end
it
'creates status'
do
expect
(
Status
.
find_by
(
uri:
'tag:quitter.no,2016-03-20:noticeId=1276923:objectType=note'
)).
to_not
be_nil
end
context
'with invalid post data'
do
before
do
request
.
env
[
'RAW_POST_DATA'
]
=
''
post
:update
,
params:
{
id:
account
.
id
}
end
it
'creates mention for target account'
do
expect
(
account
.
mentions
.
count
).
to
eq
1
it
'returns http success'
do
expect
(
response
).
to
have_http_status
(
202
)
end
end
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