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.

46 lines
1.3 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Api::V1::Accounts::PinsController, type: :controller do
  4. let(:john) { Fabricate(:user, account: Fabricate(:account, username: 'john')) }
  5. let(:kevin) { Fabricate(:user, account: Fabricate(:account, username: 'kevin')) }
  6. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: john.id, scopes: 'write:accounts') }
  7. before do
  8. kevin.account.followers << john.account
  9. allow(controller).to receive(:doorkeeper_token) { token }
  10. end
  11. describe 'POST #create' do
  12. subject { post :create, params: { account_id: kevin.account.id } }
  13. it 'returns 200' do
  14. expect(response).to have_http_status(200)
  15. end
  16. it 'creates account_pin' do
  17. expect do
  18. subject
  19. end.to change { AccountPin.where(account: john.account, target_account: kevin.account).count }.by(1)
  20. end
  21. end
  22. describe 'DELETE #destroy' do
  23. subject { delete :destroy, params: { account_id: kevin.account.id } }
  24. before do
  25. Fabricate(:account_pin, account: john.account, target_account: kevin.account)
  26. end
  27. it 'returns 200' do
  28. expect(response).to have_http_status(200)
  29. end
  30. it 'destroys account_pin' do
  31. expect do
  32. subject
  33. end.to change { AccountPin.where(account: john.account, target_account: kevin.account).count }.by(-1)
  34. end
  35. end
  36. end