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.

71 lines
1.8 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::AccountsController, type: :controller do
  3. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  4. let(:token) { double acceptable?: true, resource_owner_id: user.id }
  5. before do
  6. allow(controller).to receive(:doorkeeper_token) { token }
  7. end
  8. describe 'GET #show' do
  9. it 'returns http success' do
  10. get :show, id: user.account.id
  11. expect(response).to have_http_status(:success)
  12. end
  13. end
  14. describe 'GET #statuses' do
  15. it 'returns http success' do
  16. get :statuses, id: user.account.id
  17. expect(response).to have_http_status(:success)
  18. end
  19. end
  20. describe 'GET #followers' do
  21. it 'returns http success' do
  22. get :followers, id: user.account.id
  23. expect(response).to have_http_status(:success)
  24. end
  25. end
  26. describe 'GET #following' do
  27. it 'returns http success' do
  28. get :following, id: user.account.id
  29. expect(response).to have_http_status(:success)
  30. end
  31. end
  32. describe 'POST #follow' do
  33. let(:other_account) { Fabricate(:account, username: 'bob') }
  34. before do
  35. post :follow, id: other_account.id
  36. end
  37. it 'returns http success' do
  38. expect(response).to have_http_status(:success)
  39. end
  40. it 'creates a following relation between user and target user' do
  41. expect(user.account.following?(other_account)).to be true
  42. end
  43. end
  44. describe 'POST #unfollow' do
  45. let(:other_account) { Fabricate(:account, username: 'bob') }
  46. before do
  47. user.account.follow!(other_account)
  48. post :unfollow, id: other_account.id
  49. end
  50. it 'returns http success' do
  51. expect(response).to have_http_status(:success)
  52. end
  53. it 'removes the following relation between user and target user' do
  54. expect(user.account.following?(other_account)).to be false
  55. end
  56. end
  57. end