~cytrogen/masto-fe

ref: 0139b1c8e1aa6cde4fcabd56ededaa0e5ab40a68 masto-fe/spec/controllers/concerns/export_controller_concern_spec.rb -rw-r--r-- 844 bytes
0139b1c8 — Matt Jankowski Update uri to version 0.12.2 (CVE fix) (#25657) 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

require 'rails_helper'

describe ApplicationController do
  controller do
    include ExportControllerConcern

    def index
      send_export_file
    end

    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

      expect(response).to have_http_status(200)
      expect(response.media_type).to eq 'text/csv'
      expect(response.headers['Content-Disposition']).to start_with 'attachment; filename="anonymous.csv"'
      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(401)
    end
  end
end