The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

82 lines
2.0 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::V1::FiltersController, type: :controller do
  3. render_views
  4. let(:user) { Fabricate(:user) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read write') }
  6. before do
  7. allow(controller).to receive(:doorkeeper_token) { token }
  8. end
  9. describe 'GET #index' do
  10. let!(:filter) { Fabricate(:custom_filter, account: user.account) }
  11. it 'returns http success' do
  12. get :index
  13. expect(response).to have_http_status(200)
  14. end
  15. end
  16. describe 'POST #create' do
  17. before do
  18. post :create, params: { phrase: 'magic', context: %w(home), irreversible: true }
  19. end
  20. it 'returns http success' do
  21. expect(response).to have_http_status(200)
  22. end
  23. it 'creates a filter' do
  24. filter = user.account.custom_filters.first
  25. expect(filter).to_not be_nil
  26. expect(filter.phrase).to eq 'magic'
  27. expect(filter.context).to eq %w(home)
  28. expect(filter.irreversible?).to be true
  29. expect(filter.expires_at).to be_nil
  30. end
  31. end
  32. describe 'GET #show' do
  33. let(:filter) { Fabricate(:custom_filter, account: user.account) }
  34. it 'returns http success' do
  35. get :show, params: { id: filter.id }
  36. expect(response).to have_http_status(200)
  37. end
  38. end
  39. describe 'PUT #update' do
  40. let(:filter) { Fabricate(:custom_filter, account: user.account) }
  41. before do
  42. put :update, params: { id: filter.id, phrase: 'updated' }
  43. end
  44. it 'returns http success' do
  45. expect(response).to have_http_status(200)
  46. end
  47. it 'updates the filter' do
  48. expect(filter.reload.phrase).to eq 'updated'
  49. end
  50. end
  51. describe 'DELETE #destroy' do
  52. let(:filter) { Fabricate(:custom_filter, account: user.account) }
  53. before do
  54. delete :destroy, params: { id: filter.id }
  55. end
  56. it 'returns http success' do
  57. expect(response).to have_http_status(200)
  58. end
  59. it 'removes the filter' do
  60. expect { filter.reload }.to raise_error ActiveRecord::RecordNotFound
  61. end
  62. end
  63. end