notes_controller_spec.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. require 'rails_helper'
  2. describe Api::V1::Accounts::NotesController do
  3. render_views
  4. let(:user) { Fabricate(:user) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:accounts') }
  6. let(:account) { Fabricate(:account) }
  7. let(:comment) { 'foo' }
  8. before do
  9. allow(controller).to receive(:doorkeeper_token) { token }
  10. end
  11. describe 'POST #create' do
  12. subject do
  13. post :create, params: { account_id: account.id, comment: comment }
  14. end
  15. context 'when account note has reasonable length' do
  16. let(:comment) { 'foo' }
  17. it 'returns http success' do
  18. subject
  19. expect(response).to have_http_status(200)
  20. end
  21. it 'updates account note' do
  22. subject
  23. expect(AccountNote.find_by(account_id: user.account.id, target_account_id: account.id).comment).to eq comment
  24. end
  25. end
  26. context 'when account note exceeds allowed length' do
  27. let(:comment) { 'a' * 2_001 }
  28. it 'returns 422' do
  29. subject
  30. expect(response).to have_http_status(422)
  31. end
  32. it 'does not create account note' do
  33. subject
  34. expect(AccountNote.where(account_id: user.account.id, target_account_id: account.id).exists?).to be_falsey
  35. end
  36. end
  37. end
  38. end