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.

133 lines
5.1 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 @ancestors for ancestors of the status if it is a reply' do
  45. ancestor = Fabricate(:status)
  46. status = Fabricate(:status, in_reply_to_id: ancestor.id)
  47. get :show, params: { account_username: status.account.username, id: status.id }
  48. expect(assigns(:ancestors)).to eq [ancestor]
  49. end
  50. it 'assigns @ancestors for [] if it is not a reply' do
  51. status = Fabricate(:status)
  52. get :show, params: { account_username: status.account.username, id: status.id }
  53. expect(assigns(:ancestors)).to eq []
  54. end
  55. it 'assigns @descendant_threads for a thread with several statuses' do
  56. status = Fabricate(:status)
  57. child = Fabricate(:status, in_reply_to_id: status.id)
  58. grandchild = Fabricate(:status, in_reply_to_id: child.id)
  59. get :show, params: { account_username: status.account.username, id: status.id }
  60. expect(assigns(:descendant_threads)[0][:statuses].pluck(:id)).to eq [child.id, grandchild.id]
  61. end
  62. it 'assigns @descendant_threads for several threads sharing the same descendant' do
  63. status = Fabricate(:status)
  64. child = Fabricate(:status, in_reply_to_id: status.id)
  65. grandchildren = 2.times.map { Fabricate(:status, in_reply_to_id: child.id) }
  66. get :show, params: { account_username: status.account.username, id: status.id }
  67. expect(assigns(:descendant_threads)[0][:statuses].pluck(:id)).to eq [child.id, grandchildren[0].id]
  68. expect(assigns(:descendant_threads)[1][:statuses].pluck(:id)).to eq [grandchildren[1].id]
  69. end
  70. it 'assigns @max_descendant_thread_id for the last thread if it is hitting the status limit' do
  71. stub_const 'StatusControllerConcern::DESCENDANTS_LIMIT', 1
  72. status = Fabricate(:status)
  73. child = Fabricate(:status, in_reply_to_id: status.id)
  74. get :show, params: { account_username: status.account.username, id: status.id }
  75. expect(assigns(:descendant_threads)).to eq []
  76. expect(assigns(:max_descendant_thread_id)).to eq child.id
  77. end
  78. it 'assigns @descendant_threads for threads with :next_status key if they are hitting the depth limit' do
  79. stub_const 'StatusControllerConcern::DESCENDANTS_DEPTH_LIMIT', 2
  80. status = Fabricate(:status)
  81. child0 = Fabricate(:status, in_reply_to_id: status.id)
  82. child1 = Fabricate(:status, in_reply_to_id: child0.id)
  83. child2 = Fabricate(:status, in_reply_to_id: child0.id)
  84. get :show, params: { account_username: status.account.username, id: status.id }
  85. expect(assigns(:descendant_threads)[0][:statuses].pluck(:id)).not_to include child1.id
  86. expect(assigns(:descendant_threads)[1][:statuses].pluck(:id)).not_to include child2.id
  87. expect(assigns(:descendant_threads)[0][:next_status].id).to eq child1.id
  88. expect(assigns(:descendant_threads)[1][:next_status].id).to eq child2.id
  89. end
  90. it 'returns a success' do
  91. status = Fabricate(:status)
  92. get :show, params: { account_username: status.account.username, id: status.id }
  93. expect(response).to have_http_status(200)
  94. end
  95. it 'renders statuses/show' do
  96. status = Fabricate(:status)
  97. get :show, params: { account_username: status.account.username, id: status.id }
  98. expect(response).to render_template 'statuses/show'
  99. end
  100. end
  101. end
  102. end