poll_spec.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 valid' do
  28. let(:poll) { Fabricate.build(:poll) }
  29. it 'is valid with valid attributes' do
  30. expect(poll).to be_valid
  31. end
  32. end
  33. context 'when not valid' do
  34. let(:poll) { Fabricate.build(:poll, expires_at: nil) }
  35. it 'is invalid without an expire date' do
  36. poll.valid?
  37. expect(poll).to model_have_error_on_field(:expires_at)
  38. end
  39. end
  40. end
  41. end