mirror of https://github.com/mastodon/mastodon
Fix spec descriptions around configurable limit values (#31079)
This commit is contained in:
parent
5a60a3b80c
commit
6e4305de69
|
@ -592,7 +592,7 @@ RSpec.describe Account do
|
||||||
expect(results).to eq [match]
|
expect(results).to eq [match]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'limits by 10 by default' do
|
it 'limits result count by default value' do
|
||||||
stub_const('Account::Search::DEFAULT_LIMIT', 1)
|
stub_const('Account::Search::DEFAULT_LIMIT', 1)
|
||||||
2.times { Fabricate(:account, display_name: 'Display Name') }
|
2.times { Fabricate(:account, display_name: 'Display Name') }
|
||||||
results = described_class.advanced_search_for('display', account)
|
results = described_class.advanced_search_for('display', account)
|
||||||
|
|
|
@ -6,7 +6,7 @@ describe NoteLengthValidator do
|
||||||
subject { described_class.new(attributes: { note: true }, maximum: 500) }
|
subject { described_class.new(attributes: { note: true }, maximum: 500) }
|
||||||
|
|
||||||
describe '#validate' do
|
describe '#validate' do
|
||||||
it 'adds an error when text is over 500 characters' do
|
it 'adds an error when text is over configured character limit' do
|
||||||
text = 'a' * 520
|
text = 'a' * 520
|
||||||
account = instance_double(Account, note: text, errors: activemodel_errors)
|
account = instance_double(Account, note: text, errors: activemodel_errors)
|
||||||
|
|
||||||
|
@ -14,16 +14,16 @@ describe NoteLengthValidator do
|
||||||
expect(account.errors).to have_received(:add)
|
expect(account.errors).to have_received(:add)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'counts URLs as 23 characters flat' do
|
it 'reduces calculated length of auto-linkable space-separated URLs' do
|
||||||
text = ('a' * 476) + " http://#{'b' * 30}.com/example"
|
text = [starting_string, example_link].join(' ')
|
||||||
account = instance_double(Account, note: text, errors: activemodel_errors)
|
account = instance_double(Account, note: text, errors: activemodel_errors)
|
||||||
|
|
||||||
subject.validate_each(account, 'note', text)
|
subject.validate_each(account, 'note', text)
|
||||||
expect(account.errors).to_not have_received(:add)
|
expect(account.errors).to_not have_received(:add)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not count non-autolinkable URLs as 23 characters flat' do
|
it 'does not reduce calculated length of non-autolinkable URLs' do
|
||||||
text = ('a' * 476) + "http://#{'b' * 30}.com/example"
|
text = [starting_string, example_link].join
|
||||||
account = instance_double(Account, note: text, errors: activemodel_errors)
|
account = instance_double(Account, note: text, errors: activemodel_errors)
|
||||||
|
|
||||||
subject.validate_each(account, 'note', text)
|
subject.validate_each(account, 'note', text)
|
||||||
|
@ -32,6 +32,14 @@ describe NoteLengthValidator do
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def starting_string
|
||||||
|
'a' * 476
|
||||||
|
end
|
||||||
|
|
||||||
|
def example_link
|
||||||
|
"http://#{'b' * 30}.com/example"
|
||||||
|
end
|
||||||
|
|
||||||
def activemodel_errors
|
def activemodel_errors
|
||||||
instance_double(ActiveModel::Errors, add: nil)
|
instance_double(ActiveModel::Errors, add: nil)
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,8 +19,9 @@ describe ReactionValidator do
|
||||||
expect(reaction.errors).to be_empty
|
expect(reaction.errors).to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'adds error when 8 reactions already exist' do
|
it 'adds error when reaction limit count has already been reached' do
|
||||||
%w(🐘 ❤️ 🙉 😍 😋 😂 😞 👍).each do |name|
|
stub_const 'ReactionValidator::LIMIT', 2
|
||||||
|
%w(🐘 ❤️).each do |name|
|
||||||
announcement.announcement_reactions.create!(name: name, account: Fabricate(:account))
|
announcement.announcement_reactions.create!(name: name, account: Fabricate(:account))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -42,23 +42,23 @@ describe StatusLengthValidator do
|
||||||
expect(status.errors).to have_received(:add)
|
expect(status.errors).to have_received(:add)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'counts URLs as 23 characters flat' do
|
it 'reduces calculated length of auto-linkable space-separated URLs' do
|
||||||
text = ('a' * 476) + " http://#{'b' * 30}.com/example"
|
text = [starting_string, example_link].join(' ')
|
||||||
status = status_double(text: text)
|
status = status_double(text: text)
|
||||||
|
|
||||||
subject.validate(status)
|
subject.validate(status)
|
||||||
expect(status.errors).to_not have_received(:add)
|
expect(status.errors).to_not have_received(:add)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not count non-autolinkable URLs as 23 characters flat' do
|
it 'does not reduce calculated length of non-autolinkable URLs' do
|
||||||
text = ('a' * 476) + "http://#{'b' * 30}.com/example"
|
text = [starting_string, example_link].join
|
||||||
status = status_double(text: text)
|
status = status_double(text: text)
|
||||||
|
|
||||||
subject.validate(status)
|
subject.validate(status)
|
||||||
expect(status.errors).to have_received(:add)
|
expect(status.errors).to have_received(:add)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not count overly long URLs as 23 characters flat' do
|
it 'does not reduce calculated length of count overly long URLs' do
|
||||||
text = "http://example.com/valid?#{'#foo?' * 1000}"
|
text = "http://example.com/valid?#{'#foo?' * 1000}"
|
||||||
status = status_double(text: text)
|
status = status_double(text: text)
|
||||||
subject.validate(status)
|
subject.validate(status)
|
||||||
|
@ -84,6 +84,14 @@ describe StatusLengthValidator do
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def starting_string
|
||||||
|
'a' * 476
|
||||||
|
end
|
||||||
|
|
||||||
|
def example_link
|
||||||
|
"http://#{'b' * 30}.com/example"
|
||||||
|
end
|
||||||
|
|
||||||
def status_double(spoiler_text: '', text: '')
|
def status_double(spoiler_text: '', text: '')
|
||||||
instance_double(
|
instance_double(
|
||||||
Status,
|
Status,
|
||||||
|
|
Loading…
Reference in New Issue