2017-05-29 16:05:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-05-04 03:49:53 +00:00
|
|
|
describe ApplicationController do
|
2017-05-29 16:05:01 +00:00
|
|
|
controller do
|
2017-05-30 17:06:01 +00:00
|
|
|
include ExportControllerConcern
|
2020-09-15 12:37:58 +00:00
|
|
|
|
2017-05-30 17:06:01 +00:00
|
|
|
def index
|
|
|
|
send_export_file
|
|
|
|
end
|
2018-10-04 15:38:04 +00:00
|
|
|
|
2017-05-29 16:05:01 +00:00
|
|
|
def export_data
|
|
|
|
@export.account.username
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #index' do
|
|
|
|
it 'returns a csv of the exported data when signed in' do
|
|
|
|
user = Fabricate(:user)
|
|
|
|
sign_in user
|
|
|
|
get :index, format: :csv
|
|
|
|
|
2018-04-21 19:35:07 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2021-03-17 09:09:55 +00:00
|
|
|
expect(response.media_type).to eq 'text/csv'
|
|
|
|
expect(response.headers['Content-Disposition']).to start_with 'attachment; filename="anonymous.csv"'
|
2017-05-29 16:05:01 +00:00
|
|
|
expect(response.body).to eq user.account.username
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns unauthorized when not signed in' do
|
|
|
|
get :index, format: :csv
|
2023-02-20 02:16:40 +00:00
|
|
|
expect(response).to have_http_status(401)
|
2017-05-29 16:05:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|