2023-02-22 11:55:31 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-04 08:18:23 +11:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 15:12:25 +10:00
|
|
|
RSpec.describe Poll do
|
2023-03-05 03:16:45 +11:00
|
|
|
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 23:56:24 +11:00
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
context 'when not valid' do
|
2024-09-06 01:36:05 +10:00
|
|
|
subject { Fabricate.build(:poll) }
|
2023-10-17 23:56:24 +11:00
|
|
|
|
2024-09-06 01:36:05 +10:00
|
|
|
it { is_expected.to validate_presence_of(:expires_at) }
|
2023-10-17 23:56:24 +11:00
|
|
|
end
|
|
|
|
end
|
2019-03-04 08:18:23 +11:00
|
|
|
end
|