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