Fix polls not being validated on edition (#33755)
This commit is contained in:
parent
80f72ee501
commit
32aa83e9d7
8 changed files with 82 additions and 21 deletions
|
@ -59,7 +59,7 @@ RSpec.describe 'Instances' do
|
|||
description_limit: MediaAttachment::MAX_DESCRIPTION_LENGTH
|
||||
),
|
||||
polls: include(
|
||||
max_options: PollValidator::MAX_OPTIONS
|
||||
max_options: PollOptionsValidator::MAX_OPTIONS
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe PollValidator do
|
||||
RSpec.describe PollExpirationValidator do
|
||||
describe '#validate' do
|
||||
before do
|
||||
validator.validate(poll)
|
||||
|
@ -14,16 +14,24 @@ RSpec.describe PollValidator do
|
|||
let(:options) { %w(foo bar) }
|
||||
let(:expires_at) { 1.day.from_now }
|
||||
|
||||
it 'have no errors' do
|
||||
it 'has no errors' do
|
||||
expect(errors).to_not have_received(:add)
|
||||
end
|
||||
|
||||
context 'when expires is just 5 min ago' do
|
||||
context 'when the poll expires in 5 min from now' do
|
||||
let(:expires_at) { 5.minutes.from_now }
|
||||
|
||||
it 'not calls errors add' do
|
||||
it 'has no errors' do
|
||||
expect(errors).to_not have_received(:add)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the poll expires in the past' do
|
||||
let(:expires_at) { 5.minutes.ago }
|
||||
|
||||
it 'has errors' do
|
||||
expect(errors).to have_received(:add)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
45
spec/validators/poll_options_validator_spec.rb
Normal file
45
spec/validators/poll_options_validator_spec.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe PollOptionsValidator do
|
||||
describe '#validate' do
|
||||
before do
|
||||
validator.validate(poll)
|
||||
end
|
||||
|
||||
let(:validator) { described_class.new }
|
||||
let(:poll) { instance_double(Poll, options: options, expires_at: expires_at, errors: errors) }
|
||||
let(:errors) { instance_double(ActiveModel::Errors, add: nil) }
|
||||
let(:options) { %w(foo bar) }
|
||||
let(:expires_at) { 1.day.from_now }
|
||||
|
||||
it 'has no errors' do
|
||||
expect(errors).to_not have_received(:add)
|
||||
end
|
||||
|
||||
context 'when the poll has duplicate options' do
|
||||
let(:options) { %w(foo foo) }
|
||||
|
||||
it 'adds errors' do
|
||||
expect(errors).to have_received(:add)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the poll has no options' do
|
||||
let(:options) { [] }
|
||||
|
||||
it 'adds errors' do
|
||||
expect(errors).to have_received(:add)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the poll has too many options' do
|
||||
let(:options) { Array.new(described_class::MAX_OPTIONS + 1) { |i| "option #{i}" } }
|
||||
|
||||
it 'adds errors' do
|
||||
expect(errors).to have_received(:add)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue