pins_controller_spec.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Api::V1::Accounts::PinsController do
  4. let(:john) { Fabricate(:user) }
  5. let(:kevin) { Fabricate(:user) }
  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 'creates account_pin', :aggregate_failures do
  14. expect do
  15. subject
  16. end.to change { AccountPin.where(account: john.account, target_account: kevin.account).count }.by(1)
  17. expect(response).to have_http_status(200)
  18. end
  19. end
  20. describe 'DELETE #destroy' do
  21. subject { delete :destroy, params: { account_id: kevin.account.id } }
  22. before do
  23. Fabricate(:account_pin, account: john.account, target_account: kevin.account)
  24. end
  25. it 'destroys account_pin', :aggregate_failures do
  26. expect do
  27. subject
  28. end.to change { AccountPin.where(account: john.account, target_account: kevin.account).count }.by(-1)
  29. expect(response).to have_http_status(200)
  30. end
  31. end
  32. end