pins_controller_spec.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Api::V1::Statuses::PinsController do
  4. render_views
  5. let(:user) { Fabricate(:user) }
  6. let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
  7. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:accounts', application: app) }
  8. context 'with an oauth token' do
  9. before do
  10. allow(controller).to receive(:doorkeeper_token) { token }
  11. end
  12. describe 'POST #create' do
  13. let(:status) { Fabricate(:status, account: user.account) }
  14. before do
  15. post :create, params: { status_id: status.id }
  16. end
  17. it 'returns http success' do
  18. expect(response).to have_http_status(200)
  19. end
  20. it 'updates the pinned attribute' do
  21. expect(user.account.pinned?(status)).to be true
  22. end
  23. it 'return json with updated attributes' do
  24. hash_body = body_as_json
  25. expect(hash_body[:id]).to eq status.id.to_s
  26. expect(hash_body[:pinned]).to be true
  27. end
  28. end
  29. describe 'POST #destroy' do
  30. let(:status) { Fabricate(:status, account: user.account) }
  31. before do
  32. Fabricate(:status_pin, status: status, account: user.account)
  33. post :destroy, params: { status_id: status.id }
  34. end
  35. it 'returns http success' do
  36. expect(response).to have_http_status(200)
  37. end
  38. it 'updates the pinned attribute' do
  39. expect(user.account.pinned?(status)).to be false
  40. end
  41. end
  42. end
  43. end