2017-05-29 12:05:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-05-30 13:06:01 -04:00
|
|
|
describe ApplicationController, type: :controller do
|
2017-05-29 12:05:01 -04:00
|
|
|
controller do
|
2017-05-30 13:06:01 -04:00
|
|
|
include ExportControllerConcern
|
|
|
|
def index
|
|
|
|
send_export_file
|
|
|
|
end
|
2018-10-04 11:38:04 -04:00
|
|
|
|
2017-05-29 12:05:01 -04: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 15:35:07 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2017-05-29 12:05:01 -04:00
|
|
|
expect(response.content_type).to eq 'text/csv'
|
2017-05-30 13:06:01 -04:00
|
|
|
expect(response.headers['Content-Disposition']).to eq 'attachment; filename="anonymous.csv"'
|
2017-05-29 12:05:01 -04:00
|
|
|
expect(response.body).to eq user.account.username
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns unauthorized when not signed in' do
|
|
|
|
get :index, format: :csv
|
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|