2023-02-22 01:55:31 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-03 22:18:23 +01:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 07:12:25 +02:00
|
|
|
RSpec.describe Poll do
|
2024-12-20 09:21:34 +01:00
|
|
|
include_examples 'Expireable'
|
|
|
|
|
2024-10-15 14:48:10 +02:00
|
|
|
describe '#reset_votes!' do
|
|
|
|
let(:poll) { Fabricate :poll, cached_tallies: [2, 3], votes_count: 5, voters_count: 5 }
|
|
|
|
let!(:vote) { Fabricate :poll_vote, poll: }
|
|
|
|
|
|
|
|
it 'resets vote data and deletes votes' do
|
|
|
|
expect { poll.reset_votes! }
|
|
|
|
.to change(poll, :cached_tallies).to([0, 0])
|
|
|
|
.and change(poll, :votes_count).to(0)
|
|
|
|
.and(change(poll, :voters_count).to(0))
|
|
|
|
expect { vote.reload }
|
|
|
|
.to raise_error(ActiveRecord::RecordNotFound)
|
2023-10-17 14:56:24 +02:00
|
|
|
end
|
|
|
|
end
|
2024-10-15 14:48:10 +02:00
|
|
|
|
|
|
|
describe 'Validations' do
|
|
|
|
subject { Fabricate.build(:poll) }
|
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of(:expires_at) }
|
|
|
|
end
|
2019-03-03 22:18:23 +01:00
|
|
|
end
|