2023-02-21 19:55:31 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-03 16:18:23 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-03-04 11:16:45 -05:00
|
|
|
describe Poll do
|
|
|
|
describe 'scopes' do
|
|
|
|
let(:status) { Fabricate(:status) }
|
|
|
|
let(:attached_poll) { Fabricate(:poll, status: status) }
|
|
|
|
let(:not_attached_poll) do
|
|
|
|
Fabricate(:poll).tap do |poll|
|
|
|
|
poll.status = nil
|
|
|
|
poll.save(validate: false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'attached' do
|
|
|
|
it 'finds the correct records' do
|
|
|
|
results = described_class.attached
|
|
|
|
|
|
|
|
expect(results).to eq([attached_poll])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'unattached' do
|
|
|
|
it 'finds the correct records' do
|
|
|
|
results = described_class.unattached
|
|
|
|
|
|
|
|
expect(results).to eq([not_attached_poll])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-10-17 08:56:24 -04:00
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
context 'when valid' do
|
|
|
|
let(:poll) { Fabricate.build(:poll) }
|
|
|
|
|
|
|
|
it 'is valid with valid attributes' do
|
|
|
|
expect(poll).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when not valid' do
|
|
|
|
let(:poll) { Fabricate.build(:poll, expires_at: nil) }
|
|
|
|
|
|
|
|
it 'is invalid without an expire date' do
|
|
|
|
poll.valid?
|
|
|
|
expect(poll).to model_have_error_on_field(:expires_at)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-03-03 16:18:23 -05:00
|
|
|
end
|