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
ccb9c1b9
Commit
ccb9c1b9
authored
6 years ago
by
ysksn
Committed by
Eugen Rochko
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add pending specs for StatusLengthValidator (#9647)
* Add pending specs of StatusLengthValidator * Use instance variable
parent
c1693827
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/status_length_validator.rb
+12
-10
12 additions, 10 deletions
app/validators/status_length_validator.rb
spec/validators/status_length_validator_spec.rb
+11
-2
11 additions, 2 deletions
spec/validators/status_length_validator_spec.rb
with
23 additions
and
12 deletions
app/validators/status_length_validator.rb
+
12
−
10
View file @
ccb9c1b9
...
...
@@ -5,27 +5,29 @@ class StatusLengthValidator < ActiveModel::Validator
def
validate
(
status
)
return
unless
status
.
local?
&&
!
status
.
reblog?
status
.
errors
.
add
(
:text
,
I18n
.
t
(
'statuses.over_character_limit'
,
max:
MAX_CHARS
))
if
too_long?
(
status
)
@status
=
status
status
.
errors
.
add
(
:text
,
I18n
.
t
(
'statuses.over_character_limit'
,
max:
MAX_CHARS
))
if
too_long?
end
private
def
too_long?
(
status
)
countable_length
(
status
)
>
MAX_CHARS
def
too_long?
countable_length
>
MAX_CHARS
end
def
countable_length
(
status
)
total_text
(
status
)
.
mb_chars
.
grapheme_length
def
countable_length
total_text
.
mb_chars
.
grapheme_length
end
def
total_text
(
status
)
[
status
.
spoiler_text
,
countable_text
(
status
)
].
join
def
total_text
[
@
status
.
spoiler_text
,
countable_text
].
join
end
def
countable_text
(
status
)
return
''
if
status
.
text
.
nil?
def
countable_text
return
''
if
@
status
.
text
.
nil?
status
.
text
.
dup
.
tap
do
|
new_text
|
@
status
.
text
.
dup
.
tap
do
|
new_text
|
new_text
.
gsub!
(
FetchLinkCardService
::
URL_PATTERN
,
'x'
*
23
)
new_text
.
gsub!
(
Account
::
MENTION_RE
,
'@\2'
)
end
...
...
This diff is collapsed.
Click to expand it.
spec/validators/status_length_validator_spec.rb
+
11
−
2
View file @
ccb9c1b9
...
...
@@ -4,8 +4,17 @@ require 'rails_helper'
describe
StatusLengthValidator
do
describe
'#validate'
do
it
'does not add errors onto remote statuses'
it
'does not add errors onto local reblogs'
it
'does not add errors onto remote statuses'
do
status
=
double
(
local?:
false
)
subject
.
validate
(
status
)
expect
(
status
).
not_to
receive
(
:errors
)
end
it
'does not add errors onto local reblogs'
do
status
=
double
(
local?:
false
,
reblog?:
true
)
subject
.
validate
(
status
)
expect
(
status
).
not_to
receive
(
:errors
)
end
it
'adds an error when content warning is over 500 characters'
do
status
=
double
(
spoiler_text:
'a'
*
520
,
text:
''
,
errors:
double
(
add:
nil
),
local?:
true
,
reblog?:
false
)
...
...
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