You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
4.5 KiB

  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. let(:stream_entry) { Fabricate(:stream_entry, activity: activity) }
  9. let(:activity) { reblog }
  10. describe '#object_type' do
  11. before do
  12. allow(stream_entry).to receive(:orphaned?).and_return(orphaned)
  13. allow(stream_entry).to receive(:targeted?).and_return(targeted)
  14. end
  15. subject { stream_entry.object_type }
  16. context 'orphaned? is true' do
  17. let(:orphaned) { true }
  18. let(:targeted) { false }
  19. it 'returns :activity' do
  20. is_expected.to be :activity
  21. end
  22. end
  23. context 'targeted? is true' do
  24. let(:orphaned) { false }
  25. let(:targeted) { true }
  26. it 'returns :activity' do
  27. is_expected.to be :activity
  28. end
  29. end
  30. context 'orphaned? and targeted? are false' do
  31. let(:orphaned) { false }
  32. let(:targeted) { false }
  33. context 'activity is reblog' do
  34. let(:activity) { reblog }
  35. it 'returns :note' do
  36. is_expected.to be :note
  37. end
  38. end
  39. context 'activity is reply' do
  40. let(:activity) { reply }
  41. it 'returns :comment' do
  42. is_expected.to be :comment
  43. end
  44. end
  45. end
  46. end
  47. describe '#verb' do
  48. before do
  49. allow(stream_entry).to receive(:orphaned?).and_return(orphaned)
  50. end
  51. subject { stream_entry.verb }
  52. context 'orphaned? is true' do
  53. let(:orphaned) { true }
  54. it 'returns :delete' do
  55. is_expected.to be :delete
  56. end
  57. end
  58. context 'orphaned? is false' do
  59. let(:orphaned) { false }
  60. context 'activity is reblog' do
  61. let(:activity) { reblog }
  62. it 'returns :share' do
  63. is_expected.to be :share
  64. end
  65. end
  66. context 'activity is reply' do
  67. let(:activity) { reply }
  68. it 'returns :post' do
  69. is_expected.to be :post
  70. end
  71. end
  72. end
  73. end
  74. describe '#mentions' do
  75. before do
  76. allow(stream_entry).to receive(:orphaned?).and_return(orphaned)
  77. end
  78. subject { stream_entry.mentions }
  79. context 'orphaned? is true' do
  80. let(:orphaned) { true }
  81. it 'returns []' do
  82. is_expected.to eq []
  83. end
  84. end
  85. context 'orphaned? is false' do
  86. before do
  87. reblog.mentions << Fabricate(:mention, account: alice)
  88. reblog.mentions << Fabricate(:mention, account: bob)
  89. end
  90. let(:orphaned) { false }
  91. it 'returns [Account] includes alice and bob' do
  92. is_expected.to eq [alice, bob]
  93. end
  94. end
  95. end
  96. describe '#targeted?' do
  97. it 'returns true for a reblog' do
  98. expect(reblog.stream_entry.targeted?).to be true
  99. end
  100. it 'returns false otherwise' do
  101. expect(status.stream_entry.targeted?).to be false
  102. end
  103. end
  104. describe '#threaded?' do
  105. it 'returns true for a reply' do
  106. expect(reply.stream_entry.threaded?).to be true
  107. end
  108. it 'returns false otherwise' do
  109. expect(status.stream_entry.threaded?).to be false
  110. end
  111. end
  112. describe 'delegated methods' do
  113. context 'with a nil status' do
  114. subject { described_class.new(status: nil) }
  115. it 'returns nil for target' do
  116. expect(subject.target).to be_nil
  117. end
  118. it 'returns nil for title' do
  119. expect(subject.title).to be_nil
  120. end
  121. it 'returns nil for content' do
  122. expect(subject.content).to be_nil
  123. end
  124. it 'returns nil for thread' do
  125. expect(subject.thread).to be_nil
  126. end
  127. end
  128. context 'with a real status' do
  129. let(:original) { Fabricate(:status, text: 'Test status') }
  130. let(:status) { Fabricate(:status, reblog: original, thread: original) }
  131. subject { described_class.new(status: status) }
  132. it 'delegates target' do
  133. expect(status.target).not_to be_nil
  134. expect(subject.target).to eq(status.target)
  135. end
  136. it 'delegates title' do
  137. expect(status.title).not_to be_nil
  138. expect(subject.title).to eq(status.title)
  139. end
  140. it 'delegates content' do
  141. expect(status.content).not_to be_nil
  142. expect(subject.content).to eq(status.content)
  143. end
  144. it 'delegates thread' do
  145. expect(status.thread).not_to be_nil
  146. expect(subject.thread).to eq(status.thread)
  147. end
  148. end
  149. end
  150. end