Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
22caa32b
Commit
22caa32b
authored
6 years ago
by
Shuhei Kitagawa
Committed by
Yamagishi Kazutoshi
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for embeds controller (#7719)
* Small refactoring of status_finder_spec * Add tests for embeds_controller
parent
6b2f4f8c
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
spec/controllers/api/web/embeds_controller_spec.rb
+52
-0
52 additions, 0 deletions
spec/controllers/api/web/embeds_controller_spec.rb
spec/lib/status_finder_spec.rb
+2
-5
2 additions, 5 deletions
spec/lib/status_finder_spec.rb
with
54 additions
and
5 deletions
spec/controllers/api/web/embeds_controller_spec.rb
0 → 100644
+
52
−
0
View file @
22caa32b
# frozen_string_literal: true
require
'rails_helper'
describe
Api
::
Web
::
EmbedsController
do
render_views
let
(
:user
)
{
Fabricate
(
:user
)
}
before
{
sign_in
user
}
describe
'POST #create'
do
subject
(
:response
)
{
post
:create
,
params:
{
url:
url
}
}
subject
(
:body
)
{
JSON
.
parse
(
response
.
body
,
symbolize_names:
true
)
}
context
'when successfully finds status'
do
let
(
:status
)
{
Fabricate
(
:status
)
}
let
(
:url
)
{
"http://
#{
Rails
.
configuration
.
x
.
web_domain
}
/@
#{
status
.
account
.
username
}
/
#{
status
.
id
}
"
}
it
'returns a right response'
do
expect
(
response
).
to
have_http_status
:ok
expect
(
body
[
:author_name
]).
to
eq
status
.
account
.
username
end
end
context
'when fails to find status'
do
let
(
:url
)
{
'https://host.test/oembed.html'
}
let
(
:service_instance
)
{
double
(
'fetch_oembed_service'
)
}
before
do
allow
(
FetchOEmbedService
).
to
receive
(
:new
)
{
service_instance
}
allow
(
service_instance
).
to
receive
(
:call
)
{
call_result
}
end
context
'when successfully fetching oembed'
do
let
(
:call_result
)
{
{
result: :ok
}
}
it
'returns a right response'
do
expect
(
response
).
to
have_http_status
:ok
expect
(
body
[
:result
]).
to
eq
'ok'
end
end
context
'when fails to fetch oembed'
do
let
(
:call_result
)
{
nil
}
it
'returns a right response'
do
expect
(
response
).
to
have_http_status
:not_found
end
end
end
end
end
This diff is collapsed.
Click to expand it.
spec/lib/status_finder_spec.rb
+
2
−
5
View file @
22caa32b
...
...
@@ -6,10 +6,11 @@ describe StatusFinder do
include
RoutingHelper
describe
'#status'
do
subject
{
described_class
.
new
(
url
)
}
context
'with a status url'
do
let
(
:status
)
{
Fabricate
(
:status
)
}
let
(
:url
)
{
short_account_status_url
(
account_username:
status
.
account
.
username
,
id:
status
.
id
)
}
subject
{
described_class
.
new
(
url
)
}
it
'finds the stream entry'
do
expect
(
subject
.
status
).
to
eq
(
status
)
...
...
@@ -27,7 +28,6 @@ describe StatusFinder do
context
'with a stream entry url'
do
let
(
:stream_entry
)
{
Fabricate
(
:stream_entry
)
}
let
(
:url
)
{
account_stream_entry_url
(
stream_entry
.
account
,
stream_entry
)
}
subject
{
described_class
.
new
(
url
)
}
it
'finds the stream entry'
do
expect
(
subject
.
status
).
to
eq
(
stream_entry
.
status
)
...
...
@@ -37,7 +37,6 @@ describe StatusFinder do
context
'with a remote url even if id exists on local'
do
let
(
:status
)
{
Fabricate
(
:status
)
}
let
(
:url
)
{
"https://example.com/users/test/statuses/
#{
status
.
id
}
"
}
subject
{
described_class
.
new
(
url
)
}
it
'raises an error'
do
expect
{
subject
.
status
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
...
...
@@ -46,7 +45,6 @@ describe StatusFinder do
context
'with a plausible url'
do
let
(
:url
)
{
'https://example.com/users/test/updates/123/embed'
}
subject
{
described_class
.
new
(
url
)
}
it
'raises an error'
do
expect
{
subject
.
status
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
...
...
@@ -55,7 +53,6 @@ describe StatusFinder do
context
'with an unrecognized url'
do
let
(
:url
)
{
'https://example.com/about'
}
subject
{
described_class
.
new
(
url
)
}
it
'raises an error'
do
expect
{
subject
.
status
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
...
...
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