-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathrack_spec.rb
74 lines (63 loc) · 1.43 KB
/
rack_spec.rb
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# frozen_string_literal: true
describe Rack do
describe 'from a Tempfile' do
subject { last_response.body }
let(:app) do
Class.new(Grape::API) do
format :json
params do
requires :file, type: File
end
post do
params[:file].then do |file|
{
filename: file[:filename],
type: file[:type],
content: file[:tempfile].read
}
end
end
end
end
let(:response_body) do
{
filename: File.basename(tempfile.path),
type: 'text/plain',
content: 'rubbish'
}.to_json
end
let(:tempfile) do
Tempfile.new.tap do |t|
t.write('rubbish')
t.rewind
end
end
before do
post '/', file: Rack::Test::UploadedFile.new(tempfile.path, 'text/plain')
end
it 'correctly populates params from a Tempfile' do
expect(subject).to eq(response_body)
ensure
tempfile.close!
end
end
context 'when the app is mounted' do
let(:ping_mount) do
Class.new(Grape::API) do
get 'ping'
end
end
let(:app) do
app_to_mount = ping_mount
Class.new(Grape::API) do
namespace 'namespace' do
mount app_to_mount
end
end
end
it 'finds the app on the namespace' do
get '/namespace/ping'
expect(last_response).to be_successful
end
end
end