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.

145 lines
5.6 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe StatusesController do
  4. render_views
  5. describe '#show' do
  6. context 'account is suspended' do
  7. it 'returns gone' do
  8. account = Fabricate(:account, suspended: true)
  9. status = Fabricate(:status, account: account)
  10. get :show, params: { account_username: account.username, id: status.id }
  11. expect(response).to have_http_status(410)
  12. end
  13. end
  14. context 'status is not permitted' do
  15. it 'raises ActiveRecord::RecordNotFound' do
  16. user = Fabricate(:user)
  17. status = Fabricate(:status)
  18. status.account.block!(user.account)
  19. sign_in(user)
  20. get :show, params: { account_username: status.account.username, id: status.id }
  21. expect(response).to have_http_status(404)
  22. end
  23. end
  24. context 'status is a reblog' do
  25. it 'redirects to the original status' do
  26. original_account = Fabricate(:account, domain: 'example.com')
  27. original_status = Fabricate(:status, account: original_account, uri: 'tag:example.com,2017:foo', url: 'https://example.com/123')
  28. status = Fabricate(:status, reblog: original_status)
  29. get :show, params: { account_username: status.account.username, id: status.id }
  30. expect(response).to redirect_to(original_status.url)
  31. end
  32. end
  33. context 'account is not suspended and status is permitted' do
  34. it 'assigns @account' do
  35. status = Fabricate(:status)
  36. get :show, params: { account_username: status.account.username, id: status.id }
  37. expect(assigns(:account)).to eq status.account
  38. end
  39. it 'assigns @status' do
  40. status = Fabricate(:status)
  41. get :show, params: { account_username: status.account.username, id: status.id }
  42. expect(assigns(:status)).to eq status
  43. end
  44. it 'assigns @stream_entry' do
  45. status = Fabricate(:status)
  46. get :show, params: { account_username: status.account.username, id: status.id }
  47. expect(assigns(:stream_entry)).to eq status.stream_entry
  48. end
  49. it 'assigns @type' do
  50. status = Fabricate(:status)
  51. get :show, params: { account_username: status.account.username, id: status.id }
  52. expect(assigns(:type)).to eq 'status'
  53. end
  54. it 'assigns @ancestors for ancestors of the status if it is a reply' do
  55. ancestor = Fabricate(:status)
  56. status = Fabricate(:status, in_reply_to_id: ancestor.id)
  57. get :show, params: { account_username: status.account.username, id: status.id }
  58. expect(assigns(:ancestors)).to eq [ancestor]
  59. end
  60. it 'assigns @ancestors for [] if it is not a reply' do
  61. status = Fabricate(:status)
  62. get :show, params: { account_username: status.account.username, id: status.id }
  63. expect(assigns(:ancestors)).to eq []
  64. end
  65. it 'assigns @descendant_threads for a thread with several statuses' do
  66. status = Fabricate(:status)
  67. child = Fabricate(:status, in_reply_to_id: status.id)
  68. grandchild = Fabricate(:status, in_reply_to_id: child.id)
  69. get :show, params: { account_username: status.account.username, id: status.id }
  70. expect(assigns(:descendant_threads)[0][:statuses].pluck(:id)).to eq [child.id, grandchild.id]
  71. end
  72. it 'assigns @descendant_threads for several threads sharing the same descendant' do
  73. status = Fabricate(:status)
  74. child = Fabricate(:status, in_reply_to_id: status.id)
  75. grandchildren = 2.times.map { Fabricate(:status, in_reply_to_id: child.id) }
  76. get :show, params: { account_username: status.account.username, id: status.id }
  77. expect(assigns(:descendant_threads)[0][:statuses].pluck(:id)).to eq [child.id, grandchildren[0].id]
  78. expect(assigns(:descendant_threads)[1][:statuses].pluck(:id)).to eq [grandchildren[1].id]
  79. end
  80. it 'assigns @max_descendant_thread_id for the last thread if it is hitting the status limit' do
  81. stub_const 'StatusesController::DESCENDANTS_LIMIT', 1
  82. status = Fabricate(:status)
  83. child = Fabricate(:status, in_reply_to_id: status.id)
  84. get :show, params: { account_username: status.account.username, id: status.id }
  85. expect(assigns(:descendant_threads)).to eq []
  86. expect(assigns(:max_descendant_thread_id)).to eq child.id
  87. end
  88. it 'assigns @descendant_threads for threads with :next_status key if they are hitting the depth limit' do
  89. stub_const 'StatusesController::DESCENDANTS_DEPTH_LIMIT', 2
  90. status = Fabricate(:status)
  91. child0 = Fabricate(:status, in_reply_to_id: status.id)
  92. child1 = Fabricate(:status, in_reply_to_id: child0.id)
  93. child2 = Fabricate(:status, in_reply_to_id: child0.id)
  94. get :show, params: { account_username: status.account.username, id: status.id }
  95. expect(assigns(:descendant_threads)[0][:statuses].pluck(:id)).not_to include child1.id
  96. expect(assigns(:descendant_threads)[1][:statuses].pluck(:id)).not_to include child2.id
  97. expect(assigns(:descendant_threads)[0][:next_status].id).to eq child1.id
  98. expect(assigns(:descendant_threads)[1][:next_status].id).to eq child2.id
  99. end
  100. it 'returns a success' do
  101. status = Fabricate(:status)
  102. get :show, params: { account_username: status.account.username, id: status.id }
  103. expect(response).to have_http_status(200)
  104. end
  105. it 'renders stream_entries/show' do
  106. status = Fabricate(:status)
  107. get :show, params: { account_username: status.account.username, id: status.id }
  108. expect(response).to render_template 'stream_entries/show'
  109. end
  110. end
  111. end
  112. end