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.

68 lines
1.6 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: 'read write') }
  6. let!(:list) { Fabricate(:list, account: user.account) }
  7. before { allow(controller).to receive(:doorkeeper_token) { token } }
  8. describe 'GET #index' do
  9. it 'returns http success' do
  10. get :index
  11. expect(response).to have_http_status(200)
  12. end
  13. end
  14. describe 'GET #show' do
  15. it 'returns http success' do
  16. get :show, params: { id: list.id }
  17. expect(response).to have_http_status(200)
  18. end
  19. end
  20. describe 'POST #create' do
  21. before do
  22. post :create, params: { title: 'Foo bar' }
  23. end
  24. it 'returns http success' do
  25. expect(response).to have_http_status(200)
  26. end
  27. it 'creates list' do
  28. expect(List.where(account: user.account).count).to eq 2
  29. expect(List.last.title).to eq 'Foo bar'
  30. end
  31. end
  32. describe 'PUT #update' do
  33. before do
  34. put :update, params: { id: list.id, title: 'Updated title' }
  35. end
  36. it 'returns http success' do
  37. expect(response).to have_http_status(200)
  38. end
  39. it 'updates the list' do
  40. expect(list.reload.title).to eq 'Updated title'
  41. end
  42. end
  43. describe 'DELETE #destroy' do
  44. before do
  45. delete :destroy, params: { id: list.id }
  46. end
  47. it 'returns http success' do
  48. expect(response).to have_http_status(200)
  49. end
  50. it 'deletes the list' do
  51. expect(List.find_by(id: list.id)).to be_nil
  52. end
  53. end
  54. end