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
1f183842
Commit
1f183842
authored
7 years ago
by
Yamagishi Kazutoshi
Committed by
Eugen Rochko
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Refactor remote_follow_spec.rb (#5690)
parent
20150659
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
spec/models/remote_follow_spec.rb
+33
-51
33 additions, 51 deletions
spec/models/remote_follow_spec.rb
with
33 additions
and
51 deletions
spec/models/remote_follow_spec.rb
+
33
−
51
View file @
1f183842
...
...
@@ -3,83 +3,65 @@
require
'rails_helper'
RSpec
.
describe
RemoteFollow
do
before
do
stub_request
(
:get
,
'https://quitter.no/.well-known/webfinger?resource=acct:gargron@quitter.no'
).
to_return
(
request_fixture
(
'webfinger.txt'
))
end
let
(
:attrs
)
{
nil
}
let
(
:remote_follow
)
{
described_class
.
new
(
attrs
)
}
describe
'.initialize'
do
let
(
:remote_follow
)
{
R
emote
F
ollow
.
new
(
option
)
}
subject
{
r
emote
_f
ollow
.
acct
}
context
'
option
with acct'
do
let
(
:
option
)
{
{
acct:
'
hoge@example.com
'
}
}
context
'
attrs
with acct'
do
let
(
:
attrs
)
{
{
acct:
'
gargron@quitter.no
'
}
}
it
'
s
ets acct'
do
expect
(
remote_follow
.
acct
).
to
eq
'hoge@example.com
'
it
'
r
et
urn
s acct'
do
is_
expect
ed
.
to
eq
'gargron@quitter.no
'
end
end
context
'
option
without acct'
do
let
(
:
option
)
{
{}
}
context
'
attrs
without acct'
do
let
(
:
attrs
)
{
{}
}
it
'does not set acct'
do
expect
(
remote_follow
.
acct
)
.
to
be_nil
it
do
is_
expect
ed
.
to
be_nil
end
end
end
describe
'#valid?'
do
let
(
:remote_follow
)
{
R
emote
F
ollow
.
new
}
subject
{
r
emote
_f
ollow
.
valid?
}
context
'super is falsy'
do
module
InvalidSuper
def
valid?
nil
end
end
before
do
class
RemoteFollow
include
InvalidSuper
end
end
it
'returns false without calling #populate_template and #errors'
do
expect
(
remote_follow
).
not_to
receive
(
:populate_template
)
expect
(
remote_follow
).
not_to
receive
(
:errors
)
expect
(
remote_follow
.
valid?
).
to
be
false
context
'attrs with acct'
do
let
(
:attrs
)
{
{
acct:
'gargron@quitter.no'
}}
it
do
is_expected
.
to
be
true
end
end
context
'super is truthy'
do
module
ValidSuper
def
valid?
true
end
end
context
'attrs without acct'
do
let
(
:attrs
)
{
{
}
}
before
do
class
RemoteFollow
include
ValidSuper
end
end
it
'calls #populate_template and #errors.empty?'
do
expect
(
remote_follow
).
to
receive
(
:populate_template
)
expect
(
remote_follow
).
to
receive_message_chain
(
:errors
,
:empty?
)
remote_follow
.
valid?
it
do
is_expected
.
to
be
false
end
end
end
describe
'#subscribe_address_for'
do
before
do
allow
(
remote_follow
).
to
receive
(
:addressable_template
).
and_return
(
addressable_template
)
remote_follow
.
valid?
end
let
(
:a
ccount
)
{
instance_double
(
'Account'
,
local_username_and_domain:
local_username_and_domain
)
}
let
(
:a
ddressable_template
)
{
instance_double
(
'Addressable::Templat
e'
)
}
let
(
:local_username_and_domain
)
{
'hoge@example.com'
}
let
(
:
remote_follow
)
{
RemoteFollow
.
new
}
let
(
:a
ttrs
)
{
{
acct:
'gargron@quitter.no'
}
}
let
(
:a
ccount
)
{
Fabricate
(
:account
,
username:
'alic
e'
)
}
subject
{
remote_follow
.
subscribe_address_for
(
account
)
}
it
'calls Addressable::Template#expand.to_s'
do
expect
(
addressable_template
).
to
receive_message_chain
(
:expand
,
:to_s
).
with
(
uri:
local_username_and_domain
).
with
(
no_args
)
remote_follow
.
subscribe_address_for
(
account
)
it
'returns subscribe address'
do
is_expected
.
to
eq
'https://quitter.no/main/ostatussub?profile=alice%40cb6e6126.ngrok.io'
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