闭社主体 forked from https://github.com/tootsuite/mastodon
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.

141 lines
5.3 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', 1
  90. status = Fabricate(:status)
  91. child = Fabricate(:status, in_reply_to_id: status.id)
  92. get :show, params: { account_username: status.account.username, id: status.id }
  93. expect(assigns(:descendant_threads)[0][:statuses].pluck(:id)).not_to include child.id
  94. expect(assigns(:descendant_threads)[0][:next_status].id).to eq child.id
  95. end
  96. it 'returns a success' do
  97. status = Fabricate(:status)
  98. get :show, params: { account_username: status.account.username, id: status.id }
  99. expect(response).to have_http_status(200)
  100. end
  101. it 'renders stream_entries/show' do
  102. status = Fabricate(:status)
  103. get :show, params: { account_username: status.account.username, id: status.id }
  104. expect(response).to render_template 'stream_entries/show'
  105. end
  106. end
  107. end
  108. end