The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

313 lines
9.4 KiB

  1. require 'rails_helper'
  2. RSpec.describe Status, type: :model do
  3. let(:alice) { Fabricate(:account, username: 'alice') }
  4. let(:bob) { Fabricate(:account, username: 'bob') }
  5. let(:other) { Fabricate(:status, account: bob, text: 'Skulls for the skull god! The enemy\'s gates are sideways!')}
  6. subject { Fabricate(:status, account: alice) }
  7. describe '#local?' do
  8. it 'returns true when no remote URI is set' do
  9. expect(subject.local?).to be true
  10. end
  11. it 'returns false if a remote URI is set' do
  12. subject.uri = 'a'
  13. expect(subject.local?).to be false
  14. end
  15. end
  16. describe '#reblog?' do
  17. it 'returns true when the status reblogs another status' do
  18. subject.reblog = other
  19. expect(subject.reblog?).to be true
  20. end
  21. it 'returns false if the status is self-contained' do
  22. expect(subject.reblog?).to be false
  23. end
  24. end
  25. describe '#reply?' do
  26. it 'returns true if the status references another' do
  27. subject.thread = other
  28. expect(subject.reply?).to be true
  29. end
  30. it 'returns false if the status is self-contained' do
  31. expect(subject.reply?).to be false
  32. end
  33. end
  34. describe '#verb' do
  35. it 'is always post' do
  36. expect(subject.verb).to be :post
  37. end
  38. end
  39. describe '#object_type' do
  40. it 'is note when the status is self-contained' do
  41. expect(subject.object_type).to be :note
  42. end
  43. it 'is comment when the status replies to another' do
  44. subject.thread = other
  45. expect(subject.object_type).to be :comment
  46. end
  47. end
  48. describe '#title' do
  49. it 'is a shorter version of the content' do
  50. expect(subject.title).to be_a String
  51. end
  52. end
  53. describe '#content' do
  54. it 'returns the text of the status if it is not a reblog' do
  55. expect(subject.content).to eql subject.text
  56. end
  57. it 'returns the text of the reblogged status' do
  58. subject.reblog = other
  59. expect(subject.content).to eql other.text
  60. end
  61. end
  62. describe '#target' do
  63. it 'returns nil if the status is self-contained' do
  64. expect(subject.target).to be_nil
  65. end
  66. it 'returns nil if the status is a reply' do
  67. subject.thread = other
  68. expect(subject.target).to be_nil
  69. end
  70. it 'returns the reblogged status' do
  71. subject.reblog = other
  72. expect(subject.target).to eq other
  73. end
  74. end
  75. describe '#reblogs_count' do
  76. it 'is the number of reblogs' do
  77. Fabricate(:status, account: bob, reblog: subject)
  78. Fabricate(:status, account: alice, reblog: subject)
  79. expect(subject.reblogs_count).to eq 2
  80. end
  81. end
  82. describe '#favourites_count' do
  83. it 'is the number of favorites' do
  84. Fabricate(:favourite, account: bob, status: subject)
  85. Fabricate(:favourite, account: alice, status: subject)
  86. expect(subject.favourites_count).to eq 2
  87. end
  88. end
  89. describe '#proper' do
  90. it 'is itself for original statuses' do
  91. expect(subject.proper).to eq subject
  92. end
  93. it 'is the source status for reblogs' do
  94. subject.reblog = other
  95. expect(subject.proper).to eq other
  96. end
  97. end
  98. describe '#permitted?' do
  99. pending
  100. end
  101. describe '#filter_from_context?' do
  102. pending
  103. end
  104. describe '.local_only' do
  105. it 'returns only statuses from local accounts' do
  106. local_account = Fabricate(:account, domain: nil)
  107. remote_account = Fabricate(:account, domain: 'test.com')
  108. local_status = Fabricate(:status, account: local_account)
  109. remote_status = Fabricate(:status, account: remote_account)
  110. results = described_class.local_only
  111. expect(results).to include(local_status)
  112. expect(results).not_to include(remote_status)
  113. end
  114. end
  115. describe '.as_home_timeline' do
  116. before do
  117. account = Fabricate(:account)
  118. followed = Fabricate(:account)
  119. not_followed = Fabricate(:account)
  120. Fabricate(:follow, account: account, target_account: followed)
  121. @self_status = Fabricate(:status, account: account)
  122. @followed_status = Fabricate(:status, account: followed)
  123. @not_followed_status = Fabricate(:status, account: not_followed)
  124. @results = Status.as_home_timeline(account)
  125. end
  126. it 'includes statuses from self' do
  127. expect(@results).to include(@self_status)
  128. end
  129. it 'includes statuses from followed' do
  130. expect(@results).to include(@followed_status)
  131. end
  132. it 'does not include statuses from non-followed' do
  133. expect(@results).not_to include(@not_followed_status)
  134. end
  135. end
  136. describe '.as_public_timeline' do
  137. it 'only includes statuses with public visibility' do
  138. public_status = Fabricate(:status, visibility: :public)
  139. private_status = Fabricate(:status, visibility: :private)
  140. results = Status.as_public_timeline
  141. expect(results).to include(public_status)
  142. expect(results).not_to include(private_status)
  143. end
  144. it 'does not include replies' do
  145. status = Fabricate(:status)
  146. reply = Fabricate(:status, in_reply_to_id: status.id)
  147. results = Status.as_public_timeline
  148. expect(results).to include(status)
  149. expect(results).not_to include(reply)
  150. end
  151. it 'does not include boosts' do
  152. status = Fabricate(:status)
  153. boost = Fabricate(:status, reblog_of_id: status.id)
  154. results = Status.as_public_timeline
  155. expect(results).to include(status)
  156. expect(results).not_to include(boost)
  157. end
  158. it 'filters out silenced accounts' do
  159. account = Fabricate(:account)
  160. silenced_account = Fabricate(:account, silenced: true)
  161. status = Fabricate(:status, account: account)
  162. silenced_status = Fabricate(:status, account: silenced_account)
  163. results = Status.as_public_timeline
  164. expect(results).to include(status)
  165. expect(results).not_to include(silenced_status)
  166. end
  167. context 'with a local_only option set' do
  168. it 'does not include remote instances statuses' do
  169. local_account = Fabricate(:account, domain: nil)
  170. remote_account = Fabricate(:account, domain: 'test.com')
  171. local_status = Fabricate(:status, account: local_account)
  172. remote_status = Fabricate(:status, account: remote_account)
  173. results = Status.as_public_timeline(nil, true)
  174. expect(results).to include(local_status)
  175. expect(results).not_to include(remote_status)
  176. end
  177. end
  178. describe 'with an account passed in' do
  179. before do
  180. @account = Fabricate(:account)
  181. end
  182. it 'excludes statuses from accounts blocked by the account' do
  183. blocked = Fabricate(:account)
  184. Fabricate(:block, account: @account, target_account: blocked)
  185. blocked_status = Fabricate(:status, account: blocked)
  186. results = Status.as_public_timeline(@account)
  187. expect(results).not_to include(blocked_status)
  188. end
  189. it 'excludes statuses from accounts who have blocked the account' do
  190. blocked = Fabricate(:account)
  191. Fabricate(:block, account: blocked, target_account: @account)
  192. blocked_status = Fabricate(:status, account: blocked)
  193. results = Status.as_public_timeline(@account)
  194. expect(results).not_to include(blocked_status)
  195. end
  196. it 'excludes statuses from accounts muted by the account' do
  197. muted = Fabricate(:account)
  198. Fabricate(:mute, account: @account, target_account: muted)
  199. muted_status = Fabricate(:status, account: muted)
  200. results = Status.as_public_timeline(@account)
  201. expect(results).not_to include(muted_status)
  202. end
  203. context 'with language preferences' do
  204. it 'excludes statuses in languages not allowed by the account user' do
  205. user = Fabricate(:user, allowed_languages: [:en, :es])
  206. @account.update(user: user)
  207. en_status = Fabricate(:status, language: 'en')
  208. es_status = Fabricate(:status, language: 'es')
  209. fr_status = Fabricate(:status, language: 'fr')
  210. results = Status.as_public_timeline(@account)
  211. expect(results).to include(en_status)
  212. expect(results).to include(es_status)
  213. expect(results).not_to include(fr_status)
  214. end
  215. it 'includes all languages when account does not have a user' do
  216. expect(@account.user).to be_nil
  217. en_status = Fabricate(:status, language: 'en')
  218. es_status = Fabricate(:status, language: 'es')
  219. results = Status.as_public_timeline(@account)
  220. expect(results).to include(en_status)
  221. expect(results).to include(es_status)
  222. end
  223. end
  224. context 'where that account is silenced' do
  225. it 'includes statuses from other accounts that are silenced' do
  226. @account.update(silenced: true)
  227. other_silenced_account = Fabricate(:account, silenced: true)
  228. other_status = Fabricate(:status, account: other_silenced_account)
  229. results = Status.as_public_timeline(@account)
  230. expect(results).to include(other_status)
  231. end
  232. end
  233. end
  234. end
  235. describe '.as_tag_timeline' do
  236. it 'includes statuses with a tag' do
  237. tag = Fabricate(:tag)
  238. status = Fabricate(:status, tags: [tag])
  239. other = Fabricate(:status)
  240. results = Status.as_tag_timeline(tag)
  241. expect(results).to include(status)
  242. expect(results).not_to include(other)
  243. end
  244. it 'allows replies to be included' do
  245. original = Fabricate(:status)
  246. tag = Fabricate(:tag)
  247. status = Fabricate(:status, tags: [tag], in_reply_to_id: original.id)
  248. results = Status.as_tag_timeline(tag)
  249. expect(results).to include(status)
  250. end
  251. end
  252. end