about summary refs log tree commit diff
path: root/spec/controllers/concerns/obfuscate_filename_spec.rb
blob: e06d53c038557ef52ea530bddd159197218bfb6e (plain) (blame)
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
# frozen_string_literal: true

require 'rails_helper'

describe ApplicationController, type: :controller do
  controller do
    include ObfuscateFilename

    obfuscate_filename :file

    def file
      render plain: params[:file]&.original_filename
    end
  end

  before do
    routes.draw { get 'file' => 'anonymous#file' }
  end

  it 'obfusticates filename if the given parameter is specified' do
    file = fixture_file_upload('files/imports.txt', 'text/plain')
    post 'file', params: { file: file }
    expect(response.body).to end_with '.txt'
    expect(response.body).not_to include 'imports'
  end

  it 'does nothing if the given parameter is not specified' do
    post 'file'
  end
end