mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-22 14:08:07 +01:00
Extend spec coverage for Poll
model (#32500)
This commit is contained in:
parent
a1eb1a9642
commit
d74c2c583a
1 changed files with 19 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue