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.

99 lines
3.5 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 anbd 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 'renders with HTML' do
  52. ancestor = Fabricate(:status)
  53. status = Fabricate(:status, in_reply_to_id: ancestor.id)
  54. descendant = Fabricate(:status, in_reply_to_id: status.id)
  55. get :show, params: { account_username: status.account.username, id: status.stream_entry.id }
  56. expect(assigns(:ancestors)).to eq [ancestor]
  57. expect(assigns(:descendants)).to eq [descendant]
  58. expect(response).to have_http_status(:success)
  59. end
  60. it 'returns http success with Atom' do
  61. status = Fabricate(:status)
  62. get :show, params: { account_username: status.account.username, id: status.stream_entry.id }, format: 'atom'
  63. expect(response).to have_http_status(:success)
  64. end
  65. end
  66. describe 'GET #embed' do
  67. include_examples 'before_action', :embed
  68. it 'redirects to new embed page' do
  69. status = Fabricate(:status)
  70. get :embed, params: { account_username: status.account.username, id: status.stream_entry.id }
  71. expect(response).to redirect_to(embed_short_account_status_url(status.account, status))
  72. end
  73. end
  74. end