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.

78 lines
1.8 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::V1::ListsController, type: :controller do
  3. render_views
  4. let!(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  5. let!(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  6. let!(:list) { Fabricate(:list, account: user.account) }
  7. before { allow(controller).to receive(:doorkeeper_token) { token } }
  8. describe 'GET #index' do
  9. let(:scopes) { 'read:lists' }
  10. it 'returns http success' do
  11. get :index
  12. expect(response).to have_http_status(200)
  13. end
  14. end
  15. describe 'GET #show' do
  16. let(:scopes) { 'read:lists' }
  17. it 'returns http success' do
  18. get :show, params: { id: list.id }
  19. expect(response).to have_http_status(200)
  20. end
  21. end
  22. describe 'POST #create' do
  23. let(:scopes) { 'write:lists' }
  24. before do
  25. post :create, params: { title: 'Foo bar' }
  26. end
  27. it 'returns http success' do
  28. expect(response).to have_http_status(200)
  29. end
  30. it 'creates list' do
  31. expect(List.where(account: user.account).count).to eq 2
  32. expect(List.last.title).to eq 'Foo bar'
  33. end
  34. end
  35. describe 'PUT #update' do
  36. let(:scopes) { 'write:lists' }
  37. before do
  38. put :update, params: { id: list.id, title: 'Updated title' }
  39. end
  40. it 'returns http success' do
  41. expect(response).to have_http_status(200)
  42. end
  43. it 'updates the list' do
  44. expect(list.reload.title).to eq 'Updated title'
  45. end
  46. end
  47. describe 'DELETE #destroy' do
  48. let(:scopes) { 'write:lists' }
  49. before do
  50. delete :destroy, params: { id: list.id }
  51. end
  52. it 'returns http success' do
  53. expect(response).to have_http_status(200)
  54. end
  55. it 'deletes the list' do
  56. expect(List.find_by(id: list.id)).to be_nil
  57. end
  58. end
  59. end