mirror of https://github.com/mastodon/mastodon
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
939 B
Ruby
38 lines
939 B
Ruby
6 years ago
|
# frozen_string_literal: true
|
||
|
|
||
|
require 'rails_helper'
|
||
|
|
||
1 month ago
|
RSpec.describe PollExpirationValidator do
|
||
6 years ago
|
describe '#validate' do
|
||
|
before do
|
||
|
validator.validate(poll)
|
||
|
end
|
||
|
|
||
|
let(:validator) { described_class.new }
|
||
2 years ago
|
let(:poll) { instance_double(Poll, options: options, expires_at: expires_at, errors: errors) }
|
||
|
let(:errors) { instance_double(ActiveModel::Errors, add: nil) }
|
||
6 years ago
|
let(:options) { %w(foo bar) }
|
||
|
let(:expires_at) { 1.day.from_now }
|
||
|
|
||
1 month ago
|
it 'has no errors' do
|
||
2 years ago
|
expect(errors).to_not have_received(:add)
|
||
6 years ago
|
end
|
||
|
|
||
1 month ago
|
context 'when the poll expires in 5 min from now' do
|
||
6 years ago
|
let(:expires_at) { 5.minutes.from_now }
|
||
2 years ago
|
|
||
1 month ago
|
it 'has no errors' do
|
||
2 years ago
|
expect(errors).to_not have_received(:add)
|
||
6 years ago
|
end
|
||
|
end
|
||
1 month ago
|
|
||
|
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
|
||
6 years ago
|
end
|
||
|
end
|