poll_spec.rb 993 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Poll do
  4. describe 'scopes' do
  5. let(:status) { Fabricate(:status) }
  6. let(:attached_poll) { Fabricate(:poll, status: status) }
  7. let(:not_attached_poll) do
  8. Fabricate(:poll).tap do |poll|
  9. poll.status = nil
  10. poll.save(validate: false)
  11. end
  12. end
  13. describe 'attached' do
  14. it 'finds the correct records' do
  15. results = described_class.attached
  16. expect(results).to eq([attached_poll])
  17. end
  18. end
  19. describe 'unattached' do
  20. it 'finds the correct records' do
  21. results = described_class.unattached
  22. expect(results).to eq([not_attached_poll])
  23. end
  24. end
  25. end
  26. describe 'validations' do
  27. context 'when not valid' do
  28. let(:poll) { Fabricate.build(:poll, expires_at: nil) }
  29. it 'is invalid without an expire date' do
  30. poll.valid?
  31. expect(poll).to model_have_error_on_field(:expires_at)
  32. end
  33. end
  34. end
  35. end