stream_entry_spec.rb 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. require 'rails_helper'
  2. RSpec.describe StreamEntry, type: :model do
  3. let(:alice) { Fabricate(:account, username: 'alice') }
  4. let(:bob) { Fabricate(:account, username: 'bob') }
  5. let(:status) { Fabricate(:status, account: alice) }
  6. let(:reblog) { Fabricate(:status, account: bob, reblog: status) }
  7. let(:reply) { Fabricate(:status, account: bob, thread: status) }
  8. describe '#targeted?' do
  9. it 'returns true for a reblog' do
  10. expect(reblog.stream_entry.targeted?).to be true
  11. end
  12. it 'returns false otherwise' do
  13. expect(status.stream_entry.targeted?).to be false
  14. end
  15. end
  16. describe '#threaded?' do
  17. it 'returns true for a reply' do
  18. expect(reply.stream_entry.threaded?).to be true
  19. end
  20. it 'returns false otherwise' do
  21. expect(status.stream_entry.threaded?).to be false
  22. end
  23. end
  24. describe 'delegated methods' do
  25. context 'with a nil status' do
  26. subject { described_class.new(status: nil) }
  27. it 'returns nil for target' do
  28. expect(subject.target).to be_nil
  29. end
  30. it 'returns nil for title' do
  31. expect(subject.title).to be_nil
  32. end
  33. it 'returns nil for content' do
  34. expect(subject.content).to be_nil
  35. end
  36. it 'returns nil for thread' do
  37. expect(subject.thread).to be_nil
  38. end
  39. end
  40. context 'with a real status' do
  41. let(:original) { Fabricate(:status, text: 'Test status') }
  42. let(:status) { Fabricate(:status, reblog: original, thread: original) }
  43. subject { described_class.new(status: status) }
  44. it 'delegates target' do
  45. expect(status.target).not_to be_nil
  46. expect(subject.target).to eq(status.target)
  47. end
  48. it 'delegates title' do
  49. expect(status.title).not_to be_nil
  50. expect(subject.title).to eq(status.title)
  51. end
  52. it 'delegates content' do
  53. expect(status.content).not_to be_nil
  54. expect(subject.content).to eq(status.content)
  55. end
  56. it 'delegates thread' do
  57. expect(status.thread).not_to be_nil
  58. expect(subject.thread).to eq(status.thread)
  59. end
  60. end
  61. end
  62. end