1
0
mirror of https://github.com/mastodon/mastodon synced 2024-11-23 22:56:20 +09:00

Extend spec coverage for Poll model (#32500)

This commit is contained in:
Matt Jankowski 2024-10-15 08:48:10 -04:00 committed by GitHub
parent a1eb1a9642
commit d74c2c583a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,7 +3,7 @@
require 'rails_helper'
RSpec.describe Poll do
describe 'scopes' do
describe 'Scopes' do
let(:status) { Fabricate(:status) }
let(:attached_poll) { Fabricate(:poll, status: status) }
let(:not_attached_poll) do
@ -13,7 +13,7 @@ RSpec.describe Poll do
end
end
describe 'attached' do
describe '.attached' do
it 'finds the correct records' do
results = described_class.attached
@ -21,7 +21,7 @@ RSpec.describe Poll do
end
end
describe 'unattached' do
describe '.unattached' do
it 'finds the correct records' do
results = described_class.unattached
@ -30,11 +30,23 @@ RSpec.describe Poll do
end
end
describe 'validations' do
context 'when not valid' do
subject { Fabricate.build(:poll) }
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 { is_expected.to validate_presence_of(:expires_at) }
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)
end
end
describe 'Validations' do
subject { Fabricate.build(:poll) }
it { is_expected.to validate_presence_of(:expires_at) }
end
end