闭社主体 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.

95 lines
3.3 KiB

  1. require 'rails_helper'
  2. RSpec.describe StreamEntriesController, type: :controller do
  3. render_views
  4. shared_examples 'before_action' do |route|
  5. context 'when account is not suspended and stream_entry is available' do
  6. it 'assigns instance variables' do
  7. status = Fabricate(:status)
  8. get route, params: { account_username: status.account.username, id: status.stream_entry.id }
  9. expect(assigns(:account)).to eq status.account
  10. expect(assigns(:stream_entry)).to eq status.stream_entry
  11. expect(assigns(:type)).to eq 'status'
  12. end
  13. it 'sets Link headers' do
  14. alice = Fabricate(:account, username: 'alice')
  15. status = Fabricate(:status, account: alice)
  16. get route, params: { account_username: alice.username, id: status.stream_entry.id }
  17. expect(response.headers['Link'].to_s).to eq "<http://test.host/users/alice/updates/#{status.stream_entry.id}.atom>; rel=\"alternate\"; type=\"application/atom+xml\", <https://cb6e6126.ngrok.io/users/alice/statuses/#{status.id}>; rel=\"alternate\"; type=\"application/activity+json\""
  18. end
  19. end
  20. context 'when account is suspended' do
  21. it 'returns http status 410' do
  22. account = Fabricate(:account, suspended: true)
  23. status = Fabricate(:status, account: account)
  24. get route, params: { account_username: account.username, id: status.stream_entry.id }
  25. expect(response).to have_http_status(410)
  26. end
  27. end
  28. context 'when activity is nil' do
  29. it 'raises ActiveRecord::RecordNotFound' do
  30. account = Fabricate(:account)
  31. stream_entry = Fabricate.build(:stream_entry, account: account, activity: nil, activity_type: 'Status')
  32. stream_entry.save!(validate: false)
  33. get route, params: { account_username: account.username, id: stream_entry.id }
  34. expect(response).to have_http_status(404)
  35. end
  36. end
  37. context 'when it is hidden and it is not permitted' do
  38. it 'raises ActiveRecord::RecordNotFound' do
  39. status = Fabricate(:status)
  40. user = Fabricate(:user)
  41. status.account.block!(user.account)
  42. status.stream_entry.update!(hidden: true)
  43. sign_in(user)
  44. get route, params: { account_username: status.account.username, id: status.stream_entry.id }
  45. expect(response).to have_http_status(404)
  46. end
  47. end
  48. end
  49. describe 'GET #show' do
  50. include_examples 'before_action', :show
  51. it 'redirects to status page' do
  52. status = Fabricate(:status)
  53. get :show, params: { account_username: status.account.username, id: status.stream_entry.id }
  54. expect(response).to redirect_to(short_account_status_url(status.account, status))
  55. end
  56. it 'returns http success with Atom' do
  57. status = Fabricate(:status)
  58. get :show, params: { account_username: status.account.username, id: status.stream_entry.id }, format: 'atom'
  59. expect(response).to have_http_status(200)
  60. end
  61. end
  62. describe 'GET #embed' do
  63. include_examples 'before_action', :embed
  64. it 'redirects to new embed page' do
  65. status = Fabricate(:status)
  66. get :embed, params: { account_username: status.account.username, id: status.stream_entry.id }
  67. expect(response).to redirect_to(embed_short_account_status_url(status.account, status))
  68. end
  69. end
  70. end