2019-04-09 15:02:12 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2025-01-28 14:38:18 +00:00
|
|
|
RSpec.describe PollExpirationValidator do
|
2019-04-09 15:02:12 +00:00
|
|
|
describe '#validate' do
|
|
|
|
before do
|
|
|
|
validator.validate(poll)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:validator) { described_class.new }
|
2023-06-22 12:55:22 +00:00
|
|
|
let(:poll) { instance_double(Poll, options: options, expires_at: expires_at, errors: errors) }
|
|
|
|
let(:errors) { instance_double(ActiveModel::Errors, add: nil) }
|
2019-04-09 15:02:12 +00:00
|
|
|
let(:options) { %w(foo bar) }
|
|
|
|
let(:expires_at) { 1.day.from_now }
|
|
|
|
|
2025-01-28 14:38:18 +00:00
|
|
|
it 'has no errors' do
|
2023-02-20 01:33:27 +00:00
|
|
|
expect(errors).to_not have_received(:add)
|
2019-04-09 15:02:12 +00:00
|
|
|
end
|
|
|
|
|
2025-01-28 14:38:18 +00:00
|
|
|
context 'when the poll expires in 5 min from now' do
|
2019-04-09 15:02:12 +00:00
|
|
|
let(:expires_at) { 5.minutes.from_now }
|
2023-02-18 22:10:19 +00:00
|
|
|
|
2025-01-28 14:38:18 +00:00
|
|
|
it 'has no errors' do
|
2023-02-20 01:33:27 +00:00
|
|
|
expect(errors).to_not have_received(:add)
|
2019-04-09 15:02:12 +00:00
|
|
|
end
|
|
|
|
end
|
2025-01-28 14:38:18 +00:00
|
|
|
|
|
|
|
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
|
2019-04-09 15:02:12 +00:00
|
|
|
end
|
|
|
|
end
|