Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mastofe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Pleroma
mastofe
Commits
4725aeec
Commit
4725aeec
authored
6 years ago
by
ysksn
Committed by
Eugen Rochko
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add specs for DisallowedHashtagsValidator (#9653)
In order to implement tests easier, `#select_tags` created.
parent
0f938ff2
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/validators/disallowed_hashtags_validator.rb
+7
-2
7 additions, 2 deletions
app/validators/disallowed_hashtags_validator.rb
spec/validators/disallowed_hashtags_validator_spec.rb
+46
-0
46 additions, 0 deletions
spec/validators/disallowed_hashtags_validator_spec.rb
with
53 additions
and
2 deletions
app/validators/disallowed_hashtags_validator.rb
+
7
−
2
View file @
4725aeec
...
...
@@ -4,14 +4,19 @@ class DisallowedHashtagsValidator < ActiveModel::Validator
def
validate
(
status
)
return
unless
status
.
local?
&&
!
status
.
reblog?
tags
=
Extractor
.
extract_hashtags
(
status
.
text
)
tags
.
keep_if
{
|
tag
|
disallowed_hashtags
.
include?
tag
.
downcase
}
@status
=
status
tags
=
select_tags
status
.
errors
.
add
(
:text
,
I18n
.
t
(
'statuses.disallowed_hashtags'
,
tags:
tags
.
join
(
', '
),
count:
tags
.
size
))
unless
tags
.
empty?
end
private
def
select_tags
tags
=
Extractor
.
extract_hashtags
(
@status
.
text
)
tags
.
keep_if
{
|
tag
|
disallowed_hashtags
.
include?
tag
.
downcase
}
end
def
disallowed_hashtags
return
@disallowed_hashtags
if
@disallowed_hashtags
...
...
This diff is collapsed.
Click to expand it.
spec/validators/disallowed_hashtags_validator_spec.rb
0 → 100644
+
46
−
0
View file @
4725aeec
# frozen_string_literal: true
require
'rails_helper'
RSpec
.
describe
DisallowedHashtagsValidator
,
type: :validator
do
describe
'#validate'
do
before
do
allow_any_instance_of
(
described_class
).
to
receive
(
:select_tags
)
{
tags
}
described_class
.
new
.
validate
(
status
)
end
let
(
:status
)
{
double
(
errors:
errors
,
local?:
local
,
reblog?:
reblog
,
text:
''
)
}
let
(
:errors
)
{
double
(
add:
nil
)
}
context
'unless status.local? && !status.reblog?'
do
let
(
:local
)
{
false
}
let
(
:reblog
)
{
true
}
it
'not calls errors.add'
do
expect
(
errors
).
not_to
have_received
(
:add
).
with
(
:text
,
any_args
)
end
end
context
'status.local? && !status.reblog?'
do
let
(
:local
)
{
true
}
let
(
:reblog
)
{
false
}
context
'tags.empty?'
do
let
(
:tags
)
{
[]
}
it
'not calls errors.add'
do
expect
(
errors
).
not_to
have_received
(
:add
).
with
(
:text
,
any_args
)
end
end
context
'!tags.empty?'
do
let
(
:tags
)
{
%w(a b c)
}
it
'calls errors.add'
do
expect
(
errors
).
to
have_received
(
:add
)
.
with
(
:text
,
I18n
.
t
(
'statuses.disallowed_hashtags'
,
tags:
tags
.
join
(
', '
),
count:
tags
.
size
))
end
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