|
7 | 7 | let(:logger) { instance_double(Logger) }
|
8 | 8 |
|
9 | 9 | before do
|
10 |
| - allow(Time).to receive(:now).and_return(1, 2) |
| 10 | + allow(Time).to receive(:now).and_return( |
| 11 | + Time.new(2022, 12, 19, 0, 0, 0), |
| 12 | + Time.new(2022, 12, 19, 0, 0, 1) |
| 13 | + ) |
11 | 14 | allow(logger).to receive(:info)
|
12 | 15 | end
|
13 | 16 |
|
|
21 | 24 |
|
22 | 25 | described_class.new(app).call(env)
|
23 | 26 |
|
24 |
| - expect(logger).to have_received(:info).with('method=GET path=/test client=n/a status=200 duration=1') |
| 27 | + expect(logger).to have_received(:info).with('method=GET path=/test client=n/a status=200 duration=1.0') |
25 | 28 | end
|
26 | 29 |
|
27 | 30 | it 'logs the request with REMOTE_ADDR' do
|
|
30 | 33 |
|
31 | 34 | described_class.new(app).call(env)
|
32 | 35 |
|
33 |
| - expect(logger).to have_received(:info).with('method=GET path=/test client=123.456.789.123 status=200 duration=1') |
| 36 | + expect(logger).to have_received(:info).with('method=GET path=/test client=123.456.789.123 status=200 duration=1.0') |
34 | 37 | end
|
35 | 38 |
|
36 | 39 | it 'logs the request with X_FORWARDED_FOR' do
|
|
39 | 42 |
|
40 | 43 | described_class.new(app).call(env)
|
41 | 44 |
|
42 |
| - expect(logger).to have_received(:info).with('method=GET path=/test client=123.456.789.123 status=200 duration=1') |
| 45 | + expect(logger).to have_received(:info).with('method=GET path=/test client=123.456.789.123 status=200 duration=1.0') |
43 | 46 | end
|
44 | 47 |
|
45 | 48 | it 'logs the request with no params if not GET' do
|
|
48 | 51 |
|
49 | 52 | described_class.new(app).call(env)
|
50 | 53 |
|
51 |
| - expect(logger).to have_received(:info).with('method=POST path=/test client=n/a status=200 duration=1') |
| 54 | + expect(logger).to have_received(:info).with('method=POST path=/test client=n/a status=200 duration=1.0') |
| 55 | + end |
| 56 | + |
| 57 | + it 'rescues request with no params if Rack::Multipart::MultipartPartLimitError is raised' do # rubocop:disable RSpec/ExampleLength |
| 58 | + data = invalid_multipart_body |
| 59 | + env = Rack::MockRequest.env_for('http://localhost/test', { |
| 60 | + 'CONTENT_TYPE' => 'multipart/form-data; boundary=myboundary', |
| 61 | + 'CONTENT_LENGTH' => data.bytesize, |
| 62 | + input: StringIO.new(data) |
| 63 | + }) |
| 64 | + env['logger'] = logger |
| 65 | + described_class.new(app).call(env) |
| 66 | + |
| 67 | + expect(logger).to have_received(:info).with('method=GET path=/test client=n/a status=200 duration=1.0') |
52 | 68 | end
|
53 | 69 | end
|
0 commit comments