export_controller_concern_spec.rb 869 B

1234567891011121314151617181920212223242526272829303132333435
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe ExportControllerConcern do
  4. controller(ApplicationController) do
  5. include ExportControllerConcern
  6. def index
  7. send_export_file
  8. end
  9. def export_data
  10. @export.account.username
  11. end
  12. end
  13. describe 'GET #index' do
  14. it 'returns a csv of the exported data when signed in' do
  15. user = Fabricate(:user)
  16. sign_in user
  17. get :index, format: :csv
  18. expect(response).to have_http_status(200)
  19. expect(response.media_type).to eq 'text/csv'
  20. expect(response.headers['Content-Disposition']).to start_with 'attachment; filename="anonymous.csv"'
  21. expect(response.body).to eq user.account.username
  22. end
  23. it 'returns unauthorized when not signed in' do
  24. get :index, format: :csv
  25. expect(response).to have_http_status(401)
  26. end
  27. end
  28. end