2017-05-30 01:05:01 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 14:12:25 +09:00
|
|
|
RSpec.describe Settings::ExportControllerConcern do
|
2023-07-27 21:27:21 +09:00
|
|
|
controller(ApplicationController) do
|
2023-11-30 23:39:41 +09:00
|
|
|
include Settings::ExportControllerConcern
|
2020-09-15 21:37:58 +09:00
|
|
|
|
2017-05-31 02:06:01 +09:00
|
|
|
def index
|
|
|
|
send_export_file
|
|
|
|
end
|
2018-10-05 00:38:04 +09:00
|
|
|
|
2017-05-30 01:05:01 +09:00
|
|
|
def export_data
|
2023-11-09 00:42:30 +09:00
|
|
|
'body data value'
|
2017-05-30 01:05:01 +09:00
|
|
|
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-22 04:35:07 +09:00
|
|
|
expect(response).to have_http_status(200)
|
2021-03-17 18:09:55 +09:00
|
|
|
expect(response.media_type).to eq 'text/csv'
|
|
|
|
expect(response.headers['Content-Disposition']).to start_with 'attachment; filename="anonymous.csv"'
|
2023-11-09 00:42:30 +09:00
|
|
|
expect(response.body).to eq 'body data value'
|
2017-05-30 01:05:01 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns unauthorized when not signed in' do
|
|
|
|
get :index, format: :csv
|
2023-02-20 11:16:40 +09:00
|
|
|
expect(response).to have_http_status(401)
|
2017-05-30 01:05:01 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|