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.

102 lines
2.6 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::StatusesController, type: :controller do
  3. render_views
  4. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  5. let(:token) { double acceptable?: true, resource_owner_id: user.id }
  6. before do
  7. stub_request(:post, "https://pubsubhubbub.superfeedr.com/").to_return(:status => 200, :body => "", :headers => {})
  8. allow(controller).to receive(:doorkeeper_token) { token }
  9. end
  10. describe 'GET #show' do
  11. let(:status) { Fabricate(:status, account: user.account) }
  12. it 'returns http success' do
  13. get :show, params: { id: status.id }
  14. expect(response).to have_http_status(:success)
  15. end
  16. end
  17. describe 'GET #home' do
  18. it 'returns http success' do
  19. get :home
  20. expect(response).to have_http_status(:success)
  21. end
  22. end
  23. describe 'GET #mentions' do
  24. it 'returns http success' do
  25. get :mentions
  26. expect(response).to have_http_status(:success)
  27. end
  28. end
  29. describe 'POST #create' do
  30. before do
  31. post :create, params: { status: 'Hello world' }
  32. end
  33. it 'returns http success' do
  34. expect(response).to have_http_status(:success)
  35. end
  36. end
  37. describe 'POST #reblog' do
  38. let(:status) { Fabricate(:status, account: user.account) }
  39. before do
  40. post :reblog, params: { id: status.id }
  41. end
  42. it 'returns http success' do
  43. expect(response).to have_http_status(:success)
  44. end
  45. it 'updates the reblogs count' do
  46. expect(status.reblogs_count).to eq 1
  47. end
  48. it 'updates the reblogged attribute' do
  49. expect(user.account.reblogged?(status)).to be true
  50. end
  51. it 'return json with updated attributes' do
  52. hash_body = body_as_json
  53. expect(hash_body[:reblog][:id]).to eq status.id
  54. expect(hash_body[:reblog][:reblogs_count]).to eq 1
  55. expect(hash_body[:reblog][:reblogged]).to be true
  56. end
  57. end
  58. describe 'POST #favourite' do
  59. let(:status) { Fabricate(:status, account: user.account) }
  60. before do
  61. post :favourite, params: { id: status.id }
  62. end
  63. it 'returns http success' do
  64. expect(response).to have_http_status(:success)
  65. end
  66. it 'updates the favourites count' do
  67. expect(status.favourites_count).to eq 1
  68. end
  69. it 'updates the favourited attribute' do
  70. expect(user.account.favourited?(status)).to be true
  71. end
  72. it 'return json with updated attributes' do
  73. hash_body = body_as_json
  74. expect(hash_body[:id]).to eq status.id
  75. expect(hash_body[:favourites_count]).to eq 1
  76. expect(hash_body[:favourited]).to be true
  77. end
  78. end
  79. end